如何使用 RSpec/RoR 测试 AJAX 请求? [英] How do you test an AJAX request with RSpec/RoR?

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

问题描述

我对 RoR 还很陌生,最近开始学习 BDD/Rspec 以测试我的应用程序.我一直在寻找一种规范 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.

有人知道怎么做吗?我的存根使用 rails 2.3.8、rspec 1.3.0 和 mocha 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

使用 GET 向索引操作发出 XmlHttpRequest (AJAX) 请求.

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

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

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