Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use puffing-billy and VCR to prevent testing stripe's checkout from creating endless new files?

I am using puffing-billy/vcr/capybara/rspec to write a feature spec that is testing my use of the stripe gem. My specs are passing but I have been unable to get puffing-billy to use cached data rather than creating new files each time I run rspec.

Is it possible to test the stripe checkout functionality without hitting the network or mocking anything else?

like image 516
Eric Avatar asked Jan 19 '26 11:01

Eric


1 Answers

You can use the merge_cached_responses_whitelist option to merge responses. It was difficult to figure out the correct syntax for URLs, but this is what I figured out:

  • The rules MUST be regexes. I tried using strings and it froze my tests.
  • You must NOT include the protocol in your regex (e.g. https?:\/\/)
  • For HTTPS urls, you must handle port :443 after the domain

Here's my rules to cache some Stripe responses on the front-end:

config.merge_cached_responses_whitelist = [
  /api\.stripe\.com(:443)*\/v1\/tokens/,
  /m\.stripe\.com(:443)*\/4/
]

Another important tip is that puffing-billy logs are not printed to your console, but go directly into your test logs at log/test.log. It really helps if you keep an eye on your test logs with:

tail -f log/test.log

You will see lines like this:

puffing-billy: CACHE KEY for 'https://api.stripe.com:443/v1/tokens' is 'post_e23c813681b1bac66ef1cc6f5f1b56108a18ec52'
puffing-billy: CACHE post for 'https://api.stripe.com:443/v1/tokens'
puffing-billy: CACHE KEY for 'https://m.stripe.com:443/4' is post_8072c2c958962829d4ba630f02301dc3a51f6a6e'
puffing-billy: CACHE post for 'https://m.stripe.com:443/4'
like image 169
ndbroadbent Avatar answered Jan 21 '26 02:01

ndbroadbent



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!