سؤال

I just generated a scaffold in rails 3.1.10 and when I run rspec I get the following error:

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

It seems that the spec can't find the form partial when it runs render. Here's the failing part in the rails generated spec (it fails when it reaches the "render" keyword):

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

I've searched around this on google but can't find anything specific to this scaffold. I've found this SO post:

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

but it seems to suggest that render is the right way to go, i.e. the scaffold is correct. Any ideas?

Many thanks in advance

هل كانت مفيدة؟

المحلول

I have found at least a temporary solution which is to add the following to the spec before the render operation:

view.lookup_context.prefixes = %w[organizations application]

based on this documented rails issue here:

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

نصائح أخرى

The file "./app/views/organizations/edit.html" has a call at line 3 which probably reads something like

render "form" which can equate to => "organizations/_form.html.erb"

this file is missing....

you can either provide one or edit the line out in edit.html(.erb/.haml)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top