我正在尝试编写一个测试来验证我的控制器的动作。当手动测试时,代码按预期执行。但是,我的测试引发了一个错误,因为它无法找到我正试图呈现的模板。功能测试无法找到模板
response = {:success => true}
response[:html] = {}
response[:html][:list] = render_to_string :partial => "data_source", :locals => {:data_source => @data_source}
respond_to do |format|
format.json {render :json => response}
end
我的测试:
before do
@data_source = FactoryGirl.create :data_source, :facebook_fan_page, :account_id => @account.id, :user_id => @user.id
post :delete, :format => :json, :id => @data_source.id
end
it "should disable the data source" do
assert_equal false, @data_source.reload.enabled?
end
错误消息:
::的ActionView MissingTemplate:缺少部分data_sources/DATA_SOURCE, 捕获
从我的控制器代码片段/ data_source,application/data_source与{:locale => [:en], :格式s => [:json],:handlers => [:erb,:builder,:haml]}。搜索:
*“/ Users/me/code/my_app/app/views”*“/Users/me/code/my_app/vendor/bundle/ruby/1.9.1/gems/konacha-3.0.0/app/views“ from /Users/me/code/my_app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.17/lib/action_view/path_set.rb:58:in `find'
app/view/data_sources目录中肯定存在“_data_source.html.haml”的部分内容。
为什么测试不能找到部分?我怀疑设置问题
在此先感谢。
谢谢!我现在看到了这个问题。挖掘我的代码,在发出请求时本地运行,它的格式为*/*,因此它部分正确地呈现,但我的测试请求:json。 – Destron