你怎么测试一个AJAX请求使用RSpec /回报率? [英] How do you test an AJAX request with RSpec/RoR?

查看:112
本文介绍了你怎么测试一个AJAX请求使用RSpec /回报率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是相当新的回报率,最近开始学习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.

这篇关于你怎么测试一个AJAX请求使用RSpec /回报率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