Skip to content

Commit 0f0a95f

Browse files
author
Michael MacDonald
committed
Upgraded to pickle 0.2.0, cucumber 0.4.4 and fixed an inaccurate scenario step
1 parent 1f3be3a commit 0f0a95f

File tree

11 files changed

+141
-77
lines changed

11 files changed

+141
-77
lines changed

README

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33
This is a very basic and contrived example designed to demonstrate the benefits of using Ian White's "Pickle gem":http://github.com/ianwhite/pickle with Cucumber to improve the way you BDD.
44

5+
== Requirements
6+
7+
cucumber >= 0.4.4
8+
pickle >= 0.2.0
9+
510
== Getting Started
611

7-
1. rake gems:install
12+
1. rake gems:install RAILS_ENV=cucumber
813
2. rake db:migrate
914
3. rake db:test:prepare
1015
4. cucumber

config/environments/cucumber.rb

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# IMPORTANT: This file was generated by Cucumber 0.4.2
1+
# IMPORTANT: This file was generated by Cucumber 0.4.4
22
# Edit at your own peril - it's recommended to regenerate this file
33
# in the future when you upgrade to a newer version of Cucumber.
44

@@ -19,9 +19,8 @@
1919
# ActionMailer::Base.deliveries array.
2020
config.action_mailer.delivery_method = :test
2121

22-
config.gem 'cucumber', :lib => false, :version => '>=0.4.2' unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber'))
23-
config.gem 'webrat', :lib => false, :version => '>=0.5.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat'))
24-
config.gem 'rspec', :lib => false, :version => '>=1.2.8' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec'))
25-
config.gem 'rspec-rails', :lib => false, :version => '>=1.2.7.1' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec-rails'))
26-
27-
config.gem 'pickle'
22+
config.gem 'cucumber', :lib => false, :version => '>=0.4.4' unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber'))
23+
config.gem 'webrat', :lib => false, :version => '>=0.5.3' unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat'))
24+
config.gem 'rspec', :lib => false, :version => '>=1.2.9' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec'))
25+
config.gem 'rspec-rails', :lib => false, :version => '>=1.2.9' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec-rails'))
26+
config.gem 'pickle', :version => '>=0.2.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/pickle'))

features/person.feature

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Feature: Pickle demonstration with Person objects
1616
Given a company exists
1717
And another company: "rubyflare" exists
1818
And a person exists with company: company "rubyflare"
19-
And another person exists with company: the company
19+
And another person exists with company: the first company
2020
Then the first person should be one of company: "rubyflare"'s employees
2121

2222
Scenario: email

features/step_definitions/email_steps.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# this file generated by script/generate pickle email
2+
#
3+
# add email mappings in features/support/email.rb
24

35
ActionMailer::Base.delivery_method = :test
46
ActionMailer::Base.perform_deliveries = true
@@ -7,6 +9,7 @@
79
ActionMailer::Base.deliveries.clear
810
end
911

12+
# Clear the deliveries array, useful if your background sends email that you want to ignore
1013
Given(/^all emails? (?:have|has) been delivered$/) do
1114
ActionMailer::Base.deliveries.clear
1215
end
@@ -16,17 +19,15 @@
1619
end
1720

1821
Then(/^(\d)+ emails? should be delivered to (.*)$/) do |count, to|
19-
to =~ /^#{capture_model}$/ && to = model($1).email
20-
emails("to: \"#{to}\"").size.should == count.to_i
22+
emails("to: \"#{email_for(to)}\"").size.should == count.to_i
2123
end
2224

