Skip to content

Commit

Permalink
features/support/email.rb adds an email helper for mapping names to e…
Browse files Browse the repository at this point in the history
…mail addresses (similar to NavigationHelper in paths.rb)
  • Loading branch information
ianwhite committed Nov 24, 2009
1 parent 14977d7 commit de405f7
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 4 deletions.
14 changes: 14 additions & 0 deletions History.txt
@@ -1,3 +1,17 @@
== master

* 1 major improvement
* features/support/email.rb adds an email helper for mapping names to email addresses (similar to NavigationHelper in paths.rb)

* 1 minor improvement
* generated pickle steps are less picky about possessives so that pickle mappings accepted in more places
e.g. when you have
config.map 'my', 'I', 'myself', :to => 'user: "me"'
you can now do
Given I exist
...
Then the project should be one of my assigned projects

== 0.1.23 - 22 Nov 2009

* 1 major improvement
Expand Down
7 changes: 7 additions & 0 deletions features/generator/generators.feature
Expand Up @@ -28,22 +28,28 @@ Feature: allow pickle to generate steps
Given cucumber has been freshly generated
When I run "script/generate pickle email"
Then the file features/support/pickle.rb should exist
And the file features/support/email.rb should exist
And the file features/step_definitions/email.rb should exist
And the file features/support/pickle.rb should match /require 'pickle\/world'/
And the file features/support/pickle.rb should match /require 'pickle\/email\/world'/
And the file features/step_definitions/pickle_steps.rb should be identical to the local step_definitions/pickle_steps.rb
And the file features/step_definitions/email_steps.rb should be identical to the local step_definitions/email_steps.rb
And the file features/support/email.rb should be identical to the local support/email.rb

Scenario: script/generate pickle path email on fresh cuke install
Given cucumber has been freshly generated
When I run "script/generate pickle path email"
Then the file features/support/pickle.rb should exist
And the file features/support/email.rb should exist
And the file features/support/paths.rb should exist
And the file features/support/pickle.rb should be identical to the local support/pickle.rb
And the file features/support/pickle.rb should match /require 'pickle\/world'/
And the file features/support/pickle.rb should match /require 'pickle\/path\/world'/
And the file features/support/pickle.rb should match /require 'pickle\/email\/world'/
And the file features/step_definitions/pickle_steps.rb should be identical to the local step_definitions/pickle_steps.rb
And the file features/support/paths.rb should be identical to the local support/paths.rb
And the file features/step_definitions/email_steps.rb should be identical to the local step_definitions/email_steps.rb
And the file features/support/email.rb should be identical to the local support/email.rb

Scenario: regenerating pickle
Given cucumber has been freshly generated
Expand All @@ -58,3 +64,4 @@ Feature: allow pickle to generate steps
But the file features/support/pickle.rb should not match /require 'pickle\/world'.*require 'pickle\/world'/
And the file features/support/pickle.rb should not match /require 'pickle\/path\/world'.*require 'pickle\/path\/world'/
And the file features/support/pickle.rb should not match /require 'pickle\/email\/world'.*require 'pickle\/email\/world'/
And the file features/support/email.rb should be identical to the local support/email.rb
1 change: 1 addition & 0 deletions features/support/email.rb
1 change: 1 addition & 0 deletions rails_generators/pickle/pickle_generator.rb
Expand Up @@ -30,6 +30,7 @@ def manifest
if @generate_email_steps
pickle_assigns[:pickle_email] = true
m.template 'email_steps.rb', File.join('features/step_definitions', 'email_steps.rb')
m.template 'email.rb', File.join('features/support', 'email.rb')
end

m.template 'pickle_steps.rb', File.join('features/step_definitions', 'pickle_steps.rb')
Expand Down
21 changes: 21 additions & 0 deletions rails_generators/pickle/templates/email.rb
@@ -0,0 +1,21 @@
module EmailHelpers
# Maps a name to an email address. Used by email_steps

def email_for(to)
case to

# add your own name => email address mappings here

when /^#{capture_model}$/
model($1).email

when /^"(.*)"$/
$1

else
to
end
end
end

World(EmailHelpers)
9 changes: 5 additions & 4 deletions rails_generators/pickle/templates/email_steps.rb
@@ -1,4 +1,6 @@
# this file generated by script/generate pickle email
#
# add email mappings in features/support/email.rb

ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
Expand All @@ -7,6 +9,7 @@
ActionMailer::Base.deliveries.clear
end

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

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

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

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

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

0 comments on commit de405f7

Please sign in to comment.