Rails2-3-stableでfactory_girl+rspecを使用しています:
テスト:
context "test" do
before(:each) do
@profile.stub!(:lastfm_enabled?).and_return(true)
end
it "should be able to scrobble if true" do
@profile.update_attribute(:lastfm_scrobbling, true)
@profile.lastfm_scrobbling_enabled?.should be_true
end
end
コード:
def lastfm_scrobbling_enabled?
lastfm_enabled? && lastfm_scrobbling
end
この簡単なテストは失敗し、さらに実際のlastfm_enabled?メソッドは実際に呼び出されます。
@profileはモックではなく、factory_girlで作成されています。
最初はlastfm_scrobbling属性もスタブしましたが、factory_girlがどのように機能するかを考えていたので、直接設定することを好みました。
なぜですか?