thoughtbot / fake_stripe

A Stripe fake so that you can avoid hitting Stripe servers in tests.
MIT License
401 stars 78 forks source link

Faster require #77

Closed odlp closed 7 years ago

odlp commented 7 years ago

Requiring fake_stripe is slow because it boots the Stripe JS server immediately, even when FakeStripe.stub_stripe hasn't been called yet.

This PR proposes:

Impact

By deferring spinning up a Capybara server until necessary there's a significant improvement on the time to require the gem.

Running command:

repeat 10 { /usr/bin/time -p bundle exec ruby -e "require 'fake_stripe'" 2>&1 } | grep real
Before (secs) After (secs)
5.85 0.71
5.74 0.71
5.75 0.72
5.81 0.69
5.81 0.7
5.72 0.68
5.72 0.67
5.81 0.71
5.79 0.7
5.81 0.66
Average: 5.781 0.695

Motivation

When I run an non-Stripe related test I don't want to experience the performance penalty. Today one would have to use the following in a Gemfile & explicitly require fake_stripe later:

gem "fake_stripe", require: false

After this PR there's far less performance impact of a vanilla require fake_stripe in the Gemfile like:

gem "fake_stripe"
derekprior commented 7 years ago

👍

samcday commented 7 years ago

@odlp it looks like this (awesome) PR never ended up in a release anywhere. Would you mind cutting a new release to RubyGems sometime?

odlp commented 7 years ago

@samcday good spot - I just released v0.1.0 to Rubygems: https://rubygems.org/gems/fake_stripe/versions/0.1.0