Skip to content

Instantly share code, notes, and snippets.

@clemens
Created October 26, 2009 17:48
Show Gist options
  • Select an option

  • Save clemens/218855 to your computer and use it in GitHub Desktop.

Select an option

Save clemens/218855 to your computer and use it in GitHub Desktop.
# Domtastic Cucumber
#
# domesticate your Cucumber
#
# written by Clemens Kofler <clemens@railway.at>
# http://www.railway.at
# http://github.com/clemens
#
# see http://www.railway.at/articles/2009/09/12/using-cucumber-to-test-a-multilingual-app
# for reasons why this might be what you need ;-)
module DomesticHelpers
def domify(string)
string.gsub(' ', '_')
end
def to_field_id(type, field)
"#{domify(type)}_#{domify(field)}"
end
end
World(DomesticHelpers)
# Domtastic Cucumber
#
# domesticate your Cucumber
#
# written by Clemens Kofler <clemens@railway.at>
# http://www.railway.at
# http://github.com/clemens
#
# see http://www.railway.at/articles/2009/09/12/using-cucumber-to-test-a-multilingual-app
# for reasons why this might be what you need ;-)
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
When /^I (?:press|click|click on) the (.*) button$/ do |button|
click_button(button)
end
When /^I (?:follow|click|click on) the link to add a new (.*)$/ do |type|
click_link("new_#{domify(type)}")
end
When /^I fill in "([^\"]*)" as the (.*)'s (.*)$/ do |value, type, field|
fill_in(to_field_id(type, field), :with => value)
end
When /^I select "([^\"]*)" as the (.*)'s (.*)$/ do |value, type, field|
field_id = to_field_id(type, field)
column_type = domify(type).classify.constantize.columns_hash[domify(field)].type
case column_type
when :time then select_time(value, :id_prefix => field_id)
when :date then select_date(value, :id_prefix => field_id)
when :datetime, :timestamp then select_datetime(value, :id_prefix => field_id)
else
select(value, :from => field_id)
end
end
When /^I attach the file at "([^\"]*)" as the (.*)'s (.*)$/ do |path, type, field|
attach_file(to_field_id(type, field), path)
end
Then /^I should see a (confirmation|error) message$/ do |type|
css_class = type == 'error' ? 'error' : 'notice'
response.should have_tag(".#{css_class}")
end
Then /^I should not see a (confirmation|error) message$/ do |type|
css_class = type == 'error' ? 'error' : 'notice'
response.should_not have_tag(".#{css_class}")
end
Feature: Managing products
In order to sell products
As an admin
I want to manage products
Scenario: Add new product
Given I am on the products index page
When I click on the link to add a new product
And I fill in "Couch" as the product's name
And I select "20 November 2009" as the product's release date
And I press the save button
Then I should see a confirmation message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment