Skip to content

Commit f36e61f

Browse files
authored
Merge pull request solidusio#3753 from nebulab/explicit-deprecation-mocks
Explicit deprecation warning mocks
2 parents d88fff7 + b62ced6 commit f36e61f

34 files changed

+335
-253
lines changed

api/spec/requests/spree/api/checkouts_controller_spec.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,13 @@ module Spree
307307
}
308308
end
309309

310+
before do
311+
expect(Spree::Deprecation).to receive(:warn).
312+
with(/^Passing existing_card_id to PaymentCreate is deprecated/, any_args)
313+
end
314+
310315
it 'succeeds' do
311-
Spree::Deprecation.silence do
312-
put spree.api_checkout_path(order), params: params
313-
end
316+
put spree.api_checkout_path(order), params: params
314317

315318
expect(response.status).to eq 200
316319
expect(order.credit_cards).to match_array [credit_card]

core/spec/lib/spree/core/controller_helpers/order_spec.rb

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,22 @@
2121
end
2222

2323
describe '#simple_current_order' do
24+
before do
25+
expect(Spree::Deprecation).to receive(:warn).
26+
with(/^simple_current_order is deprecated and will be removed/, any_args)
27+
end
28+
2429
it "returns an empty order" do
25-
Spree::Deprecation.silence do
26-
expect(controller.simple_current_order.item_count).to eq 0
27-
end
30+
expect(controller.simple_current_order.item_count).to eq 0
2831
end
32+
2933
it 'returns Spree::Order instance' do
30-
Spree::Deprecation.silence do
31-
allow(controller).to receive_messages(cookies: double(signed: { guest_token: order.guest_token }))
32-
expect(controller.simple_current_order).to eq order
33-
end
34+
allow(controller).to receive_messages(cookies: double(signed: { guest_token: order.guest_token }))
35+
expect(controller.simple_current_order).to eq order
3436
end
37+
3538
it 'assigns the current_store id' do
36-
Spree::Deprecation.silence do
37-
expect(controller.simple_current_order.store_id).to eq store.id
38-
end
39-
end
40-
it 'is deprecated' do
41-
Spree::Deprecation.silence do
42-
expect(Spree::Deprecation).to(receive(:warn))
43-
controller.simple_current_order
44-
end
39+
expect(controller.simple_current_order.store_id).to eq store.id
4540
end
4641
end
4742

core/spec/lib/spree/core/controller_helpers/pricing_spec.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,28 @@
1313
end
1414

1515
describe '#current_currency' do
16+
before do
17+
expect(Spree::Deprecation).to receive(:warn).
18+
with(/^current_currency is deprecated and will be removed/, any_args)
19+
end
20+
1621
subject { controller.current_currency }
1722

1823
context "when store default_currency is nil" do
1924
let(:store) { nil }
20-
it { Spree::Deprecation.silence { is_expected.to eq('USD') } }
25+
it { is_expected.to eq('USD') }
2126
end
2227

2328
context "when the current store default_currency empty" do
2429
let(:store) { FactoryBot.create :store, default_currency: '' }
2530

26-
it { Spree::Deprecation.silence { is_expected.to eq('USD') } }
31+
it { is_expected.to eq('USD') }
2732
end
2833

2934
context "when the current store default_currency is a currency" do
3035
let(:store) { FactoryBot.create :store, default_currency: 'EUR' }
3136

32-
it { Spree::Deprecation.silence { is_expected.to eq('EUR') } }
37+
it { is_expected.to eq('EUR') }
3338
end
3439
end
3540

core/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,9 @@
2121

2222
describe '#permitted_checkout_attributes' do
2323
it 'returns Array class' do
24-
Spree::Deprecation.silence do
25-
expect(controller.permitted_checkout_attributes.class).to eq Spree::CheckoutAdditionalAttributes
26-
end
27-
end
28-
29-
it 'is deprecated' do
30-
expect(Spree::Deprecation).to receive(:warn)
31-
controller.permitted_checkout_attributes
24+
expect(Spree::Deprecation).to receive(:warn).
25+
with(/^checkout_attributes is deprecated/, any_args)
26+
expect(controller.permitted_checkout_attributes.class).to eq Spree::CheckoutAdditionalAttributes
3227
end
3328
end
3429

core/spec/lib/spree/core/current_store_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44

55
RSpec.describe Spree::Core::CurrentStore do
66
describe "#store" do
7-
subject { Spree::Deprecation.silence { Spree::Core::CurrentStore.new(request).store } }
7+
before do
8+
expect(Spree::Deprecation).to receive(:warn).
9+
with(/^Using Spree::Core::CurrentStore is deprecated/, any_args)
10+
end
11+
12+
subject { Spree::Core::CurrentStore.new(request).store }
813

914
context "with a default" do
1015
let(:request) { double(headers: {}, env: {}) }
@@ -24,10 +29,5 @@
2429
end
2530
end
2631
end
27-
28-
it 'is deprecated' do
29-
expect(Spree::Deprecation).to(receive(:warn))
30-
Spree::Core::CurrentStore.new(double)
31-
end
3232
end
3333
end

core/spec/lib/spree/core/role_configuration_spec.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ class OtherDummyPermissionSet < Spree::PermissionSets::Base; end
1313
let(:instance) { Spree::RoleConfiguration.new }
1414

