Do not mutate config's state in specs

This commit is contained in:
Pau Perez
2019-02-14 13:11:49 +01:00
parent 609ff737ca
commit caf4441fa3
2 changed files with 16 additions and 12 deletions

View File

@@ -75,17 +75,19 @@ module Spree
end
describe "when tax on shipping is disabled" do
before { Config.shipment_inc_vat = false }
before do
allow(Config).to receive(:shipment_inc_vat).and_return(false)
end
it "records 0% tax on shipment adjustments" do
Config.shipping_tax_rate = 0
allow(Config).to receive(:shipping_tax_rate).and_return(0)
order.shipments = [shipment]
expect(order.adjustments.first.included_tax).to eq(0)
end
it "records 0% tax on shipments when a rate is set but shipment_inc_vat is false" do
Config.shipping_tax_rate = 0.25
allow(Config).to receive(:shipping_tax_rate).and_return(0.25)
order.shipments = [shipment]
expect(order.adjustments.first.included_tax).to eq(0)
@@ -93,10 +95,12 @@ module Spree
end
describe "when tax on shipping is enabled" do
before { Config.shipment_inc_vat = true }
before do
allow(Config).to receive(:shipment_inc_vat).and_return(true)
end
it "takes the shipment adjustment tax included from the system setting" do
Config.shipping_tax_rate = 0.25
allow(Config).to receive(:shipping_tax_rate).and_return(0.25)
order.shipments = [shipment]
# Finding the tax included in an amount that's already inclusive of tax:
@@ -107,7 +111,7 @@ module Spree
end
it "records 0% tax on shipments when shipping_tax_rate is not set" do
Config.shipping_tax_rate = nil
allow(Config).to receive(:shipping_tax_rate).and_return(0)
order.shipments = [shipment]
expect(order.adjustments.first.included_tax).to eq(0)

View File

@@ -229,8 +229,8 @@ describe Spree::Order do
context "with a taxed shipment" do
before do
Spree::Config.shipment_inc_vat = true
Spree::Config.shipping_tax_rate = 0.25
allow(Spree::Config).to receive(:shipment_inc_vat).and_return(true)
allow(Spree::Config).to receive(:shipping_tax_rate).and_return(0.25)
end
let!(:shipment) { create(:shipment_with, :shipping_method, shipping_method: shipping_method, order: order) }
@@ -261,8 +261,8 @@ describe Spree::Order do
describe "getting the total tax" do
before do
Spree::Config.shipment_inc_vat = true
Spree::Config.shipping_tax_rate = 0.25
allow(Spree::Config).to receive(:shipment_inc_vat).and_return(true)
allow(Spree::Config).to receive(:shipping_tax_rate).and_return(0.25)
end
let(:order) { create(:order) }
@@ -321,8 +321,8 @@ describe Spree::Order do
end
before do
Spree::Config.shipment_inc_vat = true
Spree::Config.shipping_tax_rate = tax_rate15.amount
allow(Spree::Config).to receive(:shipment_inc_vat).and_return(true)
allow(Spree::Config).to receive(:shipping_tax_rate).and_return(tax_rate15.amount)
end
let(:shipping_method) { create(:shipping_method, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 46.0)) }