Skip to content

Commit c795abb

Browse files
authored
Merge pull request #2402 from gnclmorais/stub-flodesk-requests
Stub Flodesk requests
2 parents efbb4f4 + 8443d31 commit c795abb

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ group :test do
111111
gem 'simplecov', require: false
112112
gem 'simplecov-lcov', require: false
113113
gem 'timecop', '~> 0.9.10'
114+
gem 'webmock'
114115
end
115116

116117
group :production do

Gemfile.lock

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ GEM
162162
commonmarker (2.5.0-x86_64-linux)
163163
concurrent-ruby (1.3.5)
164164
connection_pool (2.5.5)
165+
crack (1.0.1)
166+
bigdecimal
167+
rexml
165168
crass (1.0.6)
166169
css_parser (1.14.0)
167170
addressable
@@ -221,6 +224,7 @@ GEM
221224
rainbow
222225
rubocop (>= 1.0)
223226
sysexits (~> 1.1)
227+
hashdiff (1.2.1)
224228
hashie (5.0.0)
225229
high_voltage (4.0.0)
226230
htmlentities (4.3.4)
@@ -568,6 +572,10 @@ GEM
568572
activemodel (>= 6.0.0)
569573
bindex (>= 0.4.0)
570574
railties (>= 6.0.0)
575+
webmock (3.26.1)
576+
addressable (>= 2.8.0)
577+
crack (>= 0.3.2)
578+
hashdiff (>= 0.4.0, < 2.0.0)
571579
websocket (1.2.11)
572580
websocket-driver (0.8.0)
573581
base64
@@ -668,6 +676,7 @@ DEPENDENCIES
668676
turbo-rails
669677
tzinfo-data
670678
web-console (>= 4.1.0)
679+
webmock
671680

672681
RUBY VERSION
673682
ruby 3.4.7p58

spec/spec_helper.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'simplecov'
22
require 'simplecov-lcov'
33
require 'shoulda/matchers'
4+
require 'webmock/rspec'
45

56
# Fix incompatibility of simplecov-lcov with older versions of simplecov that are not expresses in its gemspec.
67
# https://github.com/fortissimo1997/simplecov-lcov/pull/25
@@ -33,6 +34,9 @@ def self.branch_coverage?
3334
require File.expand_path('../../config/environment', __FILE__)
3435
require 'rspec/rails'
3536

37+
# Block all external HTTP requests in tests; allows localhost for Capybara
38+
WebMock.disable_net_connect!(allow_localhost: true)
39+
3640
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
3741

3842
ActiveRecord::Migration.check_all_pending! if defined?(ActiveRecord::Migration)
@@ -70,6 +74,11 @@ def self.branch_coverage?
7074
end
7175

7276
config.before(:each) do
77+
# Stub all Flodesk API endpoints globally so tests don't make external requests
78+
# when fabricating members (which trigger Subscription.after_create callback)
79+
WebMock.stub_request(:any, %r{api\.flodesk\.com}).
80+
to_return(status: 200, body: '{"status":"active","segments":[]}', headers: { 'Content-Type' => 'application/json' })
81+
7382
DatabaseCleaner.strategy = :transaction
7483
end
7584

0 commit comments

Comments
 (0)