diff --git a/spec/support/request/stripe_helper.rb b/spec/support/request/stripe_helper.rb index 17d8893c2b..3aeef17e43 100644 --- a/spec/support/request/stripe_helper.rb +++ b/spec/support/request/stripe_helper.rb @@ -28,9 +28,18 @@ module StripeHelper fill_in "cvc", with: "678" end - def setup_stripe - Stripe.api_key = "sk_test_12345" - Stripe.publishable_key = "pk_test_12345" + def stripe_enable allow(Spree::Config).to receive(:stripe_connect_enabled).and_return(true) end + + def with_stripe_setup(api_key = "sk_test_12345", publishable_key = "pk_test_12345") + original_keys = [Stripe.api_key, Stripe.publishable_key] + + Stripe.api_key = api_key + Stripe.publishable_key = publishable_key + + yield + + Stripe.api_key, Stripe.publishable_key = original_keys + end end diff --git a/spec/system/admin/payments_stripe_spec.rb b/spec/system/admin/payments_stripe_spec.rb index 7852fbfcda..77374225c1 100644 --- a/spec/system/admin/payments_stripe_spec.rb +++ b/spec/system/admin/payments_stripe_spec.rb @@ -18,9 +18,11 @@ describe ' create(:stripe_account, enterprise: order.distributor, stripe_user_id: "abc123") end - before { setup_stripe } + around do |example| + with_stripe_setup { example.run } + end - context "making a new Stripe payment", js: true do + context "making a new Stripe payment" do before do stub_payment_methods_post_request stub_payment_intent_get_request diff --git a/spec/system/consumer/shopping/checkout_stripe_spec.rb b/spec/system/consumer/shopping/checkout_stripe_spec.rb index c91d64de10..15a0aa53cf 100644 --- a/spec/system/consumer/shopping/checkout_stripe_spec.rb +++ b/spec/system/consumer/shopping/checkout_stripe_spec.rb @@ -30,8 +30,12 @@ describe "Check out with Stripe", js: true do calculator: Calculator::FlatRate.new(preferred_amount: 5.67)) } + around do |example| + with_stripe_setup { example.run } + end + before do - setup_stripe + stripe_enable set_order order add_product_to_cart order, product distributor.shipping_methods << [shipping_with_fee, free_shipping] diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index b5e21b83ce..071fccc627 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -644,8 +644,12 @@ describe "As a consumer, I want to checkout my order", js: true do end context "for Stripe SCA", if: pay_method.eql?("Stripe SCA") do + around do |example| + with_stripe_setup { example.run } + end + before do - setup_stripe + stripe_enable visit checkout_step_path(:payment) end