Big Decimal's to_s prints as scientific notation.
rspec uses the to_s for error messages.
How could rspec be monkey-patched so that it prints errors for BigDecimal using a more conventional formatting?
This relates to this question: Override BigDecimal to_s default in Ruby
But I don't want to globally override BigDecimal.to_s.
This works. Create file in rspec/support/big_decimal_inspect.rb
# Monkey patch BigDecimal#inspect
# Otherwises test errors print like:
# expected: #<BigDecimal:108482700,'0.11E3',9(27)>
# got: #<BigDecimal:108468080,'0.12E3',9(27)>
# After get:
# expected: 110.0
# got: 120.0
class BigDecimal
def inspect
to_s
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With