[rspec-devel] The Reporter -> Formatter interface

David Chelimsky dchelimsky at gmail.com
Fri Dec 14 00:41:01 EST 2007

On Dec 13, 2007 4:50 PM, Bob Cotton <bob.cotton at rallydev.com> wrote:
> Before 1.1.0 gos out, I would like to propose a change to the interface
> of Formatter, and possibly Reporter. As the Formatter interface has
> already changed in 1.1.0, I would like to get this in now.

Sorry Bob, but I just released 1.1 without this. I've been anxious to
get it out for months and couldn't bear waiting for another feature.

> I have on more then one occasion, in a custom Formatter, need to track
> the association between the "active" ExampleGroup and the currently
> passing/failing/pending Example.
> I believe this is caused by the fact that Examples have no knowledge of
> the ExampleGroup that they belong to.

Actually, as things stand now, the Example is an instance of the
ExampleGroup class, each of which is unique and has its own
description. Why don't you see if you can exploit that for your needs.
If not, go ahead and submit a patch to the tracker. Now that we've
gotten past the big hump of the 1.1 release, we should get back on
track of more frequent minor releases.


> This can be see in Spec::Runner::Formatter which tracks a list of
> ExampleGroups so that in Formatter#example_pending, it may pass in the
> description of the ExampleGroup that the example belongs to.
> My proposal is to change the interface of Formatter such that whenever
> an Example is passed in, the ExampleGroup that Example belongs to is
> also passed in. This would change the signature of these methods:
>     example_started
>     example_passed
>     example_failed
>     example_pending
> to all take an example_group as the fist parameter.
> This could be accomplished by having the Reporter simply pass the last
> ExampleGroup it has seen to the Formatter. However this is not
> threadsafe.
> I don't have any mult-threaded requirements at the moment, so I'm not
> proposing that the Example -> Formatter interaction needs to know about
> their ExampleGroup.
> I have time to finish this work, and can have a patch in a day or two.
> Thoughts?
> - Bob
> _______________________________________________
> rspec-devel mailing list
> rspec-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-devel

More information about the rspec-devel mailing list