[rspec-users] more verbosity for be_an?

Ashley Moran ashley.moran at patchspace.co.uk
Wed Dec 30 17:27:11 EST 2009


On 30 Dec 2009, at 20:19, David Chelimsky wrote:

> What about something like:
> 
>   expected #<Class:2158174640> => Fixnum to be a kind of Fixnum
> 
> That is more aligned with other failure messages. WDYT?

I like that.  You have to read the current message _very_ carefully to see what it's actually saying.

Thinking about it though, isn't the current format wrong anyway?  "Fixnum is the kind of 1" sounds (torturously) correct. For want of ability to say what I mean in terms of types, here are examples instead:

  Integer is a kind of Object*
    Object.new is an (instance of) Object
    Integer is a(n instance of) Class
  Fixnum is a kind of Integer
    1 is a(n instance of) Fixnum

Gets a bit harder with modules though:

  [] is an (instance of) a Class that includes Enumerable
  [] is Enumerable
  (second one only works if the module name is an adjective)

* Actually, this satisfies both definitions, as Integer is an instance Class, which is an Object...

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.

Ashley

-- 
http://www.patchspace.co.uk/
http://www.linkedin.com/in/ashleymoran





More information about the rspec-users mailing list