From 41a578783044b4e0d5d473b8e0e1eef600d48248 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Wed, 18 Nov 2020 15:39:01 +0000 Subject: [PATCH] Extract paypal response stubbing to helper --- .../consumer/shopping/checkout_paypal_spec.rb | 12 +++--------- spec/support/request/paypal_helper.rb | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 spec/support/request/paypal_helper.rb diff --git a/spec/features/consumer/shopping/checkout_paypal_spec.rb b/spec/features/consumer/shopping/checkout_paypal_spec.rb index 107d425761..0a96e910cd 100644 --- a/spec/features/consumer/shopping/checkout_paypal_spec.rb +++ b/spec/features/consumer/shopping/checkout_paypal_spec.rb @@ -3,6 +3,7 @@ require "spec_helper" feature "Check out with Paypal", js: true do include ShopWorkflow include CheckoutHelper + include PaypalHelper let(:distributor) { create(:distributor_enterprise) } let(:supplier) { create(:supplier_enterprise) } @@ -41,20 +42,13 @@ feature "Check out with Paypal", js: true do add_product_to_cart order, product end - describe "as a guest" do + context "as a guest" do it "fails with an error message" do visit checkout_path checkout_as_guest fill_out_form(free_shipping.name, paypal.name, save_default_addresses: false) - paypal_response = double(:response, success?: false, errors: []) - paypal_provider = double( - :provider, - build_set_express_checkout: nil, - set_express_checkout: paypal_response - ) - allow_any_instance_of(Spree::PaypalController).to receive(:provider). - and_return(paypal_provider) + stub_paypal_response success: false place_order expect(page).to have_content "PayPal failed." diff --git a/spec/support/request/paypal_helper.rb b/spec/support/request/paypal_helper.rb new file mode 100644 index 0000000000..7f0ad8b5c2 --- /dev/null +++ b/spec/support/request/paypal_helper.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module PaypalHelper + def stub_paypal_response(options) + paypal_response = double(:response, success?: options[:success], errors: []) + paypal_provider = double( + :provider, + build_set_express_checkout: nil, + set_express_checkout: paypal_response + ) + allow_any_instance_of(Spree::PaypalController).to receive(:provider). + and_return(paypal_provider) + end +end