我正在使用 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
这两个测试怎么能通过?我在任何时候都没有明确地使我的模拟过期。Mohca 和 Shoulda 在这方面的互动很差吗?