Skip to content

Commit 02fe18d

Browse files
authored
Lint: RSpec cops (#1181)
1 parent b350fe1 commit 02fe18d

17 files changed

+119
-192
lines changed

.rubocop.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ Lint/EmptyClass:
3939
# Allow defining empty classes, since it can be used as a base class.
4040
Enabled: false
4141

42+
# RSpec
43+
44+
RSpec/DescribedClass:
45+
Exclude:
46+
# Prefer Money.new(…) to described_class.new(…)
47+
- 'spec/money_spec.rb'
48+
- 'spec/money/formatting_spec.rb'
49+
4250
# Style
4351

4452
Style/ClassAndModuleChildren:

.rubocop_todo.yml

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

spec/bank/base_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def setup
2727
end
2828

2929
bank = MyBank.new
30-
expect(bank.setup_called).to eq true
30+
expect(bank.setup_called).to be true
3131
end
3232
end
3333

@@ -39,19 +39,19 @@ def setup
3939

4040
describe "#same_currency?" do
4141
it "accepts str/str" do
42-
expect { subject.send(:same_currency?, 'USD', 'EUR') }.to_not raise_error
42+
expect { subject.send(:same_currency?, 'USD', 'EUR') }.not_to raise_error
4343
end
4444

4545
it "accepts currency/str" do
46-
expect { subject.send(:same_currency?, Money::Currency.wrap('USD'), 'EUR') }.to_not raise_error
46+
expect { subject.send(:same_currency?, Money::Currency.wrap('USD'), 'EUR') }.not_to raise_error
4747
end
4848

4949
it "accepts str/currency" do
50-
expect { subject.send(:same_currency?, 'USD', Money::Currency.wrap('EUR')) }.to_not raise_error
50+
expect { subject.send(:same_currency?, 'USD', Money::Currency.wrap('EUR')) }.not_to raise_error
5151
end
5252

5353
it "accepts currency/currency" do
54-
expect { subject.send(:same_currency?, Money::Currency.wrap('USD'), Money::Currency.wrap('EUR')) }.to_not raise_error
54+
expect { subject.send(:same_currency?, Money::Currency.wrap('USD'), Money::Currency.wrap('EUR')) }.not_to raise_error
5555
end
5656

5757
it "returns true when currencies match" do

spec/bank/variable_exchange_spec.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@
3434

3535
describe "#exchange_with" do
3636
it "accepts str" do
37-
expect { bank.exchange_with(Money.new(100, 'USD'), 'EUR') }.to_not raise_error
37+
expect { bank.exchange_with(Money.new(100, 'USD'), 'EUR') }.not_to raise_error
3838
end
3939

4040
it "accepts currency" do
41-
expect { bank.exchange_with(Money.new(100, 'USD'), Money::Currency.wrap('EUR')) }.to_not raise_error
41+
expect { bank.exchange_with(Money.new(100, 'USD'), Money::Currency.wrap('EUR')) }.not_to raise_error
4242
end
4343

4444
it "exchanges one currency to another" do
@@ -109,7 +109,7 @@
109109
describe "#add_rate" do
110110
it 'delegates to store#add_rate' do
111111
expect(subject.store).to receive(:add_rate).with('USD', 'EUR', 1.25).and_return 1.25
112-
expect(subject.add_rate('USD', 'EUR', 1.25)).to eql 1.25
112+
expect(subject.add_rate('USD', 'EUR', 1.25)).to be 1.25
113113
end
114114

115115
it "adds rates with correct ISO codes" do
@@ -129,7 +129,7 @@
129129
describe "#set_rate" do
130130
it 'delegates to store#add_rate' do
131131
expect(subject.store).to receive(:add_rate).with('USD', 'EUR', 1.25).and_return 1.25
132-
expect(subject.set_rate('USD', 'EUR', 1.25)).to eql 1.25
132+
expect(subject.set_rate('USD', 'EUR', 1.25)).to be 1.25
133133
end
134134

135135
it "sets a rate" do
@@ -159,28 +159,28 @@
159159
end
160160

161161
describe "#export_rates" do
162-
before :each do
162+
before do
163163
subject.set_rate('USD', 'EUR', 1.25)
164164
subject.set_rate('USD', 'JPY', 2.55)
165165

166166
@rates = { "USD_TO_EUR" => 1.25, "USD_TO_JPY" => 2.55 }
167167
end
168168

169169
context "with format == :json" do
170-
it "should return rates formatted as json" do
170+
it "returns rates formatted as json" do
171171
json = subject.export_rates(:json)
172172
expect(JSON.load(json)).to eq @rates
173173
end
174174
end
175175

176176
context "with format == :ruby" do
177-
it "should return rates formatted as ruby objects" do
177+
it "returns rates formatted as ruby objects" do
178178
expect(Marshal.load(subject.export_rates(:ruby))).to eq @rates
179179
end
180180
end
181181

182182
context "with format == :yaml" do
183-
it "should return rates formatted as yaml" do
183+
it "returns rates formatted as yaml" do
184184
yaml = subject.export_rates(:yaml)
185185
expect(YAML.load(yaml)).to eq @rates
186186
end
@@ -263,7 +263,7 @@
263263

264264
describe "#marshal_dump" do
265265
it "does not raise an error" do
266-
expect { Marshal.dump(subject) }.to_not raise_error
266+
expect { Marshal.dump(subject) }.not_to raise_error
267267
end
268268

269269
it "works with Marshal.load" do

spec/currency/heuristics_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
RSpec.describe Money::Currency::Heuristics do
44
describe "#analyze_string" do
5-
it "it raises deprecation error" do
5+
it "raises deprecation error" do
66
expect { Money::Currency.analyze('123') }.to raise_error(StandardError, 'Heuristics deprecated, add `gem "money-heuristics"` to Gemfile')
77
end
88
end

spec/currency_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,17 @@ def to_s
134134
it "returns an array of currencies" do
135135
expect(described_class.all).to include described_class.new(:usd)
136136
end
137+
137138
it "includes registered currencies" do
138139
register_foo
139140
expect(described_class.all).to include described_class.new(:foo)
140141
unregister_foo
141142
end
143+
142144
it 'is sorted by priority' do
143145
expect(described_class.all.first.priority).to eq 1
144146
end
147+
145148
it "raises a MissingAttributeError if any currency has no priority" do
146149
register_foo(skip: :priority)
147150

@@ -286,7 +289,7 @@ def to_s
286289
end
287290

288291
it 'returns new object for the different :key' do
289-
expect(described_class.new("USD")).to_not be(described_class.new("EUR"))
292+
expect(described_class.new("USD")).not_to be(described_class.new("EUR"))
290293
end
291294

292295
it 'is thread safe' do

spec/locale_backend/currency_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
end
1414

1515
it 'returns format based as defined in currency' do
16-
expect(subject.lookup(:format, currency)).to eq(nil)
16+
expect(subject.lookup(:format, currency)).to be_nil
1717
end
1818
end
1919
end

spec/locale_backend/i18n_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
end
1111

1212
describe '#lookup' do
13+
subject { described_class.new }
14+
1315
after do
1416
I18n.locale = :en
1517
end
1618

17-
subject { described_class.new }
18-
1919
context 'with number.currency.format defined' do
2020
before do
2121
I18n.locale = :de
@@ -58,19 +58,19 @@
5858

5959
context 'with no translation defined' do
6060
it 'returns thousands_separator based on the current locale' do
61-
expect(subject.lookup(:thousands_separator, nil)).to eq(nil)
61+
expect(subject.lookup(:thousands_separator, nil)).to be_nil
6262
end
6363

6464
it 'returns decimal_mark based on the current locale' do
65-
expect(subject.lookup(:decimal_mark, nil)).to eq(nil)
65+
expect(subject.lookup(:decimal_mark, nil)).to be_nil
6666
end
6767

6868
it 'returns symbol based on the current locale' do
69-
expect(subject.lookup(:symbol, nil)).to eq(nil)
69+
expect(subject.lookup(:symbol, nil)).to be_nil
7070
end
7171

7272
it 'returns format based on the current locale' do
73-
expect(subject.lookup(:format, nil)).to eq(nil)
73+
expect(subject.lookup(:format, nil)).to be_nil
7474
end
7575
end
7676
end

0 commit comments

Comments
 (0)