2017-06-20 51 views
-4

運行時$ rails test,我得到的錯誤如下,如何解決這個問題?

/home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.1.1/lib/active_support/testing/declarative.rb:14:in 'test': test_should_get_help is already defined in StaticPagesControllerTest (RuntimeError) 
    from /home/nafihnafi/workspace/sample_app/test/controllers/static_pages_controller_test.rb:10:in '<class:StaticPagesControllerTest>' 
    from /home/nafihnafi/workspace/sample_app/test/controllers/static_pages_controller_test.rb:3:in '<top (required)>' 
    from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.1.1/lib/active_support/dependencies.rb:292:in 'require' 
    from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.1.1/lib/active_support/dependencies.rb:292:in 'block in require' 
    from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.1.1/lib/active_support/dependencies.rb:258:in 'load_dependency' 
    from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.1.1/lib/active_support/dependencies.rb:292:in 'require' 
    from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.1.1/lib/rails/test_unit/test_requirer.rb:14:in 'block in require_files' 
    from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.1.1/lib/rails/test_unit/test_requirer.rb:13:in 'each' 
    from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.1.1/lib/rails/test_unit/test_requirer.rb:13:in 'require_files' 
    from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.1.1/lib/rails/test_unit/minitest_plugin.rb:94:in 'plugin_rails_init' 
    from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/minitest-5.10.2/lib/minitest.rb:81:in 'block in init_plugins' 
    from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/minitest-5.10.2/lib/minitest.rb:79:in 'each' 
    from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/minitest-5.10.2/lib/minitest.rb:79:in 'init_plugins' 
    from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/minitest-5.10.2/lib/minitest.rb:130:in 'run' 
    from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.1.1/lib/rails/test_unit/minitest_plugin.rb:77:in 'run' 
    from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/minitest-5.10.2/lib/minitest.rb:63:in 'block in autorun' 
    from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in 'require' 
    from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in 'require' 
    from -e:1:in '<main>' 

回答

0

您正在定義test_should_get_help再次,當它已被定義。確保它僅被定義一次 - 把功能專用塊在這樣的文件的末尾:

[file end] 

private 

def test_should_get_help 
    [blah] 
end 

如果你需要在多個文件中,嘗試將它作爲一個幫手。

相關問題