1

I use minitest and rake task to run tests. I use standard reporter (this is from test helper):

Minitest::Reporters.use!(
  Minitest::Reporters::DefaultReporter.new(fast_fail: true, slow_count: 3),
  # show single tests with the spec reporter
  # MiniTest::Reporters::SpecReporter.new,
  ENV, Minitest.backtrace_filter
)

This is my test.rake:

require 'rake/testtask'

Rake::Task['test:run'].clear
Rake::Task['test:decorators'].clear

namespace :test do
  task run: ['test:decorators', 'test:models', 'test:controllers', 'test:mailers', 'test:integration']

  Rake::TestTask.new(decorators: 'test:prepare') do |t|
    t.pattern = 'test/decorators/**/*_test.rb'
  end
end

I also have pry installed in Gemfile:

group :pry, :test do
  gem 'pry-rails'
  gem 'pry-byebug'
end

The problem I can't use it in tests. I can add a breakpoint with binding_pry, but I don't see the output from invoked functions. I can't also log anything using puts (from both pry and directly from tests). I don't see this output nor in terminal nor in log files. The only thing I can use at the moment is a Rails logger. But it's not satysfying. How can I display output from pry and puts in terminal?

ciemborowicz
  • 93
  • 1
  • 10

1 Answers1

0

Because you are in the test environment, a different logging settings applies, other than in the default rails console one. So instead of seeing the logs in your STDOUT it is going to some file (or however you test env is setup).

To workaround this, when using pry, you can set specific pry settings on a local ~/.pryrc file for customisation and configuration. This has the advantage on not "polluting" your real test env and it is only local to your workstation.

Put this in your ~/.pryrc file:

Pry.config.hooks.add_hook(:before_session, :rails) do
  if defined?(Rails)
    ActiveRecord::Base.logger = Logger.new(STDOUT)
  end
end

As taken from Active::Record Logger to STDOUT with pry.

brutuscat
  • 3,139
  • 2
  • 28
  • 33