テストには Shoulda、Mocha、および Test::Unit を使用しています。次のコントローラーとテストがあります。
class FoosController < ApplicationController
caches_action :show
def show
@foo = requested_foo
end
private
def requested_foo
Foo.find(params[:id])
end
end
class FoosCachingTest < ActionController::IntegrationTest
def setup
@foo = Foo.first
@session = open_session
end
context 'FoosController#show' do
setup do
@session.get('/foos/1')
end
before_should 'not fetch the Foo from the database' do
FoosController.any_instance.expects(:requested_foo).never
end
before_should 'fetch the Foo from the database' do
FoosController.any_instance.expects(:requested_foo).once.returns(@foo)
end
end
end
これらのテストの両方に合格できるのはどうしてですか? どの時点でも、モックを明示的に期限切れにすることはありません。この点でモーカとシュルダのやり取りがうまくいかないことは知られていますか?