如何使用rspec测试Ajax请求? [英] how can I use rspec to test an Ajax request?
本文介绍了如何使用rspec测试Ajax请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在rspec中测试ajax请求,但是目前还不确定如何执行它.不管是rspec还是capybara,我都只是想让测试通过,任何建议都是非常感谢
I am trying to test an ajax request in rspec, but am not quite sure how to do it at this point It doesnt matter if it is rspec or capybara, I am just trying to get the test to pass, any advice is greatly appreciated
describe "Cart", js: true, search: true do
let(:product) { create(:product) }
let(:variant) { create(:variant, :product => product, :count_on_hand => 1, :sku=>"YIG01276") }
let(:flash_sale) { create(:flash_sale) }
let(:user) { create(:user) }
before do
flash_sale.variants << variant
flash_sale.save
product.reload
end
it "displays expiring time in cart" do
login_user user
visit spree.product_path(product)
click_button 'Add To Cart'
user.last_incomplete_spree_order.expires_in.should > 0
end
end
推荐答案
如果要在ajax调用后检查行为,例如更新视图.您需要将capybara https://github.com/jnicklas/capybara 与支持javascript的驱动程序(如硒)一起使用,Webkit
if you want to check behavior after ajax call, like update view. You need use capybara https://github.com/jnicklas/capybara with driver which support javascript, like selenium, webkit
如果您只想测试请求,则可以直接使用机架测试
if you just want to test the request, you can use rack-test directly
这篇关于如何使用rspec测试Ajax请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文