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 在这方面的互动很差吗?

4

1 回答 1

0

啊哈!问题是期望确实失败了,但是它们抛出的错误被控制器的错误处理所吞噬。测试动作是否正确呈现会使正确的测试失败。

于 2010-10-06T19:18:17.267 回答