Merge pull request #10057 from filipefurtad0/fix_rspec_mocks_deprecation_2

Updates syntax to remove depracation warnings
This commit is contained in:
jibees
2022-12-12 16:02:52 +01:00
committed by GitHub
4 changed files with 49 additions and 41 deletions

View File

@@ -170,7 +170,7 @@ module Reporting
def stub_model(model, params)
model.new.tap do |instance|
instance.stub(params)
allow(instance).to receive_messages(params)
end
end
end

View File

@@ -71,7 +71,7 @@ module Reporting
let(:permissions) do
Permissions.new(nil).tap do |instance|
instance.stub(allowed_order_cycles: [order_cycle])
allow(instance).to receive(:allowed_order_cycles) { [order_cycle] }
end
end

View File

@@ -143,7 +143,7 @@ describe Spree::Payment do
end
it "should call authorize on the gateway with the currency code" do
payment.stub currency: 'GBP'
allow(payment).to receive(:currency) { "GBP" }
expect(payment.payment_method).to receive(:authorize).with(
amount_in_cents, card, hash_including({ currency: "GBP" })
).and_return(success_response)
@@ -157,7 +157,7 @@ describe Spree::Payment do
context "when gateway does not match the environment" do
it "should raise an exception" do
gateway.stub environment: "foo"
allow(gateway).to receive(:environment) { "foo" }
expect { payment.authorize! }.to raise_error(Spree::Core::GatewayError)
end
end
@@ -200,7 +200,7 @@ describe Spree::Payment do
context "if unsuccessful" do
it "should mark payment as failed" do
gateway.stub(:authorize).and_return(failed_response)
allow(gateway).to receive(:authorize).and_return(failed_response)
expect(payment).to receive(:failure)
expect(payment).to_not receive(:pend)
expect {
@@ -224,7 +224,7 @@ describe Spree::Payment do
context "when gateway does not match the environment" do
it "should raise an exception" do
gateway.stub environment: "foo"
allow(gateway).to receive(:environment) { "foo" }
expect { payment.purchase! }.to raise_error(Spree::Core::GatewayError)
end
end
@@ -250,7 +250,7 @@ describe Spree::Payment do
context "if unsuccessful" do
it "should make payment failed" do
gateway.stub(:purchase).and_return(failed_response)
allow(gateway).to receive(:purchase).and_return(failed_response)
expect(payment).to receive(:failure)
expect(payment).not_to receive(:pend)
expect { payment.purchase! }.to raise_error(Spree::Core::GatewayError)
@@ -260,7 +260,7 @@ describe Spree::Payment do
context "#capture" do
before do
payment.stub(:complete).and_return(true)
allow(payment).to receive(:complete).and_return(true)
end
context "when payment is pending" do
@@ -279,7 +279,7 @@ describe Spree::Payment do
end
it "should store the response_code" do
gateway.stub capture: success_response
allow(gateway).to receive(:capture).and_return(success_response)
payment.capture!
expect(payment.response_code).to eq('123')
end
@@ -287,7 +287,7 @@ describe Spree::Payment do
context "if unsuccessful" do
it "should not make payment complete" do
gateway.stub capture: failed_response
allow(gateway).to receive(:capture).and_return(failed_response)
expect(payment).to receive(:failure)
expect(payment).to_not receive(:complete)
expect { payment.capture! }.to raise_error(Spree::Core::GatewayError)
@@ -315,7 +315,7 @@ describe Spree::Payment do
context "when profiles are supported" do
it "should call payment_gateway.void with the payment's response_code" do
gateway.stub payment_profiles_supported?: true
allow(gateway).to receive(:payment_profiles_supported) { true }
expect(gateway).to receive(:void).with('123', card,
anything).and_return(success_response)
payment.void_transaction!
@@ -324,8 +324,9 @@ describe Spree::Payment do
context "when profiles are not supported" do
it "should call payment_gateway.void with the payment's response_code" do
gateway.stub payment_profiles_supported?: false
expect(gateway).to receive(:void).with('123', anything).and_return(success_response)
allow(gateway).to receive(:payment_profiles_supported) { false }
expect(gateway).to receive(:void).with('123', card,
anything).and_return(success_response)
payment.void_transaction!
end
end
@@ -338,7 +339,7 @@ describe Spree::Payment do
context "when gateway does not match the environment" do
it "should raise an exception" do
payment = build_stubbed(:payment, payment_method: gateway)
gateway.stub environment: "foo"
allow(gateway).to receive(:environment) { "foo" }
expect { payment.void_transaction! }.to raise_error(Spree::Core::GatewayError)
end
end
@@ -354,7 +355,7 @@ describe Spree::Payment do
context "if unsuccessful" do
it "should not void the payment" do
gateway.stub void: failed_response
allow(gateway).to receive(:void).and_return(failed_response)
expect(payment).to_not receive(:void)
expect { payment.void_transaction! }.to raise_error(Spree::Core::GatewayError)
end
@@ -394,8 +395,8 @@ describe Spree::Payment do
context "when outstanding_balance is less than payment amount" do
before do
payment.order.stub outstanding_balance: 10
payment.stub credit_allowed: 1000
allow(payment.order).to receive(:outstanding_balance) { 10 }
allow(payment).to receive(:credit_allowed) { 1000 }
end
it "should call credit on the gateway with the credit amount and response_code" do
@@ -420,7 +421,7 @@ describe Spree::Payment do
context "when outstanding_balance is equal to payment amount" do
before do
payment.order.stub outstanding_balance: payment.amount
allow(payment.order).to receive(:outstanding_balance) { payment.amount }
end
it "should call credit on the gateway with the credit amount and response_code" do
@@ -433,7 +434,7 @@ describe Spree::Payment do
context "when outstanding_balance is greater than payment amount" do
before do
payment.order.stub outstanding_balance: 101
allow(payment.order).to receive(:outstanding_balance) { 101 }
end
it "should call credit on the gateway with the original payment amount and response_code" do
@@ -452,7 +453,7 @@ describe Spree::Payment do
context "when gateway does not match the environment" do
it "should raise an exception" do
payment = build_stubbed(:payment, payment_method: gateway)
gateway.stub environment: "foo"
allow(gateway).to receive(:environment) { "foo" }
expect { payment.credit! }.to raise_error(Spree::Core::GatewayError)
end
end
@@ -498,8 +499,8 @@ describe Spree::Payment do
context "when response is unsuccessful" do
it "should not create a payment" do
gateway.stub credit: failed_response
Spree::Payment.should_not_receive(:create)
allow(gateway).to receive(:credit).and_return(failed_response)
expect(Spree::Payment).not_to receive(:create)
expect { payment.credit! }.to raise_error(Spree::Core::GatewayError)
end
end
@@ -530,7 +531,7 @@ describe Spree::Payment do
context "raises no error if source is not specified" do
specify do
payment = build_stubbed(:payment, source: nil, payment_method: gateway)
payment.payment_method.stub(source_required?: false)
allow(payment.payment_method).to receive(:source_required?) { false }
expect { payment.process! }.not_to raise_error
end
end
@@ -539,9 +540,9 @@ describe Spree::Payment do
context "#credit_allowed" do
it "is the difference between offsets total and payment amount" do
payment = build_stubbed(:payment, amount: 100)
payment.stub(:offsets_total).and_return(0)
allow(payment).to receive(:offsets_total) { 0 }
expect(payment.credit_allowed).to eq(100)
payment.stub(:offsets_total).and_return(80)
allow(payment).to receive(:offsets_total) { 80 }
expect(payment.credit_allowed).to eq(20)
end
end
@@ -549,12 +550,12 @@ describe Spree::Payment do
context "#can_credit?" do
it "is true if credit_allowed > 0" do
payment = build_stubbed(:payment)
payment.stub(:credit_allowed).and_return(100)
allow(payment).to receive(:credit_allowed) { 100 }
expect(payment.can_credit?).to be true
end
it "is false if credit_allowed is 0" do
payment = build_stubbed(:payment)
payment.stub(:credit_allowed).and_return(0)
allow(payment).to receive(:credit_allowed) { 0 }
expect(payment.can_credit?).to be false
end
end
@@ -569,13 +570,13 @@ describe Spree::Payment do
payment.order = create(:order)
payment.state = 'completed'
payment.stub(:credit_allowed).and_return(10)
allow(payment).to receive(:credit_allowed) { 10 }
payment.partial_credit(10)
expect(payment).to be_processing
end
it "calls credit on the source with the payment and amount" do
payment.state = 'completed'
payment.stub(:credit_allowed).and_return(10)
allow(payment).to receive(:credit_allowed) { 10 }
expect(payment).to receive(:credit!).with(10)
payment.partial_credit(10)
end
@@ -584,7 +585,7 @@ describe Spree::Payment do
it "should not call credit on the source" do
payment = build_stubbed(:payment)
payment.state = 'completed'
payment.stub(:credit_allowed).and_return(10)
allow(payment).to receive(:credit_allowed) { 10 }
payment.partial_credit(20)
expect(payment).to be_completed
end
@@ -636,8 +637,8 @@ describe Spree::Payment do
context "when profiles are supported" do
before do
gateway.stub payment_profiles_supported?: true
payment.source.stub has_payment_profile?: false
allow(gateway).to receive(:payment_profiles_supported?) { true }
allow(payment.source).to receive(:has_payment_profile?) { false }
end
context "when there is an error connecting to the gateway" do
@@ -679,14 +680,16 @@ describe Spree::Payment do
end
context "when profiles are not supported" do
before { gateway.stub payment_profiles_supported?: false }
before do
allow(gateway).to receive(:payment_profiles_supported?) { false }
end
it "should not create a payment profile" do
gateway.name = 'Gateway'
gateway.distributors << create(:distributor_enterprise)
gateway.save!
gateway.should_not_receive :create_profile
expect(gateway).to_not receive :create_profile
payment = Spree::Payment.create(
amount: 100,
order: create(:order),
@@ -748,7 +751,9 @@ describe Spree::Payment do
# Regression test for #2216
context "#gateway_options" do
before { order.stub(last_ip_address: "192.168.1.1") }
before do
allow(order).to receive(:last_ip_address) { "192.168.1.1" }
end
it "contains an IP" do
expect(payment.gateway_options[:ip]).to eq(order.last_ip_address)

View File

@@ -61,7 +61,7 @@ module Spree
end
it "should return an empty array" do
order.stub tax_zone: @zone
allow(order).to receive(:tax_zone) { @zone }
expect(Spree::TaxRate.match(order)).to eq []
end
@@ -73,7 +73,8 @@ module Spree
calculator: calculator
)
order.stub tax_zone: @zone
allow(order).to receive(:tax_zone) { @zone }
expect(Spree::TaxRate.match(order)).to eq [rate]
end
@@ -92,7 +93,8 @@ module Spree
calculator: ::Calculator::FlatRate.new
)
order.stub tax_zone: @zone
allow(order).to receive(:tax_zone) { @zone }
expect(Spree::TaxRate.match(order)).to eq [rate1, rate2]
end
@@ -100,7 +102,8 @@ module Spree
before do
sub_zone = create(:zone, name: "State Zone", zone_members: [])
sub_zone.zone_members.create(zoneable: create(:state, country: country))
order.stub tax_zone: sub_zone
allow(order).to receive(:tax_zone) { sub_zone }
@rate = Spree::TaxRate.create(
amount: 1,
zone: @zone,
@@ -134,8 +137,8 @@ module Spree
context "when the order has the same tax zone" do
before do
order.stub tax_zone: @zone
order.stub billing_address: tax_address
allow(order).to receive(:tax_zone) { @zone }
allow(order).to receive(:billing_address) { tax_address }
end
let(:tax_address) { build_stubbed(:address) }