ruby-on-rails - Rails 3.1.10 中脚手架生成的 View 规范中缺少部分错误

标签 ruby-on-rails rspec partial scaffold

我刚刚在 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

我在谷歌上搜索过这个,但找不到任何特定于这个脚手架的东西。我找到了这个帖子:

Rails: "missing partial" when calling 'render' in RSpec test

但这似乎表明渲染是正确的方法,即脚手架是正确的。有任何想法吗?

提前非常感谢

最佳答案

我至少找到了一个临时解决方案,即在渲染操作之前将以下内容添加到规范中:

view.lookup_context.prefixes = %w[组织应用程序]

基于此处记录的 Rails 问题:

https://github.com/rails/rails/issues/5213

关于ruby-on-rails - Rails 3.1.10 中脚手架生成的 View 规范中缺少部分错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15003600/

相关文章:

ruby-on-rails - 如何组织 Rails 集成/功能规范

c# - 使用 LINQ 进行选择性排序、部分排序

java - 字符串部分匹配

c++ - struct - 部分初始化跳过中间组件

ruby-on-rails - 遵循对象所有实例的操作

ruby-on-rails - 如何在 rspec 集成测试中访问 rails 请求对象?

css - 如何使用 Bootstrap 减少输入元素的宽度

Ruby:尝试测试 STDERR 输出时 RSpec 失败

ruby-on-rails - 乘客服务器升级 : Processor (CPU) Cores VS Ram?

jquery - 使用 javascript .submit() 的 AJAX Rails 复选框