从测试中渲染部分错误

时间:2015-03-18 11:28:53

标签: ruby-on-rails railstutorial.org

我正在关注Michael Hartl Ruby on Rails教程。在5.3.1的末尾,我正在运行我们在本教程中编写的测试。对于所有4个测试/视图,它会生成以下错误:

ERROR["test_should_get_about", StaticPagesControllerTest, 0.207317345] test_should_get_about#StaticPagesControllerTest (0.21s) ActionView::Template::Error:         ActionView::Template::Error: Missing partial layouts/_shim with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in:
          * "/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/web-console-2.0.0.beta3/lib/action_dispatch/templates"
          * "/home/ubuntu/workspace/sample_app/app/views"
          * "/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/web-console-2.0.0.beta3/app/views"

            app/views/layouts/application.html.erb:9:in `_app_views_layouts_application_html_erb___3690625791535586393_66697380'
            test/controllers/static_pages_controller_test.rb:17:in `block in <class:StaticPagesControllerTest>'
        app/views/layouts/application.html.erb:9:in `_app_views_layouts_application_html_erb___3690625791535586393_66697380'
        test/controllers/static_pages_controller_test.rb:17:in `block in <class:StaticPagesControllerTest>'

我有一个文件app / views / layouts / _shim.html.erb,所以看起来没问题,而application.html.erb是:

<!DOCTYPE html>
<html>
  <head>
    <title><%= full_title(yield(:title)) %></title>
    <%= stylesheet_link_tag "application", media: "all",
                                           "data-turbolinks-track" => true %>
    <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
    <%= csrf_meta_tags %>
    <%= render 'layouts/shim' %>
  </head>
  <body>
    <%= render 'layouts/header' %>
    <div class="container">
      <%= yield %>
      <%= render 'layouts/footer' %>
    </div>
  </body>
</html>

测试是:

  test "should get about" do
    get :about
    assert_response :success
    assert_select "title", "About | Ruby on Rails Tutorial Sample App"
  end

我不明白导致错误的原因。在控制器中,它只读取def about; end和路由get 'static_pages/about'

项目结构是:

  • Sample_app
    • .bundle
    • 的.git
    • 应用
      • 资产
        • 图片
        • Javascript角
        • 样式表
      • 控制器
      • 助手
      • 邮件程序
      • 模型
        • 布局
          • _footer.html.erb
          • _header.html.erb
          • _shim.html.erb
          • application.html.erb
        • static_pages
          • about.html.erb
          • contact.html.erb
          • help.html.erb
          • home.html.erb
    • 配置
    • Db的
    • 日志
    • 公共
    • 弹簧

1 个答案:

答案 0 :(得分:1)

文件名中有空格,只需将其重命名为:

_header.html.erb
_shim.html.erb