diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a6700318e5..be5a451cc5 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -40,14 +40,6 @@ RSpec/IdenticalEqualityAssertion: - 'spec/money/arithmetic_spec.rb' - 'spec/money_spec.rb' -# Configuration parameters: AssignmentOnly. -RSpec/InstanceVariable: - Exclude: - - 'spec/bank/variable_exchange_spec.rb' - - 'spec/money/arithmetic_spec.rb' - - 'spec/money/formatting_spec.rb' - - 'spec/money_spec.rb' - # Configuration parameters: AllowedGroups. RSpec/NestedGroups: Max: 5 @@ -170,12 +162,6 @@ Style/SafeNavigation: - 'lib/money/money.rb' - 'lib/money/money/formatter.rb' -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowAsExpressionSeparator. -Style/Semicolon: - Exclude: - - 'spec/money/formatting_spec.rb' - # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. # SupportedStyles: single_quotes, double_quotes diff --git a/spec/bank/variable_exchange_spec.rb b/spec/bank/variable_exchange_spec.rb index ee8669529a..2ed59fbf6a 100644 --- a/spec/bank/variable_exchange_spec.rb +++ b/spec/bank/variable_exchange_spec.rb @@ -165,30 +165,30 @@ end describe "#export_rates" do + let(:expected_rates) { { "USD_TO_EUR" => 1.25, "USD_TO_JPY" => 2.55 } } + before do bank.set_rate('USD', 'EUR', 1.25) bank.set_rate('USD', 'JPY', 2.55) - - @rates = { "USD_TO_EUR" => 1.25, "USD_TO_JPY" => 2.55 } end context "with format == :json" do it "returns rates formatted as json" do json = bank.export_rates(:json) - expect(JSON.load(json)).to eq @rates + expect(JSON.load(json)).to eq expected_rates end end context "with format == :ruby" do it "returns rates formatted as ruby objects" do - expect(Marshal.load(bank.export_rates(:ruby))).to eq @rates + expect(Marshal.load(bank.export_rates(:ruby))).to eq expected_rates end end context "with format == :yaml" do it "returns rates formatted as yaml" do yaml = bank.export_rates(:yaml) - expect(YAML.load(yaml)).to eq @rates + expect(YAML.load(yaml)).to eq expected_rates end end @@ -206,7 +206,7 @@ bank.export_rates(:json, 'null') - expect(f).to have_received(:write).with(JSON.dump(@rates)) + expect(f).to have_received(:write).with(JSON.dump(expected_rates)) end end diff --git a/spec/money/arithmetic_spec.rb b/spec/money/arithmetic_spec.rb index acb174462a..a703a3182d 100644 --- a/spec/money/arithmetic_spec.rb +++ b/spec/money/arithmetic_spec.rb @@ -184,12 +184,13 @@ context 'when conversions disallowed' do before do - @old_default_bank = Money.default_bank Money.disallow_currency_conversion! end - after do - Money.default_bank = @old_default_bank + around do |example| + previous_bank = Money.default_bank + example.call + Money.default_bank = previous_bank end context 'when currencies differ' do @@ -858,12 +859,13 @@ context 'when conversions disallowed' do before do - @old_default_bank = Money.default_bank Money.disallow_currency_conversion! end - after do - Money.default_bank = @old_default_bank + around do |example| + previous_bank = Money.default_bank + example.call + Money.default_bank = previous_bank end context 'when other is money with different currency' do diff --git a/spec/money/formatting_spec.rb b/spec/money/formatting_spec.rb index cff30a0884..48a491115a 100644 --- a/spec/money/formatting_spec.rb +++ b/spec/money/formatting_spec.rb @@ -110,9 +110,12 @@ end context "when in Japanese" do - before { @_locale = I18n.locale; I18n.locale = :ja } - - after { I18n.locale = @_locale } + around do |example| + previous_locale = I18n.locale + I18n.locale = :ja + example.call + I18n.locale = previous_locale + end it "formats Japanese currency properly" do money = Money.new(1000, "JPY") diff --git a/spec/money_spec.rb b/spec/money_spec.rb index 5e042e5179..f453732180 100644 --- a/spec/money_spec.rb +++ b/spec/money_spec.rb @@ -154,13 +154,13 @@ end describe ".add_rate" do - before do - @default_bank = Money.default_bank + around do |example| + previous_bank = Money.default_bank Money.default_bank = Money::Bank::VariableExchange.new - end - after do - Money.default_bank = @default_bank + example.call + + Money.default_bank = previous_bank end it "saves rate into current bank" do @@ -170,12 +170,10 @@ end describe ".disallow_currency_conversions!" do - before do - @default_bank = Money.default_bank - end - - after do - Money.default_bank = @default_bank + around do |example| + default_bank = Money.default_bank + example.call + Money.default_bank = default_bank end it "disallows conversions when doing money arithmetic" do