2

Byebug with ActiveRecord in Rails 6 is not logging as expected in my test environment.

When I run a test and use byebug to pause execution ActiveRecord is not logging queries to the console. For example, if I type Candidate.second I see no SQL output:

no output showing when I run Candidate.second

What I would like to see, and what I do see if I run the same query in my development environment within the rails console:

enter image description here

I've looked through documentation on both ActiveRecord and ByeBug but can't seem to solve this. Any help is appreciated!

Steps to reproduce

Throw a debugger statement into a controller, and run a test:

ActiveRecord is not logging queries into the console when using byebug. For example, if a run a test that hits a controller action:

class JobsController < ApplicationController
  # ...

  def show
    debugger
    Candidate.first # arbitrary query
    render json: @job
  end
end

From the terminal:

rails test test/controllers/jobs_controller.rb

Matt
  • 5,800
  • 1
  • 44
  • 40

1 Answers1

4

ActiveRecord::Base.logger = Logger.new(STDOUT)

Not sure why it doesn't come by default or how to make it permanent. You have to enable rails logger in the byebug console as well.

Harsh Kumar
  • 334
  • 2
  • 12