Skip to content

Commit ea4d96c

Browse files
authored
Lint: Fix more RSpec cops (#768)
1 parent f8ecff7 commit ea4d96c

File tree

6 files changed

+32
-41
lines changed

6 files changed

+32
-41
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/active_record/migration_extensions/schema_statements_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
class Item < ActiveRecord::Base; end
77

88
describe MoneyRails::ActiveRecord::MigrationExtensions::SchemaStatements do
9+
# rubocop:disable RSpec/BeforeAfterAll
910
before :all do
1011
@connection = ActiveRecord::Base.connection
1112
@connection.drop_table :items if @connection.table_exists? :items
1213
@connection.create_table :items
1314
@connection.send :extend, described_class
1415
end
16+
# rubocop:enable RSpec/BeforeAfterAll
1517

1618
describe "add_money" do
1719
before do

spec/active_record/migration_extensions/table_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
class Item < ActiveRecord::Base; end
77

88
describe MoneyRails::ActiveRecord::MigrationExtensions::SchemaStatements do
9+
# rubocop:disable RSpec/BeforeAfterAll
910
before :all do
1011
@connection = ActiveRecord::Base.connection
1112
@connection.send :extend, described_class
1213
end
14+
# rubocop:enable RSpec/BeforeAfterAll
1315

1416
describe "money" do
1517
before do

spec/active_record/monetizable_spec.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ def assert_monetized_attributes(monetized_attributes, expected_attributes)
781781
# TODO: these specs should mock locale_backend with expected values
782782
# instead of manipulating it directly
783783
context "with an Italian locale" do
784-
around(:each) do |example|
784+
around do |example|
785785
I18n.with_locale(:it) do
786786
example.run
787787
end
@@ -810,7 +810,7 @@ def assert_monetized_attributes(monetized_attributes, expected_attributes)
810810
end
811811

812812
context "when using :currency locale backend" do
813-
around(:each) do |example|
813+
around do |example|
814814
Money.locale_backend = :currency
815815
example.run
816816
ensure
@@ -880,7 +880,7 @@ def assert_monetized_attributes(monetized_attributes, expected_attributes)
880880
end
881881

882882
context "with preserve_user_input set" do
883-
around(:each) do |example|
883+
around do |example|
884884
MoneyRails::Configuration.preserve_user_input = true
885885
example.run
886886
MoneyRails::Configuration.preserve_user_input = false
@@ -909,7 +909,7 @@ def assert_monetized_attributes(monetized_attributes, expected_attributes)
909909

910910
let(:read_monetized) { service.read_monetized(:discount, :discount_cents, options) }
911911

912-
around(:each) do |example|
912+
around do |example|
913913
service # Instantiate instance which relies on Money.default_currency
914914
original_default_currency = Money.default_currency
915915
Money.default_currency = -> { default_currency_lambda.read_currency }
@@ -920,9 +920,14 @@ def assert_monetized_attributes(monetized_attributes, expected_attributes)
920920
context "when allow_nil options is set" do
921921
let(:options) { { allow_nil: true } }
922922

923+
before do
924+
allow(default_currency_lambda).to receive(:read_currency)
925+
end
926+
923927
it "does not attempt to read the fallback default currency" do
924-
expect(default_currency_lambda).not_to receive(:read_currency)
925928
read_monetized
929+
930+
expect(default_currency_lambda).not_to have_received(:read_currency)
926931
end
927932
end
928933
end

spec/helpers/action_view_extension_spec.rb

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
let(:money_object) { Money.new(12500) }
3333
let(:options) { {} }
3434

35-
subject { helper.humanized_money money_object, options }
35+
subject(:humanized_money) { helper.humanized_money money_object, options }
3636

3737
it { is_expected.to be_a String }
3838
it { is_expected.not_to include Money.default_currency.symbol }
@@ -47,11 +47,14 @@
4747
context "with deprecated symbol" do
4848
let(:options) { true }
4949

50-
before(:each) do
51-
expect(helper).to receive(:warn)
50+
before do
51+
allow(helper).to receive(:warn)
5252
end
5353

54-
it { is_expected.to include Money.default_currency.symbol }
54+
it do
55+
expect(humanized_money).to include Money.default_currency.symbol
56+
expect(helper).to have_received(:warn)
57+
end
5558
end
5659

5760
context "with a currency with an alternate symbol" do
@@ -82,7 +85,9 @@
8285
describe "#money_without_cents" do
8386
let(:options) { {} }
8487

85-
subject { helper.money_without_cents Money.new(12500), options }
88+
subject(:money_without_cents) do
89+
helper.money_without_cents Money.new(12500), options
90+
end
8691

8792
it { is_expected.to be_a String }
8893
it { is_expected.not_to include Money.default_currency.symbol }
@@ -91,11 +96,14 @@
9196
context "with deprecated symbol" do
9297
let(:options) { true }
9398

94-
before(:each) do
95-
expect(helper).to receive(:warn)
99+
before do
100+
allow(helper).to receive(:warn)
96101
end
97102

98-
it { is_expected.to include Money.default_currency.symbol }
103+
it do
104+
expect(money_without_cents).to include Money.default_currency.symbol
105+
expect(helper).to have_received(:warn)
106+
end
99107
end
100108
end
101109

spec/support/database_cleaner.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
end
1212
end
1313

14-
config.before :each do
14+
config.before do
1515
DatabaseCleaner.start
1616
end
1717

18-
config.after :each do
18+
config.after do
1919
DatabaseCleaner.clean
2020
end
2121
end

0 commit comments

Comments
 (0)