Skip to content

Commit 8772dcd

Browse files
committed
Lint: Fix blocks
Fixes the following cops: - Layout/MultilineBlockLayout - Lint/ConstantDefinitionInBlock - Lint/EmptyBlock - Lint/UnusedBlockArgument - Style/BlockDelimiters - Style/ExplicitBlockArgument See also #1134
1 parent ae2f3c5 commit 8772dcd

File tree

12 files changed

+141
-129
lines changed

12 files changed

+141
-129
lines changed

.rubocop_todo.yml

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

lib/money/currency.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ def unregister(curr)
208208
existed ? true : false
209209
end
210210

211-
def each
212-
all.each { |c| yield(c) }
211+
def each(&)
212+
all.each(&)
213213
end
214214

215215
def reset!

lib/money/rates_store/memory.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ def marshal_dump
7272

7373
# Wraps block execution in a thread-safe transaction
7474
def transaction(&)
75-
guard.synchronize do
76-
yield
77-
end
75+
guard.synchronize(&)
7876
end
7977

8078
# Iterate over rate tuples (iso_from, iso_to, rate)

spec/bank/base_spec.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@
1717
end
1818

1919
describe "#setup" do
20-
it "calls #setup after #initialize" do
21-
class MyBank < described_class
20+
let(:bank_class) do
21+
Class.new(described_class) do
2222
attr_reader :setup_called
2323

2424
def setup
2525
@setup_called = true
2626
end
2727
end
28+
end
2829

29-
bank = MyBank.new
30+
it "calls #setup after #initialize" do
31+
bank = bank_class.new
3032
expect(bank.setup_called).to be true
3133
end
3234
end

spec/bank/single_currency_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
RSpec.describe Money::Bank::SingleCurrency do
44
describe "#exchange_with" do
55
it "raises when called" do
6-
expect {
6+
expect do
77
subject.exchange_with(Money.new(100, 'USD'), 'EUR')
8-
}.to raise_error(Money::Bank::DifferentCurrencyError, "No exchanging of currencies allowed: 1.00 USD to EUR")
8+
end.to raise_error(Money::Bank::DifferentCurrencyError, "No exchanging of currencies allowed: 1.00 USD to EUR")
99
end
1010
end
1111
end

spec/bank/variable_exchange_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
RSpec.describe Money::Bank::VariableExchange do
77
describe "#initialize" do
88
context "without &block" do
9-
let(:bank) {
9+
let(:bank) do
1010
described_class.new.tap do |bank|
1111
bank.add_rate('USD', 'EUR', 1.33)
1212
end
13-
}
13+
end
1414

1515
describe '#store' do
1616
it 'defaults to Memory store' do
@@ -86,12 +86,12 @@
8686
end
8787

8888
context "with &block" do
89-
let(:bank) {
89+
let(:bank) do
9090
proc = Proc.new { |n| n.ceil }
9191
described_class.new(&proc).tap do |bank|
9292
bank.add_rate('USD', 'EUR', 1.33)
9393
end
94-
}
94+
end
9595

9696
describe "#exchange_with" do
9797
it "uses the stored truncation method" do

spec/currency_spec.rb

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
# frozen_string_literal: true
22

3+
FOO = {
4+
priority: 1,
5+
iso_code: "FOO",
6+
iso_numeric: "840",
7+
name: "United States Dollar",
8+
symbol: "$",
9+
subunit: "Cent",
10+
subunit_to_unit: 1000,
11+
symbol_first: true,
12+
html_entity: "$",
13+
decimal_mark: ".",
14+
thousands_separator: ",",
15+
smallest_denomination: 1,
16+
}.freeze
17+
318
RSpec.describe Money::Currency do
4-
FOO = '{ "priority": 1, "iso_code": "FOO", "iso_numeric": "840", "name": "United States Dollar", "symbol": "$", "subunit": "Cent", "subunit_to_unit": 1000, "symbol_first": true, "html_entity": "$", "decimal_mark": ".", "thousands_separator": ",", "smallest_denomination": 1 }'
5-
6-
def register_foo(opts = {})
7-
foo_attrs = JSON.parse(FOO, symbolize_names: true)
8-
# Pass an array of attribute names to 'skip' to remove them from the 'FOO'
9-
# json before registering foo as a currency.
10-
Array(opts[:skip]).each { |attr| foo_attrs.delete(attr) }
11-
described_class.register(foo_attrs)
19+
# Pass an array of attribute names to skip to remove them from the registered
20+
# currency.
21+
def register_foo(skip: [])
22+
described_class.register(FOO.except(*skip))
1223
end
1324

1425
def unregister_foo
15-
described_class.unregister(JSON.parse(FOO, symbolize_names: true))
26+
described_class.unregister(FOO)
1627
end
1728

1829
describe "UnknownCurrency" do
@@ -45,19 +56,22 @@ def unregister_foo
4556
end
4657

