我正在关注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'
项目结构是:
答案 0 :(得分:1)
文件名中有空格,只需将其重命名为:
_header.html.erb
_shim.html.erb