2325
Then(/^(\d)+ emails? should be delivered with #{capture_fields}$/) do |count, fields|
2426
emails(fields).size.should == count.to_i
2527
end
2628

2729
Then(/^#{capture_email} should be delivered to (.+)$/) do |email_ref, to|
28-
to =~ /^#{capture_model}$/ && to = model($1).email
29-
email(email_ref, "to: \"#{to}\"").should_not be_nil
30+
email(email_ref, "to: \"#{email_for(to)}\"").should_not be_nil
3031
end
3132

3233
Then(/^#{capture_email} should have #{capture_fields}$/) do |email_ref, fields|

features/step_definitions/pickle_steps.rb

+34-8
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,63 @@
1111
end
1212

1313
# create models from a table
14-
Given /^the following #{capture_plural_factory} exist$/ do |plural_factory, table|
14+
Given(/^the following #{capture_plural_factory} exists?:?$/) do |plural_factory, table|
1515
name = plural_factory.singularize
1616
table.hashes.each { |hash| create_model(name, hash) }
1717
end
1818

1919
# find a model
2020
Then(/^#{capture_model} should exist(?: with #{capture_fields})?$/) do |name, fields|
21-
find_model(name, fields).should_not be_nil
21+
find_model!(name, fields)
22+
end
23+
24+
# not find a model
25+
Then(/^#{capture_model} should not exist(?: with #{capture_fields})?$/) do |name, fields|
26+
find_model(name, fields).should be_nil
27+
end
28+
29+
# find models with a table
30+
Then(/^the following #{capture_plural_factory} should exists?:?$/) do |plural_factory, table|
31+
name = plural_factory.singularize
32+
table.hashes.each { |hash| find_model!(name, hash)}
2233
end
2334

2435
# find exactly n models
2536
Then(/^(\d+) #{capture_plural_factory} should exist(?: with #{capture_fields})?$/) do |count, plural_factory, fields|
2637
find_models(plural_factory.singularize, fields).size.should == count.to_i
2738
end
2839

40+
# assert equality of models
41+
Then(/^#{capture_model} should be #{capture_model}$/) do |a, b|
42+
model!(a).should == model!(b)
43+
end
44+
2945
# assert model is in another model's has_many assoc
30-
Then(/^#{capture_model} should be (?:in|one of|amongst) #{capture_model}'s (\w+)$/) do |target, owner, association|
31-
model(owner).send(association).should include(model(target))
46+
Then(/^#{capture_model} should be (?:in|one of|amongst) #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
47+
model!(owner).send(association).should include(model!(target))
48+
end
49+
50+
# assert model is not in another model's has_many assoc
51+
Then(/^#{capture_model} should not be (?:in|one of|amongst) #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
52+
model!(owner).send(association).should_not include(model!(target))
3253
end
3354

3455
# assert model is another model's has_one/belongs_to assoc
35-
Then(/^#{capture_model} should be #{capture_model}'s (\w+)$/) do |target, owner, association|
36-
model(owner).send(association).should == model(target)
56+
Then(/^#{capture_model} should be #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
57+
model!(owner).send(association).should == model!(target)
58+
end
59+
60+
# assert model is not another model's has_one/belongs_to assoc
61+
Then(/^#{capture_model} should not be #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
62+
model!(owner).send(association).should_not == model!(target)
3763
end
3864

3965
# assert model.predicate?
4066
Then(/^#{capture_model} should (?:be|have) (?:an? )?#{capture_predicate}$/) do |name, predicate|
41-
model(name).should send("be_#{predicate.gsub(' ', '_')}")
67+
model!(name).should send("be_#{predicate.gsub(' ', '_')}")
4268
end
4369

4470
# assert not model.predicate?
4571
Then(/^#{capture_model} should not (?:be|have) (?:an? )?#{capture_predicate}$/) do |name, predicate|
46-
model(name).should_not send("be_#{predicate.gsub(' ', '_')}")
72+
model!(name).should_not send("be_#{predicate.gsub(' ', '_')}")
4773
end

features/step_definitions/webrat_steps.rb

+29-29
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# IMPORTANT: This file was generated by Cucumber 0.4.2
1+
# IMPORTANT: This file was generated by Cucumber 0.4.4
22
# Edit at your own peril - it's recommended to regenerate this file
33
# in the future when you upgrade to a newer version of Cucumber.
44
# Consider adding your own code to a new file instead of editing this one.
@@ -8,31 +8,31 @@
88
# Commonly used webrat steps
99
# http://github.com/brynary/webrat
1010

11-
Given /^I am on (.+)$/ do |page_name|
11+
Given /^(?:|I )am on (.+)$/ do |page_name|
1212
visit path_to(page_name)
1313
end
1414

15-
When /^I go to (.+)$/ do |page_name|
15+
When /^(?:|I )go to (.+)$/ do |page_name|
1616
visit path_to(page_name)
1717
end
1818

19-
When /^I press "([^\"]*)"$/ do |button|
19+
When /^(?:|I )press "([^\"]*)"$/ do |button|
2020
click_button(button)
2121
end
2222

23-
When /^I follow "([^\"]*)"$/ do |link|
23+
When /^(?:|I )follow "([^\"]*)"$/ do |link|
2424
click_link(link)
2525
end
2626

27-
When /^I follow "([^\"]*)" within "([^\"]*)"$/ do |link, parent|
27+
When /^(?:|I )follow "([^\"]*)" within "([^\"]*)"$/ do |link, parent|
2828
click_link_within(parent, link)
2929
end
3030

31-
When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
31+
When /^(?:|I )fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
3232
fill_in(field, :with => value)
3333
end
3434

35-
When /^I fill in "([^\"]*)" for "([^\"]*)"$/ do |value, field|
35+
When /^(?:|I )fill in "([^\"]*)" for "([^\"]*)"$/ do |value, field|
3636
fill_in(field, :with => value)
3737
end
3838

@@ -47,19 +47,19 @@
4747
# TODO: Add support for checkbox, select og option
4848
# based on naming conventions.
4949
#
50-
When /^I fill in the following:$/ do |fields|
50+
When /^(?:|I )fill in the following:$/ do |fields|
5151
fields.rows_hash.each do |name, value|
5252
When %{I fill in "#{name}" with "#{value}"}
5353
end
5454
end
5555

56-
When /^I select "([^\"]*)" from "([^\"]*)"$/ do |value, field|
56+
When /^(?:|I )select "([^\"]*)" from "([^\"]*)"$/ do |value, field|
5757
select(value, :from => field)
5858
end
5959

6060
# Use this step in conjunction with Rail's datetime_select helper. For example:
6161
# When I select "December 25, 2008 10:00" as the date and time
62-
When /^I select "([^\"]*)" as the date and time$/ do |time|
62+
When /^(?:|I )select "([^\"]*)" as the date and time$/ do |time|
6363
select_datetime(time)
6464
end
6565

@@ -72,92 +72,92 @@
7272
# The following steps would fill out the form:
7373
# When I select "November 23, 2004 11:20" as the "Preferred" date and time
7474
# And I select "November 25, 2004 10:30" as the "Alternative" date and time
75-
When /^I select "([^\"]*)" as the "([^\"]*)" date and time$/ do |datetime, datetime_label|
75+
When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" date and time$/ do |datetime, datetime_label|
7676
select_datetime(datetime, :from => datetime_label)
7777
end
7878

7979
# Use this step in conjunction with Rail's time_select helper. For example:
8080
# When I select "2:20PM" as the time
8181
# Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat
8282
# will convert the 2:20PM to 14:20 and then select it.
83-
When /^I select "([^\"]*)" as the time$/ do |time|
83+
When /^(?:|I )select "([^\"]*)" as the time$/ do |time|
8484
select_time(time)
8585
end
8686

8787
# Use this step when using multiple time_select helpers on a page or you want to
8888
# specify the name of the time on the form. For example:
8989
# When I select "7:30AM" as the "Gym" time
90-
When /^I select "([^\"]*)" as the "([^\"]*)" time$/ do |time, time_label|
90+
When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" time$/ do |time, time_label|
9191
select_time(time, :from => time_label)
9292
end
9393

9494
# Use this step in conjunction with Rail's date_select helper. For example:
9595
# When I select "February 20, 1981" as the date
96-
When /^I select "([^\"]*)" as the date$/ do |date|
96+
When /^(?:|I )select "([^\"]*)" as the date$/ do |date|
9797
select_date(date)
9898
end
9999

100100
# Use this step when using multiple date_select helpers on one page or
101101
# you want to specify the name of the date on the form. For example:
102102
# When I select "April 26, 1982" as the "Date of Birth" date
103-
When /^I select "([^\"]*)" as the "([^\"]*)" date$/ do |date, date_label|
103+
When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" date$/ do |date, date_label|
104104
select_date(date, :from => date_label)
105105
end
106106

107-
When /^I check "([^\"]*)"$/ do |field|
107+
When /^(?:|I )check "([^\"]*)"$/ do |field|
108108
check(field)
109109
end
110110

111-
When /^I uncheck "([^\"]*)"$/ do |field|
111+
When /^(?:|I )uncheck "([^\"]*)"$/ do |field|
112112
uncheck(field)
113113
end
114114

115-
When /^I choose "([^\"]*)"$/ do |field|
115+
When /^(?:|I )choose "([^\"]*)"$/ do |field|
116116
choose(field)
117117
end
118118

119-
When /^I attach the file at "([^\"]*)" to "([^\"]*)"$/ do |path, field|
119+
When /^(?:|I )attach the file at "([^\"]*)" to "([^\"]*)"$/ do |path, field|
120120
attach_file(field, path)
121121
end
122122

123-
Then /^I should see "([^\"]*)"$/ do |text|
123+
Then /^(?:|I )should see "([^\"]*)"$/ do |text|
124124
response.should contain(text)
125125
end
126126

127-
Then /^I should see "([^\"]*)" within "([^\"]*)"$/ do |text, selector|
127+
Then /^(?:|I )should see "([^\"]*)" within "([^\"]*)"$/ do |text, selector|
128128
within(selector) do |content|
129129
content.should contain(text)
130130
end
131131
end
132132

133-
Then /^I should see \/([^\/]*)\/$/ do |regexp|
133+
Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
134134
regexp = Regexp.new(regexp)
135135
response.should contain(regexp)
136136
end
137137

138-
Then /^I should see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector|
138+
Then /^(?:|I )should see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector|
139139
within(selector) do |content|
140140
regexp = Regexp.new(regexp)
141141
content.should contain(regexp)
142142
end
143143
end
144144

145-
Then /^I should not see "([^\"]*)"$/ do |text|
145+
Then /^(?:|I )should not see "([^\"]*)"$/ do |text|
146146
response.should_not contain(text)
147147
end
148148

149-
Then /^I should not see "([^\"]*)" within "([^\"]*)"$/ do |text, selector|
149+
Then /^(?:|I )should not see "([^\"]*)" within "([^\"]*)"$/ do |text, selector|
150150
within(selector) do |content|
151151
content.should_not contain(text)
152152
end
153153
end
154154

155-
Then /^I should not see \/([^\/]*)\/$/ do |regexp|
155+
Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
156156
regexp = Regexp.new(regexp)
157157
response.should_not contain(regexp)
158158
end
159159

160-
Then /^I should not see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector|
160+
Then /^(?:|I )should not see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector|
161161
within(selector) do |content|
162162
regexp = Regexp.new(regexp)
163163
content.should_not contain(regexp)
@@ -180,7 +180,7 @@
180180
field_labeled(label).should_not be_checked
181181
end
182182

183-
Then /^I should be on (.+)$/ do |page_name|
183+
Then /^(?:|I )should be on (.+)$/ do |page_name|
184184
URI.parse(current_url).path.should == path_to(page_name)
185185
end
186186

features/support/email.rb

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module EmailHelpers
2+
# Maps a name to an email address. Used by email_steps
3+
4+
def email_for(to)
5+
case to
6+
7+
# add your own name => email address mappings here
8+
9+
when /^#{capture_model}$/
10+
model($1).email
11+
12+
when /^"(.*)"$/
13+
$1
14+
15+
else
16+
to
17+
end
18+
end
19+
end
20+
21+
World(EmailHelpers)

features/support/env.rb

+1-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# IMPORTANT: This file was generated by Cucumber 0.4.2
1+
# IMPORTANT: This file was generated by Cucumber 0.4.4
22
# Edit at your own peril - it's recommended to regenerate this file
33
# in the future when you upgrade to a newer version of Cucumber.
44
# Consider adding your own code to a new file instead of editing this one.
@@ -45,21 +45,3 @@
4545
config.open_error_files = false # Set to true if you want error pages to pop up in the browser
4646
end
4747

48-
require 'pickle/world'
49-
# Example of configuring pickle:
50-
#
51-
# Pickle.configure do |config|
52-
# config.adapters = [:machinist]
53-
# config.map 'I', 'myself', 'me', 'my', :to => 'user: "me"'
54-
# end
55-
require 'pickle/path/world'
56-
require 'pickle/email/world'
57-
58-
# settings for machinist
59-
60-
require "#{RAILS_ROOT}/features/support/blueprints" # load blueprints
61-
# original setting
62-
Before { Sham.reset } # reset Sham in between scenarios
63-
# might want to switch to:
64-
# Before { Sham.reset(:before_each) }
65-
# and should we have one for :before_all (see related entry in machinist readme)

0 commit comments

Comments
 (0)