clemens (owner)

Revisions

gist: 218855 Download_button fork
public
Public Clone URL: git://gist.github.com/218855.git
Embed All Files: show embed
domtastic_helpers.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 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_steps.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 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
 
managing_products.feature #
1
2
3
4
5
6
7
8
9
10
11
12
13
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