Created
June 6, 2018 09:50
-
-
Save oyeb/7662df5bc3b12a66f482b0ee275c91ef to your computer and use it in GitHub Desktop.
Tests for ex_money's protocol implementation
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
alias Gringotts.Money, as: MoneyProtocol | |
describe "Gringotts.Money protocol implementation" do | |
# You may not need this one :) | |
test "currency is an upcase String.t" do | |
the_currency = MoneyProtocol.currency(Money.new(0, :USD)) | |
assert match?(currency when is_binary(currency), the_currency) | |
assert the_currency == String.upcase(the_currency) | |
end | |
test "to_integer" do | |
assert match?({"EUR", 4200, -2}, MoneyProtocol.to_integer(Money.new(42, :EUR))) | |
assert match?({"BHD", 42_000, -3}, MoneyProtocol.to_integer(Money.new(42, :BHD))) | |
assert match?({"BHD", 42_007, -3}, MoneyProtocol.to_string(Money.new("42.0066", :BHD))) | |
end | |
test "to_string" do | |
assert match?({"EUR", "42"}, MoneyProtocol.to_string(Money.new("42.00", :EUR))) | |
assert match?({"EUR", "42"}, MoneyProtocol.to_string(Money.new(42, :EUR))) | |
assert match?({"EUR", "42.01"}, MoneyProtocol.to_string(Money.new("42.0064", :EUR))) | |
assert match?({"BHD", "42.006"}, MoneyProtocol.to_string(Money.new("42.006", :BHD)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment