[rspec-users] Cucumber - Adding a step definition

Matt Wynne matt at mattwynne.net
Sat Mar 14 16:33:34 EDT 2009


On 14 Mar 2009, at 15:50, Mark Wilden wrote:

> On Sat, Mar 14, 2009 at 5:59 AM, Matt Wynne <matt at mattwynne.net>  
> wrote:
>
>> I'm not sure if I like this - dependency between steps seems like a  
>> dodgy
>> road to go down.
>
> I'm wondering how you'd feel about a style I've adopted:
>
>  Scenario: Accepting a direct challenge, without leaving a comment
>    Given there is a challenge
>    And I am logged in
>    And I have been invited to that challenge
>    When I visit the challenge's page
>    And I press "Accept"
>    Then I should go to my attempt detail page for the challenge
>    And I should see that I accepted the challenge
>    And I should not see "Attempt Challenge"
>
> Clearly, there is dependency between steps - each has to know what
> challenge they're working on, for one thing. But I've found that it
> reads better than the alternative
>
>   Given there is a challenge call 'Reach from the Stars' for 'Halo 3'
>    And I am logged in as Mark
>    And Mark was invited to 'Reach from the Stars' for 'Halo 3' on
> 'Sept 1, 2009' by 'Bill'
>   When I visit the challenge page for 'Reach from the Stars for  
> 'Halo 3'
>    And I press "Accept"
>    Then I should go to Mark's attempt detail page for the challenge
> 'Reach from the Stars' for 'Halo 3'
>    And I should see that 'You accepted this challenge on Sept 1,
> 2009'   And I should not see "Attempt Challenge"
>
> The first one reads more like a business-level story to me and the
> second one reads more like a test.

Totally agree with this, and I do it all the time. On my team we allow  
ourselves to use the term 'the Widget' to mean Widget.first, but we'll  
always assert Widget.count.should == 1 when we do.

We also have a nifty little convention that allows us to talk about  
'the Widget "Foo"' and 'the Widget "Bar"' because pretty much every  
entity in our domain (or at least the ones we refer to like this in  
our features) has a #name attribute.

Matt Wynne
http://blog.mattwynne.net
http://www.songkick.com



More information about the rspec-users mailing list