How do I output a variable in a rspec test?

If you want the output to go into the log file (i.e. logs/test.log), you can use the rails logger.

Rails.logger.debug variable.inspect
Rails.logger.debug variable.to_yaml

If you want to see the output in the console, you can use the pretty printer ‘pp’.

require 'pp'

it 'does something'
  thing = Factory(:something)
  pp thing
end

Or you can use good ‘ol puts

puts thing.to_yaml

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)