-
Notifications
You must be signed in to change notification settings - Fork 626
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not namespace specs with classes and modules (#873)
- Loading branch information
Showing
5 changed files
with
580 additions
and
596 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,74 @@ | ||
class Money | ||
module Bank | ||
describe Base do | ||
describe Money::Bank::Base do | ||
|
||
describe ".instance" do | ||
it "is local to one class" do | ||
klass = Base | ||
subclass = Class.new(Base) | ||
expect(klass.instance).not_to eq subclass.instance | ||
end | ||
end | ||
|
||
describe "#initialize" do | ||
it "accepts a block and stores @rounding_method" do | ||
proc = Proc.new { |n| n.ceil } | ||
bank = Base.new(&proc) | ||
expect(bank.rounding_method).to eq proc | ||
end | ||
end | ||
describe ".instance" do | ||
it "is local to one class" do | ||
subclass = Class.new(described_class) | ||
expect(described_class.instance).not_to eq subclass.instance | ||
end | ||
end | ||
|
||
describe "#setup" do | ||
it "calls #setup after #initialize" do | ||
class MyBank < Base | ||
attr_reader :setup_called | ||
describe "#initialize" do | ||
it "accepts a block and stores @rounding_method" do | ||
proc = Proc.new { |n| n.ceil } | ||
bank = described_class.new(&proc) | ||
expect(bank.rounding_method).to eq proc | ||
end | ||
end | ||
|
||
def setup | ||
@setup_called = true | ||
end | ||
end | ||
describe "#setup" do | ||
it "calls #setup after #initialize" do | ||
class MyBank < described_class | ||
attr_reader :setup_called | ||
|
||
bank = MyBank.new | ||
expect(bank.setup_called).to eq true | ||
def setup | ||
@setup_called = true | ||
end | ||
end | ||
|
||
describe "#exchange_with" do | ||
it "is not implemented" do | ||
expect { subject.exchange_with(Money.new(100, 'USD'), 'EUR') }.to raise_exception(NotImplementedError) | ||
end | ||
end | ||
bank = MyBank.new | ||
expect(bank.setup_called).to eq true | ||
end | ||
end | ||
|
||
describe "#same_currency?" do | ||
it "accepts str/str" do | ||
expect { subject.send(:same_currency?, 'USD', 'EUR') }.to_not raise_exception | ||
end | ||
describe "#exchange_with" do | ||
it "is not implemented" do | ||
expect { subject.exchange_with(Money.new(100, 'USD'), 'EUR') }.to raise_exception(NotImplementedError) | ||
end | ||
end | ||
|
||
it "accepts currency/str" do | ||
expect { subject.send(:same_currency?, Currency.wrap('USD'), 'EUR') }.to_not raise_exception | ||
end | ||
describe "#same_currency?" do | ||
it "accepts str/str" do | ||
expect { subject.send(:same_currency?, 'USD', 'EUR') }.to_not raise_exception | ||
end | ||
|
||
it "accepts str/currency" do | ||
expect { subject.send(:same_currency?, 'USD', Currency.wrap('EUR')) }.to_not raise_exception | ||
end | ||
it "accepts currency/str" do | ||
expect { subject.send(:same_currency?, Money::Currency.wrap('USD'), 'EUR') }.to_not raise_exception | ||
end | ||
|
||
it "accepts currency/currency" do | ||
expect { subject.send(:same_currency?, Currency.wrap('USD'), Currency.wrap('EUR')) }.to_not raise_exception | ||
end | ||
it "accepts str/currency" do | ||
expect { subject.send(:same_currency?, 'USD', Money::Currency.wrap('EUR')) }.to_not raise_exception | ||
end | ||
|
||
it "returns true when currencies match" do | ||
expect(subject.send(:same_currency?, 'USD', 'USD')).to be true | ||
expect(subject.send(:same_currency?, Currency.wrap('USD'), 'USD')).to be true | ||
expect(subject.send(:same_currency?, 'USD', Currency.wrap('USD'))).to be true | ||
expect(subject.send(:same_currency?, Currency.wrap('USD'), Currency.wrap('USD'))).to be true | ||
end | ||
it "accepts currency/currency" do | ||
expect { subject.send(:same_currency?, Money::Currency.wrap('USD'), Money::Currency.wrap('EUR')) }.to_not raise_exception | ||
end | ||
|
||
it "returns false when currencies do not match" do | ||
expect(subject.send(:same_currency?, 'USD', 'EUR')).to be false | ||
expect(subject.send(:same_currency?, Currency.wrap('USD'), 'EUR')).to be false | ||
expect(subject.send(:same_currency?, 'USD', Currency.wrap('EUR'))).to be false | ||
expect(subject.send(:same_currency?, Currency.wrap('USD'), Currency.wrap('EUR'))).to be false | ||
end | ||
it "returns true when currencies match" do | ||
expect(subject.send(:same_currency?, 'USD', 'USD')).to be true | ||
expect(subject.send(:same_currency?, Money::Currency.wrap('USD'), 'USD')).to be true | ||
expect(subject.send(:same_currency?, 'USD', Money::Currency.wrap('USD'))).to be true | ||
expect(subject.send(:same_currency?, Money::Currency.wrap('USD'), Money::Currency.wrap('USD'))).to be true | ||
end | ||
|
||
it "raises an UnknownCurrency exception when an unknown currency is passed" do | ||
expect { subject.send(:same_currency?, 'AAA', 'BBB') }.to raise_exception(Currency::UnknownCurrency) | ||
end | ||
end | ||
it "returns false when currencies do not match" do | ||
expect(subject.send(:same_currency?, 'USD', 'EUR')).to be false | ||
expect(subject.send(:same_currency?, Money::Currency.wrap('USD'), 'EUR')).to be false | ||
expect(subject.send(:same_currency?, 'USD', Money::Currency.wrap('EUR'))).to be false | ||
expect(subject.send(:same_currency?, Money::Currency.wrap('USD'), Money::Currency.wrap('EUR'))).to be false | ||
end | ||
|
||
it "raises an UnknownCurrency exception when an unknown currency is passed" do | ||
expect { subject.send(:same_currency?, 'AAA', 'BBB') }.to raise_exception(Money::Currency::UnknownCurrency) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
class Money | ||
module Bank | ||
describe SingleCurrency do | ||
describe "#exchange_with" do | ||
it "raises when called" do | ||
expect { | ||
subject.exchange_with(Money.new(100, 'USD'), 'EUR') | ||
}.to raise_exception(DifferentCurrencyError, "No exchanging of currencies allowed: 1.00 USD to EUR") | ||
end | ||
end | ||
describe Money::Bank::SingleCurrency do | ||
describe "#exchange_with" do | ||
it "raises when called" do | ||
expect { | ||
subject.exchange_with(Money.new(100, 'USD'), 'EUR') | ||
}.to raise_exception(Money::Bank::DifferentCurrencyError, "No exchanging of currencies allowed: 1.00 USD to EUR") | ||
end | ||
end | ||
end |
Oops, something went wrong.