thoughtbot / fake_stripe

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

Using gem blocks all external HTTP requests #64

Closed jdbann closed 1 month ago

jdbann commented 8 years ago

Added FakeStripe to a test suite not currently using WebMock and it blocked a number of calls to third-party services. Whilst I eventually want to mock all those calls, I didn't expect this gem to block anything beyond Stripe. Looks like the problem line is this in the WebMock initialiser.

WebMock.disable_net_connect!(allow_localhost: true)

I can put in a PR to remove that line but wanted to check if there was a reason it was in there? My assumption is that so the gem would catch any requests to Stripe that didn't match the two stubbed requests:

# fake_stripe/fake_stripe.rb:35
    stub_request(:any, /api.stripe.com/).to_rack(FakeStripe::StubApp)
    stub_request(:any, /js.stripe.com/).to_rack(FakeStripe::StubApp)
bopm commented 7 years ago

Still, it can be easily fixed by something like that:

# spec/support/fake_stripe.rb
require 'webmock/rspec'
require 'fake_stripe'

RSpec.configure do |config|
  config.before(:each) do
    FakeStripe.stub_stripe
    WebMock.disable!
    WebMock.enable!
    WebMock.disable_net_connect!(allow_localhost: true, allow: ['cloud.typography.com', 'cloud.typenetwork.com'])
  end
end
stefannibrasil commented 1 month ago

Closing this because fake_stripe has been deprecated: https://github.com/thoughtbot/fake_stripe/pull/154