More verbosity for be_an?

before I hack up a patch for it. Would a patch to change

“expected Fixnum to be a kind of Fixnum”

to

“expected Fixnum to be a kind of Fixnum (is a Class)”

or possibly

“expected Fixnum to be a kind of Fixnum (is a Class, Module, Object,
Kernel, BasicObject)”

have any chance of being accepted?
Thanks.
-r

On Wed, Dec 30, 2009 at 1:33 PM, rogerdpack [email protected]
wrote:

“expected Fixnum to be a kind of Fixnum (is a Class, Module, Object,
Kernel, BasicObject)”

have any chance of being accepted?

Probably not with that exact wording, but if you feel the message is not
telling you what you need to know, I’m open to other ideas.

What about something like:

expected #Class:2158174640 => Fixnum to be a kind of Fixnum

That is more aligned with other failure messages. WDYT?

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.

-r

2009/12/30 rogerdpack [email protected]

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++ :slight_smile:

all best

Andrew

On 30 Dec 2009, at 20:19, David C. 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

On Sat, Jan 2, 2010 at 3:23 PM, Andrew P. [email protected]
wrote:

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++ :slight_smile:

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.

On Sat, Jan 2, 2010 at 4:35 PM, David C. [email protected]
wrote:

That is more aligned with other failure messages. WDYT?

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.


Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: Rick DeNatale - Developer - IBM | LinkedIn

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++ :slight_smile:

Yeah, though it’s a bit hard when it’s supposed to return the pid of
some external process :slight_smile:

-r

On Sat, Jan 2, 2010 at 4:50 PM, Rick DeNatale
[email protected]wrote:

expected #Class:Fixnum => Class to be a kind of Fixnum

However, I need to point out that

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 :slight_smile:

2010/1/3 rogerdpack [email protected]

Well your pid could be a string or an integer, or even some a bizarre
proprietary un-docomented PID construct from planet foo . But as far as
Ruby
is concerned you’ll be getting back an object thats for sure, and
anything
else is completely up in the air. However as soon as you start
specifying
that a Fixnum should be returned, then you’ve removed the possibility of
receiving a string or a bizarre proprietary un-docomented PID construct
from
planet foo. This is very anti-ruby (its a dynamic language). And it
means
that your method will have to do all sorts of type conversion rubbish to
go
from String, 'construct to Fixnum to pass your test.

In ruby all your interested in is that you get something that responds
to
to_s (to_i) and gives you a suitable value

-r

What about something like:

expected #Class:2158174640 => Fixnum to be a kind of Fixnum

Still in favor of something like this…
:slight_smile:
-rp

2010/1/2 David C. [email protected]

That is more aligned with other failure messages. WDYT?

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.

I don’t think those cases apply to this thread (judging from its
context),
but I can see benefits from the improved error message that may result
from
this discussion.

Andrew

On Sat, Jan 9, 2010 at 1:33 PM, rogerdpack [email protected]
wrote:

What about something like:

expected #Class:2158174640 => Fixnum to be a kind of Fixnum

Truthfully, I find this much less clear than the original message.

I’ve got no idea what #Class:2158174640 => Fixnum means.

Expected Fixnum to be kind of Fixnum makes a lot of sense to me
because I know that x.kind_of? Y means that x is an INSTANCE of Y or
one of it’s subclasses, and Fixnum is not a Fixnum but a class.

Pondering this if you don’t know that should lead to doing a little
reading and then realizing that you probably wanted

1.should be_a FixNum

instead of

1.class.should be_a Fixnum


Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: Rick DeNatale - Developer - IBM | LinkedIn