在Rails中,您如何对Javascript响应格式进行功能测试? [英] In Rails, how do you functional test a Javascript response format?
本文介绍了在Rails中,您如何对Javascript响应格式进行功能测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果您的控制器操作如下所示:
If your controller action looks like this:
respond_to do |format|
format.html { raise 'Unsupported' }
format.js # index.js.erb
end
您的功能测试如下:
test "javascript response..." do
get :index
end
它将执行的HTML分支respond_to block。
it will execute the HTML branch of the respond_to block.
如果你试试这个:
test "javascript response..." do
get 'index.js'
end
它执行视图(index.js.erb)而没有运行控制器动作!
it executes the view (index.js.erb) withOUT running the controller action!
推荐答案
传入:format
使用普通参数触发该格式的响应。
Pass in a :format
with your normal params to trigger a response in that format.
get :index, :format => 'js'
无需弄乱您的请求标题。
No need to mess with your request headers.
这篇关于在Rails中,您如何对Javascript响应格式进行功能测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文