# Please clarify test / step definition return value?

**URL:** <https://www.ruby-forum.com/t/please-clarify-test-step-definition-return-value/157726>\
**Category:** RSpec\
**Created:** [January 14, 2009, 8:44pm UTC](https://www.ruby-forum.com/t/please-clarify-test-step-definition-return-value/157726 "2009-01-14T20:44:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [January 14, 2009, 8:44pm UTC](https://www.ruby-forum.com/t/please-clarify-test-step-definition-return-value/157726/1 "2009-01-14T20:44:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [January 14, 2009, 10:27pm UTC](https://www.ruby-forum.com/t/please-clarify-test-step-definition-return-value/157726/2 "2009-01-14T22:27:29Z")

</div>

On Wed, Jan 14, 2009 at 1:44 PM, James B. [removed\_email\_address@domain.invalid](mailto: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

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [January 14, 2009, 10:38pm UTC](https://www.ruby-forum.com/t/please-clarify-test-step-definition-return-value/157726/3 "2009-01-14T22:38:08Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [January 14, 2009, 10:46pm UTC](https://www.ruby-forum.com/t/please-clarify-test-step-definition-return-value/157726/4 "2009-01-14T22:46:15Z")

</div>

On Wed, Jan 14, 2009 at 8:44 PM, James B. [removed\_email\_address@domain.invalid](mailto: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

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [January 14, 2009, 11:30pm UTC](https://www.ruby-forum.com/t/please-clarify-test-step-definition-return-value/157726/5 "2009-01-14T23:30:41Z")

</div>

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.
