Forum: RSpec Given/When/Then blocks on Cucumber

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.
A91bd6cef23eb3516245a092e196c4da?d=identicon&s=25 Maurício Linhares (mauricio)
on 2009-06-05 22:58
(Received via mailing list)
Hello guys,

I've been looking at Pyccuracy and found the "Given/Then/When" blocks
to be very interesting and easier to understand and write, specially
when writting scenarios with more than one of those. An example can be
found here: http://www.pyccuracy.org/getting_started_3.html

Here's how they do:

Scenario 1 - Searching for Hello World
Given
  I go to "http://www.google.com"
When
  I fill "q" textbox with "Hello World"
  And I click "btnG" button
Then
  I see "Hello World - Google Search" title

And here's how we would do with Cucumber

Scenario: Searching for Hello World
  Given I go to "http://www.google.com"
  When  I fill "q" textbox with "Hello World"
  When  I click "btnG" button
  Then I see "Hello World - Google Search" title

With cucumber we need to repeat the When's, Then's and Given's if
there's more than one, woudn't it be nice to avoid this?

-
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) |
http://codeshooter.wordpress.com/ (en)
C694a032be7518a0d704318895f8fe1d?d=identicon&s=25 Ben Mabey (mabes)
on 2009-06-05 23:03
(Received via mailing list)
Maurício Linhares wrote:
> Given
>   Given I go to "http://www.google.com"
>   When  I fill "q" textbox with "Hello World"
>   When  I click "btnG" button
>   Then I see "Hello World - Google Search" title
>
> With cucumber we need to repeat the When's, Then's and Given's if
> there's more than one, woudn't it be nice to avoid this?
>

Yep, and you can... (since Cucumber started you've been able to do this)

You can use "And" and "But":

Scenario: Searching for Hello World
  Given I go to "http://www.google.com"
  When  I fill "q" textbox with "Hello World"
  And  I click "btnG" button
  Then I see "Hello World - Google Search" title
  But I should not see "Whatever"


-Ben
C694a032be7518a0d704318895f8fe1d?d=identicon&s=25 Ben Mabey (mabes)
on 2009-06-05 23:04
(Received via mailing list)
Maurício Linhares wrote:
> Given
>   Given I go to "http://www.google.com"
> http://codeshooter.wordpress.com/ (en)
> _______________________________________________
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>

BTW, please use the new Cucumber ML for cucumber related posts:

http://groups.google.com/group/cukes

-Ben
3c28deaff162aeda44f2e0bcdca1dacf?d=identicon&s=25 Joseph Wilk (josephwilk)
on 2009-06-05 23:21
(Received via mailing list)
Maurício Linhares wrote:
> Given
>   Given I go to "http://www.google.com"
>   When  I fill "q" textbox with "Hello World"
>   When  I click "btnG" button
>   Then I see "Hello World - Google Search" title
>
> With cucumber we need to repeat the When's, Then's and Given's if
> there's more than one, woudn't it be nice to avoid this?
>

We don't have to repeat ourselves in Cucumber:

Scenario: Searching for Hello World
  Given I go to "http://www.google.com"
  When  I fill "q" textbox with "Hello World"
  And  I click "btnG" button
  Then I see "Hello World - Google Search" title

While the block idea is interesting the key thing for me is the scenario
reads like prose.

Also we have moved Cuke to its own mailing list, so please send any
Cucumber related questions there.

http://groups.google.com/group/cukes?pli=1

Thanks!
--
Joseph Wilk
http://blog.josephwilk.net
This topic is locked and can not be replied to.