0

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
mrtriangle
  • 542
  • 11
  • 28
  • possible duplicate of [How do you test an AJAX request with RSpec/RoR?](http://stackoverflow.com/questions/3971268/how-do-you-test-an-ajax-request-with-rspec-ror) – Ryan Bigg Jul 31 '13 at 23:36

1 Answers1

1

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

allenwei
  • 4,047
  • 5
  • 23
  • 26