0
我正在使用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的交互性很差?
最近的一个版本的Mocha改变了它的异常是从Exception而不是StandardError派生的 - 在这种情况下,这可能对你有所帮助,因为控制器错误处理可能没有被踢入Exceptions。 – 2010-12-04 17:54:09