Skip to content

Commit 915d55e

Browse files
committed
Lint: Fix RSpec/InstanceVariable
1 parent e6c56f6 commit 915d55e

File tree

5 files changed

+29
-54
lines changed

5 files changed

+29
-54
lines changed

.rubocop_todo.yml

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

spec/bank/variable_exchange_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,30 +165,30 @@
165165
end
166166

167167
describe "#export_rates" do
168+
let(:expected_rates) { { "USD_TO_EUR" => 1.25, "USD_TO_JPY" => 2.55 } }
169+
168170
before do
169171
bank.set_rate('USD', 'EUR', 1.25)
170172
bank.set_rate('USD', 'JPY', 2.55)
171-
172-
@rates = { "USD_TO_EUR" => 1.25, "USD_TO_JPY" => 2.55 }
173173
end
174174

175175
context "with format == :json" do
176176
it "returns rates formatted as json" do
177177
json = bank.export_rates(:json)
178-
expect(JSON.load(json)).to eq @rates
178+
expect(JSON.load(json)).to eq expected_rates
179179
end
180180
end
181181

182182
context "with format == :ruby" do
183183
it "returns rates formatted as ruby objects" do
184-
expect(Marshal.load(bank.export_rates(:ruby))).to eq @rates
184+
expect(Marshal.load(bank.export_rates(:ruby))).to eq expected_rates
185185
end
186186
end
187187

188188
context "with format == :yaml" do
189189
it "returns rates formatted as yaml" do
190190
yaml = bank.export_rates(:yaml)
191-
expect(YAML.load(yaml)).to eq @rates
191+
expect(YAML.load(yaml)).to eq expected_rates
192192
end
193193
end
194194

@@ -206,7 +206,7 @@
206206

207207
bank.export_rates(:json, 'null')
208208

209-
expect(f).to have_received(:write).with(JSON.dump(@rates))
209+
expect(f).to have_received(:write).with(JSON.dump(expected_rates))
210210
end
211211
end
212212

spec/money/arithmetic_spec.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,13 @@
184184

185185
context 'when conversions disallowed' do
186186
before do
187-
@old_default_bank = Money.default_bank
188187
Money.disallow_currency_conversion!
189188
end
190189

191-
after do
192-
Money.default_bank = @old_default_bank
190+
around do |example|
191+
previous_bank = Money.default_bank
192+
example.call
193+
Money.default_bank = previous_bank
193194
end
194195

195196
context 'when currencies differ' do
@@ -858,12 +859,13 @@
858859

859860
context 'when conversions disallowed' do
860861
before do
861-
@old_default_bank = Money.default_bank
862862
Money.disallow_currency_conversion!
863863
end
864864

865-
after do
866-
Money.default_bank = @old_default_bank
865+
around do |example|
866+
previous_bank = Money.default_bank
867+
example.call
868+
Money.default_bank = previous_bank
867869
end
868870

869871
context 'when other is money with different currency' do

spec/money/formatting_spec.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,12 @@
110110
end
111111

112112
context "when in Japanese" do
113-
before { @_locale = I18n.locale; I18n.locale = :ja }
114-
115-
after { I18n.locale = @_locale }
113+
around do |example|
114+
previous_locale = I18n.locale
115+
I18n.locale = :ja
116+
example.call
117+
I18n.locale = previous_locale
118+
end
116119

117120
it "formats Japanese currency properly" do
118121
money = Money.new(1000, "JPY")

spec/money_spec.rb

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,13 @@
154154
end
155155

156156
describe ".add_rate" do
157-
before do
158-
@default_bank = Money.default_bank
157+
around do |example|
158+
previous_bank = Money.default_bank
159159
Money.default_bank = Money::Bank::VariableExchange.new
160-
end
161160

162-
after do
163-
Money.default_bank = @default_bank
161+
example.call
162+
163+
Money.default_bank = previous_bank
164164
end
165165

166166
it "saves rate into current bank" do
@@ -170,12 +170,10 @@
170170
end
171171

172172
describe ".disallow_currency_conversions!" do
173-
before do
174-
@default_bank = Money.default_bank
175-
end
176-
177-
after do
178-
Money.default_bank = @default_bank
173+
around do |example|
174+
default_bank = Money.default_bank
175+
example.call
176+
Money.default_bank = default_bank
179177
end
180178

181179
it "disallows conversions when doing money arithmetic" do

0 commit comments

Comments
 (0)