From d75ba79b3d186e4c78d2a3894aa346e8697a3098 Mon Sep 17 00:00:00 2001 From: CactusPuppy Date: Tue, 23 Mar 2021 13:01:22 -0700 Subject: [PATCH] Fix up RSpec tests --- spec/factories/users.rb | 1 + spec/helpers/external/mailbluster_helper_spec.rb | 5 +++++ spec/spec_helper.rb | 4 ++-- spec/support/external_request.rb | 5 +++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/spec/factories/users.rb b/spec/factories/users.rb index fdd60d67..75af7370 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -97,6 +97,7 @@ FactoryBot.define do } }" WebMock.stub_request(:post, url_mailbluster) + .to_return(body: response_body, status: 200) end # Called by every user creation diff --git a/spec/helpers/external/mailbluster_helper_spec.rb b/spec/helpers/external/mailbluster_helper_spec.rb index fa94ed37..d06fff0c 100644 --- a/spec/helpers/external/mailbluster_helper_spec.rb +++ b/spec/helpers/external/mailbluster_helper_spec.rb @@ -5,6 +5,11 @@ require 'webmock/rspec' describe External::MailblusterHelper, type: :helper do let!(:user) { create(:user) } + + before(:each) do + WebMock.reset_executed_requests! + end + url = 'https://api.mailbluster.com/api/leads/' describe 'create_lead' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 32fc961c..6021d4ab 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,8 +13,8 @@ ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) # Prevent tests from making calls to the Internet -require 'webmock/rspec' -WebMock.disable_net_connect!(allow_localhost: true) +# require 'webmock/rspec' +# WebMock.disable_net_connect!(allow_localhost: true) require 'rspec/rails' require 'shoulda/matchers' diff --git a/spec/support/external_request.rb b/spec/support/external_request.rb index c968acd3..fbedd9e3 100644 --- a/spec/support/external_request.rb +++ b/spec/support/external_request.rb @@ -11,6 +11,7 @@ RSpec.configure do |config| config.before(:each) do mock_commercial_request mock_image_request + mock_default_mailbluster end end @@ -39,3 +40,7 @@ def mock_image_request WebMock.stub_request(:post, 'https://api.cloudinary.com/v1_1/snapcon/image/destroy') .to_return(status: 200, body: {}.to_json, headers: {}) end + +def mock_default_mailbluster + WebMock.stub_request(:any, /api.mailbluster.com/) +end