从测试中渲染部分错误
Render partial error from test
我正在关注 Rails 教程中的 Michael Hartl Ruby。在第 5.3.1 段的末尾,我是 运行 我们作为教程的一部分编写的测试。对于所有 4 tests/views,它会生成以下错误:
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
- .捆绑
- .git
- 应用程序
- 资产
- 图片
- Javascripts
- 样式表
- 控制器
- 助手
- 邮寄者
- 型号
- 观看次数
- 布局
- _footer.html.erb
- _header.html.erb
- _shim.html.erb
- 申请.html.erb
- static_pages
- 关于.html.erb
- 联系。html.erb
- 帮助。html.erb
- 家.html.erb
- 斌
- 配置
- Db
- 库
- 日志
- Public
- Spring
您的文件名中有空格,只需将它们重命名为:
_header.html.erb
_shim.html.erb
我正在关注 Rails 教程中的 Michael Hartl Ruby。在第 5.3.1 段的末尾,我是 运行 我们作为教程的一部分编写的测试。对于所有 4 tests/views,它会生成以下错误:
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
- .捆绑
- .git
- 应用程序
- 资产
- 图片
- Javascripts
- 样式表
- 控制器
- 助手
- 邮寄者
- 型号
- 观看次数
- 布局
- _footer.html.erb
- _header.html.erb
- _shim.html.erb
- 申请.html.erb
- static_pages
- 关于.html.erb
- 联系。html.erb
- 帮助。html.erb
- 家.html.erb
- 布局
- 资产
- 斌
- 配置
- Db
- 库
- 日志
- Public
- Spring
您的文件名中有空格,只需将它们重命名为:
_header.html.erb
_shim.html.erb