1
votes

I'm using capybara with poltergeist for rspec testing in ruby on rails.

We're using stripe for payment gateway.

Request to stripe in already stub and real http connections are disabled.

However when I run the spec file alone.

It passes with the following test result.


Can add billing information to my account

Finished in 14.27 seconds (files took 4.84 seconds to load) 1 example, 0 failures


But when I run all the test it fails due to long time delay for response and I'm getting this output.

Failures:

enter image description here

My code-

scenario "Can add billing information to my account", js: true do
    within "#top-menu" do
      click_link "ACCOUNT"
    end
    click_link "Billing"

    click_link "Add billing information"

    within "#subscription" do
      fill_in "Name", with: "John Smith"
      fill_in "Email", with: "[email protected]"
      fill_in "Phone number", with: "0443 123123"
      fill_in "Company", with: "Cribber"
      fill_in "Street address", with: "14 Somewhere Street"
      fill_in "City", with: "Brisbane"
      fill_in "Postcode / Zip", with: "4000"
      fill_in "State", with: "QLD"
      select "Australia", from: "Country"
      select "Australian Dollar", from: "Currency"

      fill_in "Card number", with: "4242424242424242"
      select Time.now.year + 1, from: "card_expiry_year"
      fill_in "CVC", with: "123"

      check "subscription_billing_attributes_terms_of_service"
    end

    click_button "Subscribe"
    expect(page).to have_content("Thank you for subscribing to Cribber!")
  end

I added sleep(200) after click_button "Subscribe".But it showed the following result.

enter image description here

Can anyone please help?

Thanks in advance for helping.

I tried changing http://localhost to http://127.0.0.1 in .env.test file but I got these error.

enter image description here

enter image description here

The strange thing is that if I run the spec file alone or the feature folder for view spec then I get no error message and the test pass.But if I run

rspec spec/ then the test fails.

Can anyone help?

1

1 Answers

0
votes

It looks like the error is explained in your screenshot - while localhost and 127.0.0.1 point to the same place they are technically different origins. You need to find where you're setting the app to make a request to http://localhost/... and change it to 127.0.0.1