Created
January 17, 2014 00:24
-
-
Save garrow/8466181 to your computer and use it in GitHub Desktop.
Quick and dirty rspec BigDecimal matcher
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
RSpec::Matchers.define :be_decimal do |expected| | |
match do |actual| | |
coerce(actual) == coerce(expected) | |
end | |
failure_message_for_should do |actual| | |
"expected that #{format(actual)} would equal #{format(expected)}" | |
end | |
def coerce(value) | |
BigDecimal(value, 2) | |
end | |
def format(value) | |
coerce(value).to_s('F') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment