2012-11-25 29 views
2

現在我有很多的以下內容:如何使<klass> .any_instance主題

it{ ::Api.any_instance.should_receive(...).once; start } 

Rspec的電抗器,如果我試圖讓::Api.any_instance的主題,即

subject{ ::Api.any_instance } 
it{ should_receive(...).once; start } 

是否有辦法幹這些規格?

回答

0

我認爲問題在於規格的設計。

我的建議是要做到:

describe SomeClass do 
    let(:object_instance) { described_class.new } 

    before do 
    # Put expectations in before block, they shouldn't be a part of text example! 
    object_instance.should_receive(:something) 
    end 

    specify { subject.do_something_else } 
end 

如果你有更多的期待,以滿足你可以把所有的人都到before塊或者只是使用不同context秒。

如果很多規格看起來相似,我會選擇將其解壓縮到共享示例中。

相關問題