编辑:
我发现如果我在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