2013-07-24 4 views
15

rspecテストを実行してこれを実行する方法を説明するいくつかのSOの投稿を見ました。しかし、ブレークポイントに達すると、私は有用な情報を表示するのに苦労しています。以下のコードでは、コンソールからレスポンスオブジェクトを確認したいと考えています。pryデバッガでrspec変数を調べる方法

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 

どのようにすればいいですか?

答えて

18

binding.pryitブロック内に配置する必要があります。

+0

ありがとうございました。だからシンプル - なぜ私はそのことを考えなかった... – klavado

3

これは動作するはずです:

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

+1

ありがとう。あなたの答えはあまりにもうまくいくが、セルゲイが最初に答えたように、私は彼の答えを受け入れなければならなかった。 – klavado

8

たちはspec_helper.rbファイル内require 'pry'を追加する必要がスペックにプライを使用するには。それから、binding.pryを仕様の中で使用することができます。

関連する問題