How do I output a variable in a rspec test?

后端 未结 4 1182
说谎
说谎 2021-01-31 08:36

Is there a quick way to output the value of variable in a rspec test? Something like this for example, in a controller to output a variable, I do:

raise variable         


        
4条回答
  •  被撕碎了的回忆
    2021-01-31 08:59

    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
    

提交回复
热议问题