Forum: RSpec Please clarify test / step definition return value?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
James B. (Guest)
on 2009-01-14 21:44
I have been working under the impression that that tests/step
definitions worked on a simple boolean logic and behaved like ruby
methods, the last value is returned.  Thus, in my understanding, if the
return value is true then the step definition passed.  if it was false,
then the step definition failed.

However, in trying to determine why a simple boolean value returned from
the database did not seem to influence the test result I discovered
this:

# This always passes!!!
When /any matcher you want/ do
  false
end

# This, on the other hand, always fails.
When /any matcher you want/ do
  fail
end.

Was I truly fundamentally wrong in my previous belief that test results
are boolean true and false values?  If so, where exactly is this laid
out in the API because I missed it entirely.
David C. (Guest)
on 2009-01-14 23:27
(Received via mailing list)
On Wed, Jan 14, 2009 at 1:44 PM, James B. <removed_email_address@domain.invalid>
wrote:
> # This always passes!!!
> are boolean true and false values?  If so, where exactly is this laid
> out in the API because I missed it entirely.

Seems like you've answered your own question. I'm not sure where it's
laid out in the docs, but I'm also unsure as to where you got the
impression you had :)

Never-the-less - steps will remain quiet unless some error is raised.

David
James B. (Guest)
on 2009-01-14 23:38
David C. wrote:

>
> Seems like you've answered your own question. I'm not sure where it's
> laid out in the docs, but I'm also unsure as to where you got the
> impression you had :)
>

Well, the impression came from my unconscious mental mapping of
pass=true and fail=false.  "should_be something" or "assert
something_else" seem, on the surface, to be a simple true or false, yes
or no, type conditionals. I mapped that impression, in the absence of
any information to the contrary, to my personal expectations of my own
tests.

I have exerted myself to learn this stuff and even have taken the
Pragmatic Programmers course on testing.  Somehow I missed the
distinction between fail and false.  I am not likely to forget it
however...

Regards,
Aslak H. (Guest)
on 2009-01-14 23:46
(Received via mailing list)
On Wed, Jan 14, 2009 at 8:44 PM, James B. <removed_email_address@domain.invalid>
wrote:

> I have been working under the impression that that tests/step
> definitions worked on a simple boolean logic and behaved like ruby
> methods, the last value is returned.  Thus, in my understanding, if the
> return value is true then the step definition passed.  if it was false,
> then the step definition failed.
>

The return value from a step definition means nothing. Where did you get
the
impression that it did? Is there anywhere in the Wiki that hints to this
that we need to fix?


> # This, on the other hand, always fails.
> When /any matcher you want/ do
>  fail
> end.
>
> Was I truly fundamentally wrong in my previous belief that test results
> are boolean true and false values?  If so, where exactly is this laid
> out in the API because I missed it entirely.


Return values aren't mentioned anywhere in the Wiki as far as I know,
which
means they are not significant. Step definitions fail for precisely the
same
reason that Test::Unit, JUnit, NUnit, xUnit methods and RSpec "it"
blocks do
- when an exception is raised.

Since this is such a common idiom I guess noone thought it required a
specific mention.

Please give me a pointer to a relevant page where you'd expect to see
this
mentioned explicitly and I'll make it clear in the Wiki.

Aslak
James B. (Guest)
on 2009-01-15 00:30
Aslak Hellesøy wrote:

>
> Since this is such a common idiom I guess noone thought it required a
> specific mention.
>

Probably.  This is what happens when a dinosaur is brought forceably
forward in time.

> Please give me a pointer to a relevant page where you'd expect to see
> this mentioned explicitly and I'll make it clear in the Wiki.
>

I do not know where it belongs Aslak because it never occurred to me to
look for it.  It is just one of those cases where one thinks that one
understand something but does not.  However, all ones experience is
congruent with ones faulty understanding nonetheless, until it is not
and realization dawns.

I have added a small note regarding fail and false to the bottom of my
own document on Cucumber in case others get caught in the same mind trap
that I set for myself.
This topic is locked and can not be replied to.