[英]how can I use rspec to test an Ajax request?
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 我正在尝试在rspec中测试ajax请求,但是现在还不确定如何执行它。无论是rspec还是capybara,我都只是想通过测试,因此非常感谢任何建议
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
if you want to check behavior after ajax call, like update view. 如果要在ajax调用后检查行为,例如更新视图。 You need use capybara https://github.com/jnicklas/capybara with driver which support javascript, like selenium, webkit 您需要将capybara https://github.com/jnicklas/capybara与支持javascript的驱动程序一起使用,例如selenium,webkit
if you just want to test the request, you can use rack-test directly 如果您只想测试请求,则可以直接使用机架测试
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.