4758
describe ".find_by_iso_numeric" do
59+
let(:mock_class) do
60+
Class.new do
61+
def to_s
62+
"208"
63+
end
64+
end
65+
end
66+
4867
it "returns currency matching given numeric code" do
4968
expect(described_class.find_by_iso_numeric(978)).to eq described_class.new(:eur)
5069
expect(described_class.find_by_iso_numeric(208)).not_to eq described_class.new(:eur)
5170
expect(described_class.find_by_iso_numeric('840')).to eq described_class.new(:usd)
5271
expect(described_class.find_by_iso_numeric(51)).to eq described_class.new(:amd)
5372

54-
class Mock
55-
def to_s
56-
'208'
57-
end
58-
end
59-
expect(described_class.find_by_iso_numeric(Mock.new)).to eq described_class.new(:dkk)
60-
expect(described_class.find_by_iso_numeric(Mock.new)).not_to eq described_class.new(:usd)
73+
expect(described_class.find_by_iso_numeric(mock_class.new)).to eq described_class.new(:dkk)
74+
expect(described_class.find_by_iso_numeric(mock_class.new)).not_to eq described_class.new(:usd)
6175
end
6276

6377
it "returns nil if no currency has the given numeric code" do
@@ -171,9 +185,9 @@ def to_s
171185
end
172186

173187
specify ":iso_code must be present" do
174-
expect {
188+
expect do
175189
described_class.register(name: "New Currency")
176-
}.to raise_error(KeyError)
190+
end.to raise_error(KeyError)
177191
end
178192
end
179193

spec/money/arithmetic_spec.rb

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -755,21 +755,21 @@
755755
end
756756

757757
it "raises TypeError dividing by a Money (unless other is a Money)" do
758-
expect {
758+
expect do
759759
2 / Money.new(2, 'USD')
760-
}.to raise_error(TypeError)
760+
end.to raise_error(TypeError)
761761
end
762762

763763
it "raises TypeError subtracting by a Money (unless other is a Money)" do
764-
expect {
764+
expect do
765765
2 - Money.new(2, 'USD')
766-
}.to raise_error(TypeError)
766+
end.to raise_error(TypeError)
767767
end
768768

769769
it "raises TypeError adding by a Money (unless other is a Money)" do
770-
expect {
770+
expect do
771771
2 + Money.new(2, 'USD')
772-
}.to raise_error(TypeError)
772+
end.to raise_error(TypeError)
773773
end
774774

775775
it "allows subtraction from numeric zero" do
@@ -783,35 +783,35 @@
783783
end
784784

785785
it "treats multiplication as commutative" do
786-
expect {
786+
expect do
787787
2 * Money.new(2, 'USD')
788-
}.not_to raise_error
788+
end.not_to raise_error
789789
result = 2 * Money.new(2, 'USD')
790790
expect(result).to eq(Money.new(4, 'USD'))
791791
end
792792

793793
it "doesn't work with non-numerics" do
794-
expect {
794+
expect do
795795
"2" * Money.new(2, 'USD')
796-
}.to raise_error(TypeError)
796+
end.to raise_error(TypeError)
797797
end
798798

799799
it "correctly handles <=>" do
800-
expect {
800+
expect do
801801
2 < Money.new(2, 'USD')
802-
}.to raise_error(ArgumentError)
802+
end.to raise_error(ArgumentError)
803803

804-
expect {
804+
expect do
805805
2 > Money.new(2, 'USD')
806-
}.to raise_error(ArgumentError)
806+
end.to raise_error(ArgumentError)
807807

808-
expect {
808+
expect do
809809
2 <= Money.new(2, 'USD')
810-
}.to raise_error(ArgumentError)
810+
end.to raise_error(ArgumentError)
811811

812-
expect {
812+
expect do
813813
2 >= Money.new(2, 'USD')
814-
}.to raise_error(ArgumentError)
814+
end.to raise_error(ArgumentError)
815815

816816
expect(2 <=> Money.new(2, 'USD')).to be_nil
817817
end
@@ -823,17 +823,17 @@
823823
end
824824

825825
it "raises errors for all numeric types, not just Integer" do
826-
expect {
826+
expect do
827827
2.0 / Money.new(2, 'USD')
828-
}.to raise_error(TypeError)
828+
end.to raise_error(TypeError)
829829

830-
expect {
830+
expect do
831831
Rational(2, 3) / Money.new(2, 'USD')
832-
}.to raise_error(TypeError)
832+
end.to raise_error(TypeError)
833833

834-
expect {
834+
expect do
835835
BigDecimal(2) / Money.new(2, 'USD')
836-
}.to raise_error(TypeError)
836+
end.to raise_error(TypeError)
837837
end
838838
end
839839

spec/money/formatting_rules_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
RSpec.describe Money::FormattingRules do
44
it 'does not modify frozen rules in place' do
5-
expect {
5+
expect do
66
described_class.new(Money::Currency.new('USD'), { separator: '.' }.freeze)
7-
}.not_to raise_error
7+
end.not_to raise_error
88
end
99

1010
it 'does not modify rules in place' do

0 commit comments

Comments
 (0)