2013-01-06 2 views
0

나는 내가 이것을 실행할 때 application_helper_spec.rbRSpec에하자() 동작은

shared_examples_for "some shared process" do 

    it "displays the value defined by Let" do 
     puts object.inspect # This should output the value defined by Let 
    end 

end 

describe ApplicationHelper do 

    describe "a_helper_methond" do 

     describe "some behaviour" do 
      let(:object) { "foo" } 
      puts object.inspect # This should output the value defined by Let 
      it_should_behave_like "some shared process" 
     end 

    end 

end 

는 그러나, 나는 두 박았에 두 가지 오류를 얻을 내에서 다음과 같은 한 :

undefined local variable or method `object' for #<Class:0x007f951a3a7b20> (NameError) 

이유는 무엇입니까? 내 모델에 똑같은 코드가 있고 요청 사양이 잘 실행되지만 도우미 사양에서는 그렇지 않습니다.

답변

4

let 호출은 스펙이 실행되는 컨텍스트에서 메소드를 정의합니다. 그러나 puts 문은 해당 범위를 벗어납니다. it 블록 안에 포장해야합니다.

it 'print debug output' do 
    puts object.inspect 
end 
0

은 또한 더 it_behaves_like 블록 내부의하자 명령을 넣어이 개선