2

Rails 3.1.10 で scaffold を生成したところ、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

render を実行すると、spec が form partial を見つけられないようです。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

私はグーグルでこれを検索しましたが、この足場に固有のものは見つかりません. 私はこのSO投稿を見つけました:

Rails: RSpec テストで「render」を呼び出すと「missing partial」

しかし、render が正しい方法であること、つまり scaffold が正しいことを示唆しているようです。何か案は?

よろしくお願いします

4

2 に答える 2

2

レンダリング操作の前に仕様に以下を追加するという、少なくとも一時的な解決策を見つけました。

view.lookup_context.prefixes =%w[組織アプリケーション]

この文書化されたレールの問題に基づいて:

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

于 2013-02-21T13:56:27.433 に答える