【发布时间】:2011-05-03 10:21:53
【问题描述】:
我的控制器可以响应 html、xml 和 json 请求:
respond_to 做 |格式| format.html # index.html.erb format.xml { 渲染 :xml => @people } format.json { 渲染 :json => @people } 结尾在我的 RSpec 测试中,我通常使用 get 或 post 方法进行请求,例如get :index, :format => "json"。这工作正常。我从使用 xhr (xhr :get, :index, :format => "json") 的请求中得到什么好处?
我知道现在在标头中声明这是一个 XmlHttpRequest,但 respond_to 似乎也适用于正常请求(即使是 xml 或 json)。
【问题讨论】:
标签: ruby-on-rails testing rspec xmlhttprequest