[Rspec-devel] Mocha and TestCase#add_assertion

David Chelimsky dchelimsky at gmail.com
Tue Sep 12 09:15:15 EDT 2006

On 9/12/06, Jonathan del Strother <maillist at steelskies.com> wrote:
> On 12 Sep 2006, at 09:57, James Mead wrote:
> > I had a query on the Mocha mailing list this morning from someone
> > who is using RSpec and Mocha plugins. He was seeing an error which
> > looks to be down to RSpec raising an exception when add_assertion
> > is called. Mocha uses add_assertion to include verified
> > expectations in the assertion count. My colleague Chris Roos gives
> > the following tests as an illustration of the problem.
> >
> > # normal test, no errors
> > def test_abc
> >   add_assertion
> > end
> >
> > # rspec spec, raises nil.add_assertion
> > spec "should blah" do
> >   add_assertion
> > end
> >
> > I haven't looked into it any further, but does anyone have any
> > ideas? I suggested he patched his version of Mocha to rescue the
> > exception, but told him I wasn't sure of the ramifications on the
> > RSpec side.
> Just FWIW, add_assertion expects a @_result object.  I needed to call
> assert_redirected_to, and was running into similar problems.  You
> could set it up before each call to assert (@_result =
> Test::Unit::TestResult.new), though this adds a dependency on
> Test:Unit which may or may not be desirable.

You must be using this in the rails environment. The reason you can
use "assert_redirected_to" is because we're inheriting from
Test::Unit::TestCase already.

> You could set up a fake
> object with an add_assertion method, and assign that to @_result.
> ...however, these are all hacks that are just there as a workaround,
> and I'm guessing there's a much better way of doing this.

Agreed, but the fact that we're inheriting from test/unit is a hack,
in my view, to begin with. In the long run, I'd like to see
rspec_on_rails running on its own legs but that is some time off.


More information about the rspec-devel mailing list