Skip to content

Instantly share code, notes, and snippets.

@garrow
Created January 17, 2014 00:24
Show Gist options
  • Save garrow/8466181 to your computer and use it in GitHub Desktop.
Save garrow/8466181 to your computer and use it in GitHub Desktop.
Quick and dirty rspec BigDecimal matcher
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