Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to examine rspec variables with pry debugger

Tags:

I've seen some SO posts explaining how to use pry to step into rspec tests and been able to do this. Once I reach the breakpoint though, I'm struggling to display any useful information. For this code below, I'd like to examine the response object from the pry console:

describe 'happenings' do   context "#index (GET /api/v1/flat_happenings.json)" do     before(:each) do       30.times { FactoryGirl.create(:flat_happening) }       get "/api/v1/flat_happenings.json"     end     describe "should list all flat_happenings" do       binding.pry       it { JSON.parse(response.body)["flat_happenings"].length.should eq 30 }     end   end end 

Any ideas on how to do this?

like image 236
PropertyWebBuilder Avatar asked Jul 24 '13 15:07

PropertyWebBuilder


People also ask

How do I debug with binding pry?

To invoke the debugger, place binding. pry somewhere in your code. When the Ruby interpreter hits that code, execution stops, and you can type in commands to debug the state of the program.

How does binding pry work?

So when you place the line binding. pry in your code, that line will get interpreted at runtime (as your program is executed). When the interpreter hits that line, your program will actually freeze and your terminal will turn into a REPL that exists right in the middle of your program, wherever you added the binding.


1 Answers

You should place binding.pry inside it block.

like image 92
Sergey Alekseev Avatar answered Nov 12 '22 15:11

Sergey Alekseev