[rspec-users] more verbosity for be_an?

David Chelimsky dchelimsky at gmail.com
Sat Jan 2 18:49:39 EST 2010


On Sat, Jan 2, 2010 at 4:50 PM, Rick DeNatale <rick.denatale at gmail.com>wrote:

> On Sat, Jan 2, 2010 at 4:35 PM, David Chelimsky <dchelimsky at gmail.com>
> wrote:
> >
> >
> > On Sat, Jan 2, 2010 at 3:23 PM, Andrew Premdas <apremdas at gmail.com>
> wrote:
> >>
> >> 2009/12/30 rogerdpack <rogerpack2005 at gmail.com>
> >>>
> >>> > What about something like:
> >>> >
> >>> >   expected #<Class:2158174640> => Fixnum to be a kind of Fixnum
> >>> >
> >>> > That is more aligned with other failure messages. WDYT?
> >>>
> >>> I quite like it.
> >>> In this instance it was
> >>>
> >>> 3.class.should be_a Fixnum # fails
> >>>
> >>> I suppose it would be something like
> >>> expected #<Class:Fixnum> => Class to be a kind of Fixnum
> >>>
> >>> ?
> >>>
> >>> > And just out of curiosity, Roger, what's your use case?  I can't
> >>> > remember ever using be_a/be_an, at least not in any code that has
> survived.
> >>>
> >>> The very first test I thought up was "this method should return an
> >>> integer" so kind of a basic test for a not yet existent method.
> >>>
> >>
> >> Isn't this a bit anti-ruby though. Surely the things we should be
> testing
> >> is that the object exists, responds to certain messages and gives
> certain
> >> values back for those messages. Thinking about types is so Java, C++ :-)
> >
> > Generally speaking, you're correct, but there are cases where this is
> > valuable - like if you're spec'ing a factory in a lib for others to use,
> > etc.
>
> However, I need to point out that
>
> although
>
> 1.should be_a Fixnum
>
> that
>
> 1.class.should_not be_a Fixnum
>
> because
>
> 1.class == Fixnum which is after all a Class, and not a Fixnum itself.
>

Right - the initial problem that Roger was reporting was that
"1.class.should be_a(Fixnum)" produced a failure message wasn't that
helpful, not that it failed to fail :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100102/82359dd9/attachment.html>


More information about the rspec-users mailing list