How to make AmazingPrint the default formatter for debugging sessions in RSpec

41 Views Asked by At

I've successfully integrated the Amazing Print gem into my Rails application to enhance the output format of objects, hashes, and arrays within the Rails console. This was achieved by adding the following configuration to my application.rb file:

module MyApi
  class Application < Rails::Application
    console do
      require 'amazing_print'
      AmazingPrint.irb!
    end
  end
end

This works great in my rails c, providing nicely formatted output by default. However, it doesn't work for debugging sessions on my RSpec tests. When I insert a debugger into my tests (e.g., using byebug or pry) and then I inspect an object using ap object, it prints out as expected with Amazing Print formatting. But, if I simply evaluate an object by typing its name (e.g., object), it doesn't use Amazing Print's formatting by default.

I'm looking for a way to configure my RSpec environment so that all objects are automatically formatted using Amazing Print, without explicitly needing to use the ap method each time.

How can I do that?

0

There are 0 best solutions below