2013-06-01 3 views
1

it 블록에서 왜이 RSpec은 spec을 기술하여 다른 방법으로 결과를 보여줄까요?

context "stripe customer" do 
    subject { @customer = Stripe::Customer.retrieve @subscription.stripe_customer_token } 

    it "show me email" do 
    p @customer.email 
    p user.email 
    @customer.email.should == user.email 
    end 

    #its(:email) { should == user.email } 
    its(:description) { should == user.email } 
end 

주어이 통과한다. 주석 처리 된 #its 부분은 전달되지 않습니다. 나는 두 개의 다른 물건을 얻는다. expected: "[email protected]" got: "[email protected]" (using ==)

이것은 database_cleaner 보석 때문입니까? 어떤 방식 으로든 나는 factory/database_cleaner를 제대로 설정하지 못하고 있습니까?

블록에서 일치하지 않는 이유는 무엇입니까? 어떻게 다를 수 있습니까?

답변

2

당신은 subject을 이상한 방법으로 사용하고 있습니다 : 인스턴스 변수를 설정하기 위해 그것을 사용하고 있습니다. 오히려 그것을 기대하는 것으로 사용하는 것입니다.

subject에 주어진 블록은 느리게 평가됩니다. 스펙에서 주제를 사용할 때만 평가됩니다. its 예제의 경우 rspec은 subject을 호출하지만 다른 예는 subject으로 전화하지 않으므로 @customer은 아마도 둘러싸는 컨텍스트의 숙취 일 것입니다.