Skip to content

Instantly share code, notes, and snippets.

@bcardarella
Created September 14, 2011 01:00
Show Gist options
  • Save bcardarella/1215606 to your computer and use it in GitHub Desktop.
Save bcardarella/1215606 to your computer and use it in GitHub Desktop.
Given When Then for Capybara DSL
# Throw this into your spec/support directory
# Usage:
#
# feature 'Dashboard' do
# scenario 'all' do
# Given 'I am an authenticated user' do
# authenticate_user
# end
# And 'there are assignments' do
# create(:assignment)
# end
# When 'I visit the dashboard' do
# get dashboard_path
# end
# Then 'I should see my assignments' do
# current_user.assignments.each do |assignment|
# page.body.should include(assignment.title)
# end
# end
# end
#
def AcceptanceCondition(description = '', &block)
example.metadata[:description] << "\n\s\s\s\s#{description}" if description.to_s.strip.size > 0
if block_given?
yield
else
pending 'This step has not be written yet'
end
end
def Given(description = '', &block)
AcceptanceCondition("Given #{description}", &block)
end
def When(description = '', &block)
AcceptanceCondition("When #{description}", &block)
end
def Then(description = '', &block)
AcceptanceCondition("Then #{description}", &block)
end
def And(description = '', &block)
AcceptanceCondition("And #{description}", &block)
end
def But(description = '', &block)
AcceptanceCondition("But #{description}", &block)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment