I'm using factory_girl + rspec on Rails 2-3-stable:
Test:
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
Code:
def lastfm_scrobbling_enabled?
lastfm_enabled? && lastfm_scrobbling
end
This simple test fails, plus the real lastfm_enabled? method gets called for real.
@profile is not a mock, it's created with factory_girl.
Initially I also stubbed the lastfm_scrobbling attribute, but I was thinking about the way factory_girl works and preferred to set it directly.
Any idea why?