2015-10-06 7 views
5

मैं rspec-given का उपयोग कर रहा हूं और यह त्रुटि प्राप्त कर रहा हूं।rspec- दिया गया त्रुटि 'फिर' एक उदाहरण के भीतर से उपलब्ध नहीं है (उदा। एक 'यह' ब्लॉक)

विफलता/त्रुटि: फिर { Then नहीं उपलब्ध एक उदाहरण (जैसे एक it ब्लॉक) के भीतर से या निर्माणों कि एक उदाहरण (जैसे before, let, आदि) के दायरे में चलाने से है। यह केवल एक उदाहरण समूह पर उपलब्ध है (उदा। describe या context ब्लॉक)।

describe SchoolService do 
    Given(:school) { create(:school_with_applications) } 
    Given(:service) { School.new(@school) } 

    describe 'create_default_programs_and_year_grades!' do 
    it 'checks program size' do 
     When { service.create_default_programs_and_year_grades! } 
     Then { expect(school.programs.size).to eq 3 } 
    end 
    end 
end 

उत्तर

3

त्रुटि संदेश यह कहते हैं सभी:

Then is not available from within an example (e.g. an it block) or from constructs that run in the scope of an example (e.g. before, let, etc). It is only available on an example group (e.g. a describe or context block). 

कृपया त्रुटि संदेश को ध्यान से पढ़ें। और आपके पास त्रुटि संदेश में समाधान है।

आप एक it ब्लॉक के अंदर Then उपयोग नहीं कर सकते, आप केवल उपयोग कर सकते हैं या तो Thendescribe या context ब्लॉक के साथ।

तो, अपनी समस्या को हल करने के लिए, बस context बजाय it का उपयोग करें:

describe SchoolService do 
    Given(:school) { create(:school_with_applications) } 
    Given(:service) { School.new(@school) } 

    describe 'create_default_programs_and_year_grades!' do 
    context 'checks program size' do 
     When { service.create_default_programs_and_year_grades! } 
     Then { expect(school.programs.size).to eq 3 } 
    end 
    end 
end 

अधिक examples here देखें।

+1

धन्यवाद यह एक आकर्षण की तरह काम करता है! – wildrails

+0

खुशी मैं मदद कर सकता था! –

संबंधित मुद्दे

 संबंधित मुद्दे