如何使用pry調試器檢查rspec變量

[英]How to examine rspec variables with pry debugger


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:

我已經看到了一些解釋如何使用pry進入rspec測試的文章,並且能夠這樣做。一旦我達到了斷點,我就很難顯示任何有用的信息。對於下面的代碼,我想從pry控制台檢查響應對象:

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?

有什么辦法嗎?

3 个解决方案

#1


21  

You should place binding.pry inside it block.

您應該將綁定。里面撬塊。

#2


10  

To use pry in specs we need to add require 'pry' within the spec_helper.rb file. Then we are able to use binding.pry within any of the specs.

要在spec中使用pry,我們需要在spec_helper中添加需要的“pry”。rb文件。然后我們就可以使用綁定了。檢查任何規格。

#3


3  

This should work:

這應該工作:

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
    it "should list all flat_happenings" do
      binding.pry
      JSON.parse(response.body)["flat_happenings"].length.should eq 30
    end
  end
end

HTH

HTH


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2013/07/24/730065cfa64719ced7d0e44229b80243.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com