| z, ? | toggle help (this) |
| space, → | next slide |
| shift-space, ← | previous slide |
| d | toggle debug mode |
| ## <ret> | go to slide # |
| c, t | table of contents (vi) |
| f | toggle footer |
| r | reload slides |
| n | toggle notes |
| p | run preshow |


# In your Gemfile:
gem 'cucumber-rails' # For rails projects
gem 'cucumber' # Otherwise
# Install the the cucumber gem
bundle install
# Install cucumber in your rails app
# (cucumber-rails only)
rails g cucumber:install
# Setup the test database
rake db:test:prepare
# To run the test suite
cucumber
# features/user/authentication.feature
Feature: Authentication (web steps)
As A User
In order to gain access to skynet
I want to be able to login and logout
Background:
Given the following user exists:
| email | password |
| z@b.com | giraffes |
# features/user/authentication.feature
Scenario: Logging in
Given I am on the login page
When I fill in "Email" with "z@b.com"
And I fill in "Password" with "giraffes"
And I press "Sign in"
Then I should see "Signed in"# features/support/paths.rb
module NavigationHelpers
def path_to(page_name)
# ...
when /^the member(s?) sign in page$/
new_member_session_path
# ...
end
end
# features/user/authentication.feature
Feature: Authentication (web steps + Own)
As A User
In order to gain access to skynet
I want to be able to login and logout
Scenario: Logging in
Given I have a valid account
And I am on the login page
When I fill in my user details
And I press "Sign in"
Then I should see "Signed in"# features/step_definitions/authentication.rb
Given /^I have a valid account$/ do
@current_email = 'my@email.com'
@current_password = 'candles'
@current_user = FactoryGirl.create(:user,
:email => @current_email,
:password => @current_password)
end
When /^I fill in my user details$/ do
Then %{I fill in "Email" with "#{@current_email}"}
Then %{I fill in "Password" with "#{@current_password}"}
endImperative means that you write each step that needs to be taken to complete the outcome, for example "fill in the email form input".
Declarative means that you write the outcome for the scenario, which is how we write our user stories and how a client thinks of the parts of their project.
An example would be "Given a user has an account, they should be able to login"
The individual steps are not as important.
# features/user/authentication.feature
Feature: Authentication (No Web Steps, Declarative)
As A User
In order to gain access to skynet
I want to be able to login and logout
Scenario: Logging in
Given I have a valid account
Then I should be able to login# features/step_definitions/authentication.rb
Then /^I should be able to login$/ do
visit new_user_session_path
fill_in_my_details
click_button 'Sign in'
page.should have_content 'Signed in'
endfill_in_my_details method?# features/support/helpers/authentication_helper.rb
module AuthenticationHelper
def fill_in_my_details
fill_in 'Email', :with => @current_email
fill_in 'Password', :with => @current_password
end
end
World(AuthenticationHelper)These slides are online at: http://mariovisic.github.com/declarative_cucumber/
All code snippets are working examples from:
https://github.com/mariovisic/declarative_cucumber