0

I'm using awesome_print, because I want to see Bigdecimal numbers like 0.5, instead of <BigDecimal:7fbfdafa54c8,'0.5E0',9(18)>.

And I also want to use same function for Minitest result.

Is there a gem for it?

I tried minitest-reporters, but apparently this gem don't change Bigdecimal appearance.

ironsand
  • 14,329
  • 17
  • 83
  • 176

1 Answers1

1

Override inspect on BigDecimal:

class BigDecimal
  def inspect
    self.ai
  end
end

This is using Kernel#ai from awesome print (which by the way accepts accepts a handy html: true argument)

The reason I know inspect is being called by Minitest is that what you're seeing (<BigDecimal:7fbfdafa54c8,'0.5E0',9(18)>) is the same as what you'd see if you ran BigDecimal.new(num).inspect

max pleaner
  • 26,189
  • 9
  • 66
  • 118
  • Where can I override the method without affecting main project code? By adding `test_helper.rb`, I just got a `ArgumentError`. – ironsand Oct 21 '16 at 20:26
  • you're right, my code was not correct. See the updated answer. Override `inspect`, not `to_s` – max pleaner Oct 21 '16 at 20:31