How to examine rspec variables with pry debugger

PropertyWebBuilder picture PropertyWebBuilder · Jul 24, 2013 · Viewed 16.3k times · Source

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?

Answer

Sergey Alekseev picture Sergey Alekseev · Jul 24, 2013

You should place binding.pry inside it block.