开发者

What benefits do I get when testing with xhr (xml_http_request)?

My controller can respond to html, xml and json requests:

respond_to do |format|
      format.html # index.html.erb
     开发者_StackOverflow中文版 format.xml  { render :xml => @people }
      format.json { render :json => @people }
end

In my RSpec tests I normally do requests with get or post methods, e.g. get :index, :format => "json". And that works ok. What benefits do I get from requests with xhr (xhr :get, :index, :format => "json")?

I know that in the header it now states that this is an XmlHttpRequest, but respond_to also seems to work with normal request (even for xml or json).


If your respond_to works fine with http requests in all of your accepted formats, then it should be no different for AJAX requests unless there is something wrong with AJAX. If your test fails, then you are likely exposing a bug in AJAX, not in your controller code. Technically, your tests should be targeting your application, not some technology that is used by your application. On the other hand, using programmatic testing to expose a bug in a technology you're using is not a bad thing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