3

Having used Cucumber about a year ago, I got used to writing scenarios this way.

Scenario: user tries to vote on a comment
  Given I have a post
  And I have a comment on that post
  And I am logged in as a different user
  And I am on the post page
  When I click on "upvote" within the "comment"
  Then the comment score should raise
  And the comment author should get points

however recently I discovered, that since Cucumber 1.1, the basic step definitions such as

When I click on "upvote" within the "comment"

are not available anymore, since they're considered a bad practice. I can see how that makes sense, but I'm not really sure how abstract should I write my features now.

Examples that come to mind.

When I upvote on a comment
Then the comment should get points

or less abstract

Given I have a post with a comment
And I'm not the author
When I upvote on the comment
Then the comment author should get points

or even less abstract

Given I have a post with a comment
And I'm not the author
When I upvote on the comment
Then the comment score should increase
And the comment author should get 1 point

or very specific in the Given part

Given I have a post with a comment
And I'm not the author
And I am on the page for that post
When I upvote on the comment
Then the comment score should increase
And the comment author should get 1 point

I know this is a matter of preferrence, but I'm trying to seek some best practices here. Which is the best way to specify scenarios?

Jakub Arnold
  • 85,596
  • 89
  • 230
  • 327

1 Answers1

1

I like making more declarative scenarios, but not so much so that it's not clear what part of the UI is involved. I think the Cucumber team, in trying to discourage the first style, have gone a little too far to the opposite extreme.

I think I like your last example best: Given should generally be pretty specific.

Marnen Laibow-Koser
  • 5,959
  • 1
  • 28
  • 33