在完成Michael Hartl的Ruby on Rails教程时,我在执行rails test
时遇到了错误,可以使用一些帮助来解决这个问题:
$ rails test
Running via Spring preloader in process 2648
/usr/local/rvm/gems/ruby-2.3.4/gems/activesupport-5.0.4/lib/active_support/testing/declarative.rb:14:in `test': test_layout_links is already defined in SiteLayoutTest (RuntimeError)
from /home/ubuntu/workspace/sample_app/test/integration/site_layout_test.rb:5:in `<class:SiteLayoutTest>'
from /home/ubuntu/workspace/sample_app/test/integration/site_layout_test.rb:3:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.3.4/gems/activesupport-5.0.4/lib/active_support/dependencies.rb:293:in `require'
from /usr/local/rvm/gems/ruby-2.3.4/gems/activesupport-5.0.4/lib/active_support/dependencies.rb:293:in `block in require'
from /usr/local/rvm/gems/ruby-2.3.4/gems/activesupport-5.0.4/lib/active_support/dependencies.rb:259:in `load_dependency'
from /usr/local/rvm/gems/ruby-2.3.4/gems/activesupport-5.0.4/lib/active_support/dependencies.rb:293:in `require'
from /usr/local/rvm/gems/ruby-2.3.4/gems/railties-5.0.4/lib/rails/test_unit/test_requirer.rb:11:in `block in require_files'
from /usr/local/rvm/gems/ruby-2.3.4/gems/railties-5.0.4/lib/rails/test_unit/test_requirer.rb:10:in `each'
from /usr/local/rvm/gems/ruby-2.3.4/gems/railties-5.0.4/lib/rails/test_unit/test_requirer.rb:10:in `require_files'
from /usr/local/rvm/gems/ruby-2.3.4/gems/railties-5.0.4/lib/rails/test_unit/minitest_plugin.rb:86:in `plugin_rails_init'
from /usr/local/rvm/gems/ruby-2.3.4/gems/minitest-5.10.3/lib/minitest.rb:81:in `block in init_plugins'
from /usr/local/rvm/gems/ruby-2.3.4/gems/minitest-5.10.3/lib/minitest.rb:79:in `each'
from /usr/local/rvm/gems/ruby-2.3.4/gems/minitest-5.10.3/lib/minitest.rb:79:in `init_plugins'
from /usr/local/rvm/gems/ruby-2.3.4/gems/minitest-5.10.3/lib/minitest.rb:130:in `run'
from /usr/local/rvm/gems/ruby-2.3.4/gems/railties-5.0.4/lib/rails/test_unit/minitest_plugin.rb:72:in `run'
from /usr/local/rvm/gems/ruby-2.3.4/gems/minitest-5.10.3/lib/minitest.rb:63:in `block in autorun'
from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
答案 0 :(得分:0)
错误消息表明您已在文件test_layout_links
中定义了方法test/integration/site_layout_test.rb
。
它有可能发生两次吗?
像:
def test_layout_links
...
end
def test_layout_links
...
end
或者,如果您使用DSL,它可能如下所示:
test "layout_links" do
...
end
test "layout_links" do
...
end
无论哪种方式,只需删除或重命名。