Skip to content

Instantly share code, notes, and snippets.

@antonymarcano
Created March 17, 2012 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonymarcano/2057807 to your computer and use it in GitHub Desktop.
Save antonymarcano/2057807 to your computer and use it in GitHub Desktop.
The Cucumber Book – Imperative vs. Declarative
Feature: Cucumber Book v1 Imperative Steps P91
These are the scenarios from the Cucumber Book showing Imperative vs. Declarative style
I think the ideas in the book are great but I think that the examples can go further.
# Imperative example from the book
Scenario: Redirect user to originally requested page after logging in
Given a User "dave" exists with password "secret"
And I am not logged in
When I navigate to the home page
Then I am redirected to the login form
When I fill in "Username" with "dave"
And I fill in "Password" with "secret"
And I press "Login"
# Declarative example from the book
Scenario: Redirect user to originally requested page after logging in
Given I am an unauthenticated User
When I attempt to view some restricted content
Then I am shown a login form
When I authenticate with valid credentials
Then I should be shown the restricted content
# I think that the declarative example is still too close to the solution
# How would I write the declarative example?
# There is a challenge here. There's no context.
# What is the business domain?
# For now, let's keep it generic...
Scenario: See the originally requested material once you know who I am
Given I am an anonymous person
And I have tried to view some restricted material
When I prove that I am an authorised person
Then I should see the restricted material
# Notice that I've left out "Then I am shown a login form".
# I wouldn't do that because I won't be able to prove who I am unless that happens
# I'd write that differently anyway... more like: "Then I should be asked to prove that I'm authorised"
# Now, let's say it's a magazine site with articles available only to paying subscribers
Scenario: Read the originally requested subscriber-only article once you know who I am
Given I am an anonymous reader
And I have asked to read a subscriber-only article
When I prove that I am a subscriber
Then I should see the subscriber-only article
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment