Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print a variable to console in Haml to debug Rspec

Just landed on a Rails 3 app that uses haml. I am running Rspec tests and trying to print a value of a variable to console. On erb or in a any .rb file, you simply do:

p my_variable.inspect or even string interpolation:

p "this is my variable #{my_variable}" So when I run my Rspec tests I get a nice printout on the console evaluating my variables. So now, how you do that in Haml?

like image 854
Joseworks Avatar asked Oct 28 '14 11:10

Joseworks


2 Answers

it's so annoying to "p" variables as for me, and then search their output. Use better https://github.com/rweng/pry-rails and then in view just put

- binding.pry

and then in console you can debug variables and other stuff :)

like image 138
D.K. Avatar answered Oct 26 '22 20:10

D.K.


So in Haml just use:

- p my_variable
like image 32
Joseworks Avatar answered Oct 26 '22 21:10

Joseworks