English 中文(简体)
How are both of these tests passing?
原标题:

I m using Shoulda, Mocha, and Test::Unit for testing. I have the following controller and test:

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

How is it that both of those tests could pass? I am not explicitly expiring my mocks at any point. Are Mohca and Shoulda known to interact poorly in this regard?

问题回答

Aha! The problem is that the expectations do indeed fail but the errors they throw are swallowed up by the controller s error handling. Testing that the action renders properly makes the proper test fail.





相关问题
Selenium not working with Firefox 3.x on linux

I am using selenium-server , selenium rc for UI testing in my application . My dev box is Windows with FireFox 3.5 and every thing is running fine and cool. But when i try to run selenium tests on my ...

Best browser for testing under Safari Mobile on Linux?

I have an iPhone web app I m producing on a Linux machine. What s the best browser I can use to most closely mimic the feature-limited version of Safari present on the iPhone? (It s a "slimmed down" ...

Code Coverage Tools & Visual Studio 2008 Pro

Just wondering what people are using for code coverage tools when using MS Visual Studio 2008 Pro. We are using the built-in MS test project and unit testing tool (the one that come pre-installed ...

Is there any error checking web app cralwers out there?

Wondering if there was some sort of crawler we could use to test and re-test everything when changes are made to the web app so we know some new change didn t error out any existing pages. Or maybe a ...

热门标签