[rspec-users] simple == with prettier error messages + good documentation
Nick Hoffman
nick at deadorange.com
Thu Jan 29 13:42:59 EST 2009
On 29/01/2009, at 1:00 PM, r_j_h_box-sf at yahoo.com wrote:
> Hi all,
>
> I've found myself writing a thing I think is less than optimal,
> looking for suggestions. The context is, I'm testing a result, and
> as a part of that test, I might verify two or three things, which
> are individually relevant but not really discrete results (?).
>
> Here's my thinking process, using a toy example:
>
> foo.should == bar (or foo.should_not be_nil)
>
> > expected not to be nil, but was
>
> (hm, not very informative)
>
> if( foo == nil )
> "failure to setup foo".should == "foo should be set to the thing
> that will be rendered"
> end
>
> > expected "foo should be set to the thing that will be rendered",
> > got "failure to setup foo" (using ==)
>
> I've used this, by example, for a test on a dependency
> (imagemagick), where if the dependency isn't found, I show a decent
> message with info the tester can use to resolve it. And, as I
> mentioned, I've used it for revealing more details in cases where
> the it "" + the generic error aren't informative.
>
> I'm satisfied using this method for things like detecting a failure
> to use a test-helper correctly - works fine, doesn't get in my way
> as part of the documentation. Which brings me to the problem I'm
> concerned about:
>
> With this method, nothing come out in the generated spec-docs to
> represent the thing I'm conditionally requiring.
>
> I guess I could get more fine-grained with my it()'s, but I've been
> preferring a more general statement for it(), that gives the sense
> without the detail.
>
> Any suggestions?
>
> Thanks,
>
> Randy
Hi Randy. I'm not 100% sure what you're asking. In short, are you
wondering how to generate expectation failure messages that are more
verbose and contextual?
Cheers,
Nick
More information about the rspec-users
mailing list