【问题标题】:Michael Hartl RoR tutorial chapter 3, 2 errors with testingMichael Hartl RoR 教程第 3 章,2 个测试错误
【发布时间】:2015-03-17 20:26:15
【问题描述】:

我已经坚持了将近 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

我最终抓取了该应用程序,因为无论如何我并没有深入了解它,然后复制并粘贴到我卡住的部分,我不认为这可能是导致这种情况的错字。

这是静态页面的控制器

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>

更新

我将项目移动到我的主目录,这解决了问题。我的目录结构一定有问题。

【问题讨论】:

标签: ruby-on-rails ruby


【解决方案1】:

对于您的第一个错误,无需查看任何代码或其他任何内容,我可以告诉您://users/kevinmulhern/documents/the_odin_project/ruby_on_rails/sample_app/app/helpers/application_helper.rb_helper.rb 闻起来很糟糕(注意 application_helper.rb_helper.rb 部分中出现的两个 .rb更新: 勾选this similar question

对于第二个,您的错误消息是这样的:ActionView::MissingTemplate: Missing template static_pages/home。看看missing template 是什么意思。 (提示:你有static_pages/home.html.erb 文件吗?)

【讨论】:

  • 您好,感谢您的回复,我将应用程序帮助文件名更改为 application_helper.rb 但不幸的是,这并没有解决。是的,static_pages/home.html.erb 文件就在那里。
  • 你能用你收到的 application_helper 的新错误消息更新问题吗?
  • 我取出了 applicatio_helper 和 static_pages_helper,现在它显示另一个模板错误。生病将错误添加到帖子中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多