Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ Lint/EmptyClass:
# Allow defining empty classes, since it can be used as a base class.
Enabled: false

# RSpec

RSpec/DescribedClass:
Exclude:
# Prefer Money.new(…) to described_class.new(…)
- 'spec/money_spec.rb'
- 'spec/money/formatting_spec.rb'

# Style

Style/ClassAndModuleChildren:
Expand Down
98 changes: 0 additions & 98 deletions .rubocop_todo.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions spec/bank/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def setup
end

bank = MyBank.new
expect(bank.setup_called).to eq true
expect(bank.setup_called).to be true
end
end

Expand All @@ -40,19 +40,19 @@ def setup

describe "#same_currency?" do
it "accepts str/str" do
expect { subject.send(:same_currency?, 'USD', 'EUR') }.to_not raise_error
expect { subject.send(:same_currency?, 'USD', 'EUR') }.not_to raise_error
end

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

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

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

it "returns true when currencies match" do
Expand Down
18 changes: 9 additions & 9 deletions spec/bank/variable_exchange_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@

describe "#exchange_with" do
it "accepts str" do
expect { bank.exchange_with(Money.new(100, 'USD'), 'EUR') }.to_not raise_error
expect { bank.exchange_with(Money.new(100, 'USD'), 'EUR') }.not_to raise_error
end

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

it "exchanges one currency to another" do
Expand Down Expand Up @@ -110,7 +110,7 @@
describe "#add_rate" do
it 'delegates to store#add_rate' do
expect(subject.store).to receive(:add_rate).with('USD', 'EUR', 1.25).and_return 1.25
expect(subject.add_rate('USD', 'EUR', 1.25)).to eql 1.25
expect(subject.add_rate('USD', 'EUR', 1.25)).to be 1.25
end

it "adds rates with correct ISO codes" do
Expand All @@ -130,7 +130,7 @@
describe "#set_rate" do
it 'delegates to store#add_rate' do
expect(subject.store).to receive(:add_rate).with('USD', 'EUR', 1.25).and_return 1.25
expect(subject.set_rate('USD', 'EUR', 1.25)).to eql 1.25
expect(subject.set_rate('USD', 'EUR', 1.25)).to be 1.25
end

it "sets a rate" do
Expand Down Expand Up @@ -160,28 +160,28 @@
end

describe "#export_rates" do
before :each do
before do
subject.set_rate('USD', 'EUR', 1.25)
subject.set_rate('USD', 'JPY', 2.55)

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

context "with format == :json" do
it "should return rates formatted as json" do
it "returns rates formatted as json" do
json = subject.export_rates(:json)
expect(JSON.load(json)).to eq @rates
end
end

context "with format == :ruby" do
it "should return rates formatted as ruby objects" do
it "returns rates formatted as ruby objects" do
expect(Marshal.load(subject.export_rates(:ruby))).to eq @rates
end
end

context "with format == :yaml" do
it "should return rates formatted as yaml" do
it "returns rates formatted as yaml" do
yaml = subject.export_rates(:yaml)
expect(YAML.load(yaml)).to eq @rates
end
Expand Down Expand Up @@ -266,7 +266,7 @@

describe "#marshal_dump" do
it "does not raise an error" do
expect { Marshal.dump(subject) }.to_not raise_error
expect { Marshal.dump(subject) }.not_to raise_error
end

it "works with Marshal.load" do
Expand Down
2 changes: 1 addition & 1 deletion spec/currency/heuristics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe Money::Currency::Heuristics do
describe "#analyze_string" do
it "it raises deprecation error" do
it "raises deprecation error" do
expect { Money::Currency.analyze('123') }.to raise_error(StandardError, 'Heuristics deprecated, add `gem "money-heuristics"` to Gemfile')
end
end
Expand Down
5 changes: 4 additions & 1 deletion spec/currency_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,17 @@ def to_s
it "returns an array of currencies" do
expect(described_class.all).to include described_class.new(:usd)
end

it "includes registered currencies" do
register_foo
expect(described_class.all).to include described_class.new(:foo)
unregister_foo
end

it 'is sorted by priority' do
expect(described_class.all.first.priority).to eq 1
end

it "raises a MissingAttributeError if any currency has no priority" do
register_foo(skip: :priority)

Expand Down Expand Up @@ -292,7 +295,7 @@ def to_s
end

it 'returns new object for the different :key' do
expect(described_class.new("USD")).to_not be(described_class.new("EUR"))
expect(described_class.new("USD")).not_to be(described_class.new("EUR"))
end

it 'is thread safe' do
Expand Down
2 changes: 1 addition & 1 deletion spec/locale_backend/currency_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
end

it 'returns format based as defined in currency' do
expect(subject.lookup(:format, currency)).to eq(nil)
expect(subject.lookup(:format, currency)).to be_nil
end
end
end
12 changes: 6 additions & 6 deletions spec/locale_backend/i18n_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
end

describe '#lookup' do
subject { described_class.new }

after do
I18n.locale = :en
end

subject { described_class.new }

context 'with number.currency.format defined' do
before do
I18n.locale = :de
Expand Down Expand Up @@ -58,19 +58,19 @@

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

it 'returns decimal_mark based on the current locale' do
expect(subject.lookup(:decimal_mark, nil)).to eq(nil)
expect(subject.lookup(:decimal_mark, nil)).to be_nil
end

it 'returns symbol based on the current locale' do
expect(subject.lookup(:symbol, nil)).to eq(nil)
expect(subject.lookup(:symbol, nil)).to be_nil
end

it 'returns format based on the current locale' do
expect(subject.lookup(:format, nil)).to eq(nil)
expect(subject.lookup(:format, nil)).to be_nil
end
end
end
Expand Down
Loading