Hartl's sample_app warning on config.serve_static_files, and test already defined

余生颓废 提交于 2019-12-01 00:01:27

The tutorial is outdated. Your output message shows two issues.

1. Deprecation Warning

The deprecation warning is shows that serve_static_assets is an old name, and the new name is serve_static_files. Rails makes steady improvements to names and methods, so this is a pretty common warning.

Edit sample_app/config/environments/test.rb.

From this:

config.serve_static_assets  = true

To this:

config.serve_static_files  = true

2. Test redefined

The second issue is that there's a problem with your test file.

Look at the error message and see the top line that is about your code:

/home/aki/sample_app/test/models/user_test.rb:10:in `<class:UserTest>'

Can you post this file please?

The error message is saying that you've defined a method twice.

Verify

To verify your changes are in place, cd to your Rails root directory.

Find file names that contain the old assets setting:

find -type f | xargs grep -l 'serve_static_assets' 

Find file names that contain the method name text:

find -type f | xargs grep -l 'test.*should.*be.*valid' 

Look at any files that turn up, and see if there is code that still needs to be changed, or perhaps if there is a test "should be valid" in another UserTest class.

If you don't find serve_static_assets in one of your config files, it's likely that one gem is setting this options. So do it:

bundle update

It solved my problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!