我已经坚持了近4个小时了。在本章中,我们被要求首次运行测试。它输出两个错误,我不明白它们是什么。
这些是错误:
Finished in 0.097197s, 20.5768 runs/s, 0.0000 assertions/s.
1) Error:
StaticPagesControllerTest#test_should_get_help:
AbstractController::Helpers::MissingHelperError: Missing helper file helpers//users/kevinmulhern/documents/the_odin_project/ruby_on_rails/sample_app/app/helpers/application_helper.rb_helper.rb
app/controllers/application_controller.rb:1:in `<top (required)>'
app/controllers/static_pages_controller.rb:1:in `<top (required)>'
2) Error:
StaticPagesControllerTest#test_should_get_home:
ActionView::MissingTemplate: Missing template static_pages/home, application/home with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in:
* "/Users/kevinmulhern/.rvm/gems/ruby-2.2.0/gems/web-console-2.0.0.beta3/lib/action_dispatch/templates"
* "/Users/kevinmulhern/documents/the_odin_project/ruby_on_rails/sample_app/app/views"
* "/Users/kevinmulhern/.rvm/gems/ruby-2.2.0/gems/web-console-2.0.0.beta3/app/views"
test/controllers/static_pages_controller_test.rb:5:in `block in <class:StaticPagesControllerTest>'
2 runs, 0 assertions, 0 failures, 2 errors, 0 skips
我最终还是刮了一下应用程序,因为我还没有那么远,然后复制并粘贴回到我被卡住的部分,我不认为这可能是一个错字造成的。
继承人StaticPages的控制器
class StaticPagesController < ApplicationController
def home
end
def help
end
end
最后这里是测试文件:
require 'test_helper'
class StaticPagesControllerTest < ActionController::TestCase
test "should get home" do
get :home
assert_response :success
end
test "should get help" do
get :help
assert_response :success
end
end
非常感谢任何帮助。
删除帮助后更新错误:
1) Error:
StaticPagesControllerTest#test_should_get_home:
ActionView::MissingTemplate: Missing template static_pages/home, application/home with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in:
* "/Users/kevinmulhern/.rvm/gems/ruby-2.2.0/gems/web-console-2.0.0.beta3/lib/action_dispatch/templates"
* "/Users/kevinmulhern/documents/the_odin_project/ruby_on_rails/sample_app/app/views"
* "/Users/kevinmulhern/.rvm/gems/ruby-2.2.0/gems/web-console-2.0.0.beta3/app/views"
test/controllers/static_pages_controller_test.rb:5:in `block in <class:StaticPagesControllerTest>
更新
我将项目移动到我的主目录,这解决了问题。我的目录结构一定有问题。
答案 0 :(得分:0)
对于您的第一个错误,没有查看任何代码或其他任何我可以告诉您://users/kevinmulhern/documents/the_odin_project/ruby_on_rails/sample_app/app/helpers/application_helper.rb_helper.rb
闻起来很糟糕(注意.rb
部分中出现的两个application_helper.rb_helper.rb
< strong>更新:检查this similar question。
对于第二个,您的错误消息是:ActionView::MissingTemplate: Missing template static_pages/home
。浏览missing template
的含义。 (提示:您有static_pages/home.html.erb
个文件吗?)