スタブに問題があります。スタブがどのように機能するかを誤解しているに違いないと思います。
スタブは作成されたコンテキスト内にのみ存在しますか? それは私の予想ですが、私の経験では、コンテキスト内でメソッドをスタブすると、別のコンテキストにまだ存在します。
私のコントローラーテストはこれに似ています:
describe '.load_articles' do
context 'articles' do
before(:each) do
Article.stub_chain(:meth1, :meth2).and_return(['article'])
end
it 'sets articles' do
controller.load_articles.should == ['article']
end
end
context 'no articles' do
before(:each) do
Article.stub_chain(:meth1, :meth2).and_return([])
end
it 'sets article' do
controller.load_articles.should == []
end
end
end
2番目の例では、期待しているときにcontroller.load_articles
まだ返されます['article']
[]
私はこれにあまりにも長い間立ち往生してきました。どんな助けでも大歓迎です!