[Rspec-devel] Mocha and TestCase#add_assertion

aslak hellesoy aslak.hellesoy at gmail.com
Tue Sep 12 10:21:26 EDT 2006


On 9/12/06, David Chelimsky <dchelimsky at gmail.com> wrote:
> 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.
>

That's where we started, and we had to reimplement tons of code -
especially the fixtures stuff.
When we got the inherit support in RSpec we could throw away a lot of
our own code and reuse more from Rails.

This is a Good Thing.

It would be great if we could reuse without also getting the
Test::Unit baggage, but I'm not sure that's going to happen. It's a
major refactoring in Rails, and I'm not sure if anyone is willing to
undertake that effort, even less sure it will get applied if someone
does.

And I don't see how the extra Test::Unit baggage is really hurting us.

A

> David
> _______________________________________________
> Rspec-devel mailing list
> Rspec-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-devel
>


More information about the rspec-devel mailing list