Skip to content

Instantly share code, notes, and snippets.

@oyeb
Created June 6, 2018 09:50
Show Gist options
  • Save oyeb/7662df5bc3b12a66f482b0ee275c91ef to your computer and use it in GitHub Desktop.
Save oyeb/7662df5bc3b12a66f482b0ee275c91ef to your computer and use it in GitHub Desktop.
Tests for ex_money's protocol implementation
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