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?
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.
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.
You should place binding.pry
inside it
block.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With