你怎么测试一个AJAX请求使用RSpec /回报率?你怎么、回报率、测试、AJAX

2023-09-11 00:47:03 作者:你的情误伤了我/

我是相当新的回报率,最近开始学习BDD / RSpec测试,我的应用程序。我一直在寻找一种方式来SPEC一个AJAX请求,但到目前为止,我还没有发现太多的文档对这个在所有。

I'm fairly new to RoR and recently started learning BDD/Rspec for testing my application. I've been looking for a way to spec an AJAX request, but so far I haven't found much documentation on this at all.

任何人都知道如何做到这一点?我使用的铁轨2.3.8,RSpec的1.3.0和0.9.8摩卡我的存根(这我也是在学习的过程中...)

Anyone know how to do this? I'm using rails 2.3.8, rspec 1.3.0 and mocha 0.9.8 for my stubs (which I'm also in the process of learning...)

推荐答案

如果你在谈论的内部控制器的规格测试它,您通常称之为

If you're talking about testing it inside your controller specs, where you normally call

get :index

做一个HTTP请求到该指数的动作,你会改为调用

to make an HTTP request to the index action, you would instead call

xhr :get, :index

作出XmlHtt prequest使用GET(AJAX)请求index操作。

to make an XmlHttpRequest (AJAX) request to the index action using GET.

 
精彩推荐
图片推荐