# Skipping the testscenario based on Given block execution

**URL:** <https://www.ruby-forum.com/t/skipping-the-testscenario-based-on-given-block-execution/168243>\
**Category:** RSpec\
**Created:** [May 18, 2009, 5:36pm UTC](https://www.ruby-forum.com/t/skipping-the-testscenario-based-on-given-block-execution/168243 "2009-05-18T17:36:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anilg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/73ab20/32.png) [@anilg](https://www.ruby-forum.com/u/anilg)\
**Post date:** [May 18, 2009, 5:36pm UTC](https://www.ruby-forum.com/t/skipping-the-testscenario-based-on-given-block-execution/168243/1 "2009-05-18T17:36:14Z")

</div>

Hi,  
Generally in cucumber, we write the preconditions in GIVEN block,  
Is there any way in cucumber using which test scenario execution is  
skipped, based on the Given block execution.  
Because there is no point in executing the test scenario when  
precondition itself fails.

Please help me in this regard

---

<div class="post-metadata">

**Author:** ![anilg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/73ab20/32.png) [@anilg](https://www.ruby-forum.com/u/anilg)\
**Post date:** [May 18, 2009, 8:49pm UTC](https://www.ruby-forum.com/t/skipping-the-testscenario-based-on-given-block-execution/168243/2 "2009-05-18T20:49:19Z")

</div>

Anil,  
Your precondition shouldn’t fail?

- Lee

2009/5/18 Anil G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![anilg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/73ab20/32.png) [@anilg](https://www.ruby-forum.com/u/anilg)\
**Post date:** [May 19, 2009, 10:30am UTC](https://www.ruby-forum.com/t/skipping-the-testscenario-based-on-given-block-execution/168243/3 "2009-05-19T10:30:31Z")

</div>

Hi,  
I think i am not clear.  
My query is while running the testcases,  
Some times precondition of testcase fails, when precondition itself  
fails there is no point in executing the testcase further.  
so , is there any way in cucumber to skip execution of scenario when  
precondition of testcase fails.

Thanks,  
Anil

---

<div class="post-metadata">

**Author:** ![anilg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/73ab20/32.png) [@anilg](https://www.ruby-forum.com/u/anilg)\
**Post date:** [May 19, 2009, 12:46pm UTC](https://www.ruby-forum.com/t/skipping-the-testscenario-based-on-given-block-execution/168243/4 "2009-05-19T12:46:55Z")

</div>

Anil G. wrote:

> Hi,  
> I think i am not clear.  
> My query is while running the testcases,  
> Some times precondition of testcase fails, when precondition itself  
> fails there is no point in executing the testcase further.  
> so , is there any way in cucumber to skip execution of scenario when  
> precondition of testcase fails.

In a Scenario if any step fails the following steps of that scenario  
are skipped.

This is the current behaviour of Cucumber. Older versions of Cucumber  
had some trouble with properly skipping these steps.

## HTHs

Joseph W.

> **[Joseph Wilk](http://blog.josephwilk.net)**
>
> Exploring patterns as a means of documenting Clojure functions to aid recall and understanding. Whats the difference in Clojure between:
> partition …

---

<div class="post-metadata">

**Author:** ![anilg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/73ab20/32.png) [@anilg](https://www.ruby-forum.com/u/anilg)\
**Post date:** [May 19, 2009, 11:57am UTC](https://www.ruby-forum.com/t/skipping-the-testscenario-based-on-given-block-execution/168243/5 "2009-05-19T11:57:02Z")

</div>

> Hi,  
> I think i am not clear.  
> My query is while running the testcases,  
> Some times precondition of testcase fails, when precondition itself  
> fails there is no point in executing the testcase further.  
> so , is there any way in cucumber to skip execution of scenario when  
> precondition of testcase fails.

The intention is that when a Before block raises an error, the steps  
of the scenario are skipped. However, this isn’t working properly, but  
a fix is in progress:

> **[Lighthouse - Beautifully Simple Issue Tracking](https://lighthouseapp.com/)**

For new threads, please use the Cucumber google group:

> **[Cukes - Google Groups](https://groups.google.com/g/cukes)**

Cheers,  
Aslak

---

<div class="post-metadata">

**Author:** ![anilg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/73ab20/32.png) [@anilg](https://www.ruby-forum.com/u/anilg)\
**Post date:** [May 19, 2009, 1:04pm UTC](https://www.ruby-forum.com/t/skipping-the-testscenario-based-on-given-block-execution/168243/6 "2009-05-19T13:04:31Z")

</div>

This seems like a really bad practice when writing tests, and I’m having  
trouble imagining a situation where this would be justified.

If “sometimes the precondition fails” that means on each test run you  
won’t know whether the test actually ran or not, and thus whether the  
test succeeds or fails.

Seems to me this really needs 2 examples: 1 for when the precondition  
succeeds, 1 for when it fails. What is the source of this  
precondition? Sounds like that needs to be stubbed or mocked.

As always, I would be happy for others to set me back on track…  
Thanks,

dwh
