2014-11-14 27 views
0

執行我有一個測試,看起來像這樣:之前:各不共享例如

describe "test" do 
    shared_example "a thing" do 
    before :each do 
     puts 'in before' 
    end 

    describe 'the thing' do 
     puts 'in test' 
    end 
    end 

    it_behaves_like "a thing" 
end 

當運行該代碼時,輸​​出爲in test。爲什麼?

回答

4

難道你忘了it {}

describe "test" do 
    shared_examples "a thing" do 
    before :each do 
     puts 'in before' 
    end 

    describe 'the thing' do 
     it 'should puts in test' do 
     puts 'in test' 
     end 
    end 
    end 

    it_behaves_like "a thing" 
end 

# output: 

    test 
    behaves like a thing 
     the thing 
in before 
in test 
相關問題