7

編集:

view.lookup_context.prefixes = %w[base]の前に挿入するrenderと、テストは適切なパスを認識していることがわかりました。これはこれを解決する最善/適切な方法ですか?


すべてのパーシャルをベース フォルダーに配置し、これらのパーシャルにアクセスできるすべてのコントローラーがbase_controllerこのすべてを継承してうまく機能しますが、生成されたビュー テストはベース フォルダーにあるパーシャルを見つけることができません。

エラーは次のとおりです。

Failure/Error: render
     ActionView::Template::Error:
       Missing partial /admin_menu, circuits/admin_menu with {:locale=>[:en], :formats=>[:html, :text, :js, :css, :ics, :csv, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip], :handlers=>[:erb, :builder, :coffee, :jbuilder]}. Searched in:
         * "/Users/Mac/Folder/ProjectName/app/views"

パーシャルを探す場所をビュー テストに伝えるにはどうすればよいですか?

完全を期すために、仕様は次のとおりです。

require 'spec_helper'

describe "circuits/index" do
  before(:each) do
    assign(:circuits, [
      stub_model(Circuit,
        :name => "Name",
        :description => "MyText"
      ),
      stub_model(Circuit,
        :name => "Name",
        :description => "MyText"
      )
    ])
  end

  it "renders a list of circuits" do
    view.lookup_context.prefixes = %w[base application]
    render
    assert_select "tr>td", :text => "Name".to_s, :count => 2
    assert_select "tr>td", :text => "MyText".to_s, :count => 2
  end
end
4

2 に答える 2