我刚刚在rails 3.1.10中生成了一个脚手架,当我运行rspec时,我收到以下错误:
Failures: 1) organizations/edit.html.erb renders the edit organization form
Failure/Error: render
Missing partial /form with {:handlers=>[:erb, :builder, :coffee], :formats=>[:html], :locale=>[:en, :en]}. Searched in:
* "/home/ubuntu/Documents/github/LocalSupport/app/views"
# ./app/views/organizations/edit.html.erb:3:in `_app_views_organizations_edit_html_erb__643434798_103899540'
# ./spec/views/organizations/edit.html.erb_spec.rb:18:in `block (2 levels) in <top (required)>'
2) organizations/new.html.erb renders new organization form
Failure/Error: render
Missing partial /form with {:handlers=>[:erb, :builder, :coffee], :formats=>[:html], :locale=>[:en, :en]}. Searched in:
* "/home/ubuntu/Documents/github/LocalSupport/app/views"
# ./app/views/organizations/new.html.erb:3:in `_app_views_organizations_new_html_erb__277486420_91000650'
# ./spec/views/organizations/new.html.erb_spec.rb:17:in `block (2 levels) in <top (required)>'
Finished in 0.68276 seconds 29 examples, 2 failures, 2 pending
似乎规范在运行渲染时无法找到部分形式。这是rails生成规范中的失败部分(当它到达“render”关键字时失败):
require 'spec_helper'
describe "organizations/index.html.erb" do
before(:each) do
assign(:organizations, [
stub_model(Organization,
:name => "Name",
:address => "Address",
:postcode => "Postcode",
:email => "Email",
:description => "Description",
:website => "",
:telephone => "Telephone"
),
stub_model(Organization,
:name => "Name",
:address => "Address",
:postcode => "Postcode",
:email => "Email",
:description => "Description",
:website => "",
:telephone => "Telephone"
)
])
end
it "renders a list of organizations" do
render
# Run the generator again with the --webrat-matchers flag if you want to use webrat matchers
assert_select "tr>td", :text => "Name".to_s, :count => 2
我在google上搜索了这个,但是找不到任何特定于这个脚手架的东西。我发现了这个帖子:
Rails: "missing partial" when calling 'render' in RSpec test
但它似乎表明渲染是正确的方法,即脚手架是正确的。有任何想法吗?
非常感谢提前
答案 0 :(得分:2)
我至少找到了一个临时解决方案,即在渲染操作之前将以下内容添加到规范中:
view.lookup_context.prefixes =%w [组织申请]
基于此记录的rails问题:
答案 1 :(得分:0)
文件“./app/views/organizations/edit.html”在第3行有一个电话,可能会读到类似
的内容渲染“形式”,它可以等同于=&gt; “组织/ _form.html.erb”
此文件丢失....
您可以在edit.html(.erb / .haml)
中提供一行或编辑该行