Skip to content

Commit

Permalink
Refactor Spree::PaymentMethod specs
Browse files Browse the repository at this point in the history
to avoid polluting the global namespace, in fact those
classes were defined on a global Object and avaiable in
all the rest of the test suite after their first run.

This will reduce the possibility of flacky specs.
  • Loading branch information
kennyadsl committed Jan 9, 2023
1 parent 16d1e37 commit cb0cb9b
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions core/spec/models/spree/payment_method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,15 @@
end

describe '#auto_capture?' do
class TestGateway < Spree::PaymentMethod::CreditCard
def gateway_class
Provider
let(:gateway) do
gateway_class = Class.new(Spree::PaymentMethod::CreditCard) do
def gateway_class
Provider
end
end
end

let(:gateway) { TestGateway.new }
gateway_class.new
end

subject { gateway.auto_capture? }

Expand Down Expand Up @@ -174,28 +176,28 @@ def gateway_class
end

describe 'ActiveMerchant methods' do
class PaymentGateway
def initialize(options)
end

def authorize; 'authorize'; end
let(:payment_method) do
payment_method_class = Class.new(Spree::PaymentMethod) do
def gateway_class
Class.new do
def initialize(options)
end

def purchase; 'purchase'; end
def authorize; 'authorize'; end

def capture; 'capture'; end
def purchase; 'purchase'; end

def void; 'void'; end
def capture; 'capture'; end

def credit; 'credit'; end
end
def void; 'void'; end

class TestPaymentMethod < Spree::PaymentMethod
def gateway_class
PaymentGateway
def credit; 'credit'; end
end
end
end
end

let(:payment_method) { TestPaymentMethod.new }
payment_method_class.new
end

it "passes through authorize" do
expect(payment_method.authorize).to eq 'authorize'
Expand Down

0 comments on commit cb0cb9b

Please sign in to comment.