Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I better debug in RSpec?

I'm new to testing, and having troubles debugging like I might normally in a model or controller.

I've created a user from a factory (using FactoryGirl, if that makes a difference), and I'm pretty sure the create method is failing because of validation when saving. However, I'd love to know how to debug a model instantiated during testing.

I've tried:

user.inspect
puts user
raise user.to_yaml 

(The latter works, but stops execution of the rest of my tests, and doesn't show validation errors--it only proves the existence or non-existence of the model I tried to instantiate.)

Other than raising the model as an error, there is no debug output during testing, and the only other thing I've been able to do is tail the log for my test DB and see what's happening there, but it seems clunky at best. What methods would you suggest for accomplishing what I'm after?

Thank you for any direction

like image 638
jbnunn Avatar asked Sep 05 '12 18:09

jbnunn


1 Answers

Got the answer, it couldn't be easier (this user phrased my question much better and more concisely :)

How do I output a variable in a rspec test?

short answer, use pretty print:

pp user

like image 72
jbnunn Avatar answered Oct 13 '22 23:10

jbnunn