如何使用pry调试器检查rspec变量

Pro*_*der 19 debugging rspec ruby-on-rails rspec-rails pry

我已经看到一些SO帖子解释了如何使用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
Run Code Online (Sandbox Code Playgroud)

关于如何做到这一点的任何想法?

Ser*_*eev 30

你应该放在binding.pry内部it.


Bam*_*m22 16

要在specs中使用require 'pry'pry,我们需要在spec_helper.rb文件中添加.然后我们就可以在任何规范中使用binding.pry.


a.s*_*r.o 6

这应该有效:

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
Run Code Online (Sandbox Code Playgroud)

华泰