thoughtbot/fake_stripe

How can we trigger error responses?

tute opened this issue · 3 comments

tute commented

Stripe suggests the use of test cards against their dev APIs to trigger different error responses: https://stripe.com/docs/testing#cards.

We'd like to do the same while in testing, but couldn't find how to do that with fake stripe. How do you do it? Do you think we could include those in the gem?

Thank you! :)

srt32 commented

One way we could achieve this feature would be to make the fixture file used per action configurable.

For example, if we wanted creating a charge to fail (the default could remain create_charge), we could make config such as:

FakeStripe.set_fixtures({ create_charge: 'create_charge_failure' })

that would then be looked up when the mocked endpoint is defined.

post '/v1/charges' do
  FakeStripe.charge_count += 1
  json_response 201, fixture(FakeStripe.get_fixture_for('create_charge'))
end

The developer would then need to create a properly failed API response in a create_charge_failure file.

Did y'all have other API's in mind?

👍 I would like to be able to test in a System Test that UI is rendered based on various error codes from those test cards from the page @tute noted

Closing this because fake_stripe has been deprecated: #154