1515
describe ".configure" do
16-
around(:each) do |example|
17-
Spree::Deprecation.silence { example.run }
16+
before do
17+
expect(Spree::Deprecation).to receive(:warn).
18+
with(/^Spree::RoleConfiguration\.configure is deprecated/i, any_args)
1819
end
1920

2021
it "yields with the instance" do
22+
expect(Spree::Deprecation).to receive(:warn).
23+
with(/^Spree::RoleConfiguration\.instance is deprecated/i, any_args)
2124
expect { |b| described_class.configure(&b) }.to yield_with_args(described_class.instance)
2225
end
2326

core/spec/lib/spree/core/testing_support/preferences_spec.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
describe 'resetting the app configuration' do
77
around do |example|
88
with_unfrozen_spree_preference_store do
9-
Spree::Deprecation.silence do
10-
example.run
11-
end
9+
example.run
1210
end
1311
end
1412

1513
before do
14+
expect(Spree::Deprecation).to receive(:warn).
15+
with(/^reset_spree_preferences is deprecated and will be removed/, any_args).
16+
at_least(:once)
1617
reset_spree_preferences
1718
@original_spree_mails_from = Spree::Config.mails_from
1819
@original_spree_searcher_class = Spree::Config.searcher_class

core/spec/lib/spree/money_spec.rb

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
describe '#initialize' do
1111
subject do
12-
Spree::Deprecation.silence do
13-
described_class.new(amount, currency: currency, with_currency: true).to_s
14-
end
12+
described_class.new(amount, currency: currency, with_currency: true).to_s
1513
end
1614

1715
context 'with no currency' do
@@ -39,30 +37,37 @@
3937
it { should == "$10.00 USD" }
4038
end
4139

42-
context "with symbol" do
43-
let(:amount){ '$10.00' }
44-
it { should == "$10.00 USD" }
45-
end
46-
47-
context "with extra currency" do
48-
let(:amount){ '$10.00 USD' }
49-
it { should == "$10.00 USD" }
50-
end
51-
52-
context "with different currency" do
53-
let(:currency){ 'USD' }
54-
let(:amount){ '$10.00 CAD' }
55-
it { should == "$10.00 CAD" }
56-
end
57-
58-
context "with commas" do
59-
let(:amount){ '1,000.00' }
60-
it { should == "$1,000.00 USD" }
61-
end
62-
63-
context "with comma for decimal point" do
64-
let(:amount){ '10,00' }
65-
it { should == "$10.00 USD" }
40+
context 'with deprecated amount format' do
41+
before do
42+
expect(Spree::Deprecation).to receive(:warn).
43+
with(/^Spree::Money was initialized with ".*", which will not be supported in the future/, any_args)
44+
end
45+
46+
context "with symbol" do
47+
let(:amount){ '$10.00' }
48+
it { should == "$10.00 USD" }
49+
end
50+
51+
context "with extra currency" do
52+
let(:amount){ '$10.00 USD' }
53+
it { should == "$10.00 USD" }
54+
end
55+
56+
context "with different currency" do
57+
let(:currency){ 'USD' }
58+
let(:amount){ '$10.00 CAD' }
59+
it { should == "$10.00 CAD" }
60+
end
61+
62+
context "with commas" do
63+
let(:amount){ '1,000.00' }
64+
it { should == "$1,000.00 USD" }
65+
end
66+
67+
context "with comma for decimal point" do
68+
let(:amount){ '10,00' }
69+
it { should == "$10.00 USD" }
70+
end
6671
end
6772

6873
context 'with fixnum' do

core/spec/lib/tasks/migrations/migrate_shipping_rate_taxes_spec.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@
44

55
RSpec.describe 'solidus:migrations:migrate_shipping_rate_taxes' do
66
describe 'up' do
7+
before do
8+
expect(Spree::Deprecation).to receive(:warn).
9+
with(/^rake spree:migrations:migrate_shipping_rate_taxes:up has been deprecated/, any_args)
10+
end
11+
712
include_context(
813
'rake',
914
task_path: Spree::Core::Engine.root.join('lib/tasks/migrations/migrate_shipping_rate_taxes.rake'),
1015
task_name: 'solidus:migrations:migrate_shipping_rate_taxes:up',
1116
)
1217

1318
it 'runs' do
14-
Spree::Deprecation.silence do
15-
expect { task.invoke }.to output(
16-
"Adding persisted tax notes to historic shipping rates ... Success.\n"
17-
).to_stdout
18-
end
19+
expect { task.invoke }.to output(
20+
"Adding persisted tax notes to historic shipping rates ... Success.\n"
21+
).to_stdout
1922
end
2023
end
2124
end

core/spec/mailers/test_mailer_spec.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@
55
RSpec.describe Spree::TestMailer, type: :mailer do
66
let(:user) { create(:user) }
77

8-
it "confirm_email accepts a user id as an alternative to a User object" do
9-
Spree::Deprecation.silence do
10-
Spree::TestMailer.test_email('[email protected]')
8+
describe '#test_email' do
9+
subject { described_class.test_email('[email protected]') }
10+
11+
it "is deprecated" do
12+
expect(Spree::Deprecation).to receive(:warn).
13+
with(/^Spree::TestMailer has been deprecated and will be removed/, any_args)
14+
15+
test_email = subject
16+
expect(test_email.to).to eq(['[email protected]'])
1117
end
1218
end
1319
end

0 commit comments

Comments
 (0)