Skip to content

Commit 530a52b

Browse files
authored
Merge branch 'main' into lint-fix-Style/FileWrite
2 parents d7f590b + fba50e2 commit 530a52b

File tree

5 files changed

+40
-48
lines changed

5 files changed

+40
-48
lines changed

.rubocop.yml

Lines changed: 28 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+
# Naming
43+
44+
Naming/PredicateMethod:
45+
AllowedMethods:
46+
# In Ruby, the convention is to return `nil` and not `false` when calling
47+
# `#nonzero?`.
48+
- nonzero?
49+
4250
# RSpec
4351

4452
RSpec/DescribedClass:
@@ -47,10 +55,19 @@ RSpec/DescribedClass:
4755
- 'spec/money_spec.rb'
4856
- 'spec/money/formatting_spec.rb'
4957

58+
RSpec/IdenticalEqualityAssertion:
59+
# Allow identical expressions on both sides of the equality since we are
60+
# testing defining equality.
61+
Enabled: false
62+
5063
RSpec/MultipleExpectations:
5164
# Do not limit the amount of expectations in a spec
5265
Enabled: false
5366

67+
RSpec/VerifiedDoubles:
68+
# Allow building unverified doubles with `double :foo`.
69+
IgnoreSymbolicNames: true
70+
5471
# Style
5572

5673
Style/ClassAndModuleChildren:
@@ -95,6 +112,17 @@ Style/QuotedSymbols:
95112
# Prefer :"some symbol" to :'some symbol'.
96113
EnforcedStyle: double_quotes
97114

115+
Style/ReturnNilInPredicateMethodDefinition:
116+
AllowedMethods:
117+
# In Ruby, the convention is to return `nil` and not `false` when calling
118+
# `#nonzero?`.
119+
- nonzero?
120+
121+
Style/SafeNavigation:
122+
# Allow calling `foo && foo.bar` instead of `foo&.bar` since `foo` can also
123+
# be false.
124+
Enabled: false
125+
98126
Style/StringLiterals:
99127
# Prefer "double quotes" over 'single quotes'.
100128
EnforcedStyle: double_quotes

.rubocop_todo.yml

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

lib/money/money/arithmetic.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,9 @@ def zero?
339339
# @example
340340
# Money.new(100).nonzero? #=> #<Money @fractional=100>
341341
# Money.new(0).nonzero? #=> nil
342-
# rubocop:disable Naming/PredicateMethod
343342
def nonzero?
344343
fractional != 0 ? self : nil
345344
end
346-
# rubocop:enable Naming/PredicateMethod
347345

348346
# Used to make Money instance handle the operations when arguments order is reversed
349347
# @return [Array]

spec/currency_spec.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,6 @@ def to_s
391391
describe "#inspect" do
392392
it "works as documented" do
393393
expect(described_class.new(:usd).inspect).to eq "#<Money::Currency id: usd, priority: 1, symbol_first: true, thousands_separator: ,, html_entity: $, decimal_mark: ., name: United States Dollar, symbol: $, subunit_to_unit: 100, exponent: 2, iso_code: USD, iso_numeric: 840, subunit: Cent, smallest_denomination: 1, format: >"
394-
end
395-
396-
it "works as documented" do
397394
expect(described_class.new(:aed).inspect).to eq "#<Money::Currency id: aed, priority: 100, symbol_first: false, thousands_separator: ,, html_entity: , decimal_mark: ., name: United Arab Emirates Dirham, symbol: د.إ, subunit_to_unit: 100, exponent: 2, iso_code: AED, iso_numeric: 784, subunit: Fils, smallest_denomination: 25, format: %n %u>"
398395
end
399396
end

spec/money_spec.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@
223223

224224
it "accepts an optional bank" do
225225
expect(Money.from_amount(1).bank).to eq Money.default_bank
226-
bank = double "bank"
227-
expect(Money.from_amount(1, "USD", bank).bank).to eq bank
226+
bank = Money::Bank::VariableExchange.new
227+
expect(Money.from_amount(1, "USD", bank).bank).to be bank
228228
end
229229

230230
context 'when given a nil currency' do
@@ -856,17 +856,11 @@
856856

857857
describe "#allocate" do
858858
it "takes no action when one gets all" do
859-
expect(Money.us_dollar(005).allocate([1.0])).to eq [Money.us_dollar(5)]
859+
expect(Money.us_dollar(5).allocate([1.0])).to eq [Money.us_dollar(5)]
860860
end
861861

862862
it "keeps currencies intact" do
863-
expect(Money.ca_dollar(005).allocate([1])).to eq [Money.ca_dollar(5)]
864-
end
865-
866-
it "does not lose pennies" do
867-
moneys = Money.us_dollar(5).allocate([0.3, 0.7])
868-
expect(moneys[0]).to eq Money.us_dollar(2)
869-
expect(moneys[1]).to eq Money.us_dollar(3)
863+
expect(Money.ca_dollar(5).allocate([1])).to eq [Money.ca_dollar(5)]
870864
end
871865

872866
it "handles small splits" do
@@ -881,8 +875,14 @@
881875
expect(moneys[1]).to eq Money.us_dollar(3)
882876
end
883877

884-
it "does not lose pennies" do
885-
moneys = Money.us_dollar(100).allocate([0.333, 0.333, 0.333])
878+
it "does not lose pennies for one decimal" do
879+
moneys = Money.us_dollar(5).allocate([0.3, 0.7])
880+
expect(moneys[0]).to eq Money.us_dollar(2)
881+
expect(moneys[1]).to eq Money.us_dollar(3)
882+
end
883+
884+
it "does not lose pennies for three decimals" do
885+
moneys = Money.us_dollar(1_00).allocate([0.333, 0.333, 0.333])
886886
expect(moneys[0].cents).to eq 34
887887
expect(moneys[1].cents).to eq 33
888888
expect(moneys[2].cents).to eq 33

0 commit comments

Comments
 (0)