From de405f73ca558c85029295a1e811cc8af3a82126 Mon Sep 17 00:00:00 2001 From: Ian White Date: Tue, 24 Nov 2009 16:50:37 +0000 Subject: [PATCH] features/support/email.rb adds an email helper for mapping names to email addresses (similar to NavigationHelper in paths.rb) --- History.txt | 14 +++++++++++++ features/generator/generators.feature | 7 +++++++ features/support/email.rb | 1 + rails_generators/pickle/pickle_generator.rb | 1 + rails_generators/pickle/templates/email.rb | 21 +++++++++++++++++++ .../pickle/templates/email_steps.rb | 9 ++++---- 6 files changed, 49 insertions(+), 4 deletions(-) create mode 120000 features/support/email.rb create mode 100644 rails_generators/pickle/templates/email.rb diff --git a/History.txt b/History.txt index 851dd1d4..3a71bfc7 100644 --- a/History.txt +++ b/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 diff --git a/features/generator/generators.feature b/features/generator/generators.feature index 28983fd4..a6d9f290 100644 --- a/features/generator/generators.feature +++ b/features/generator/generators.feature @@ -28,15 +28,20 @@ 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'/ @@ -44,6 +49,7 @@ Feature: allow pickle to generate steps 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 @@ -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 diff --git a/features/support/email.rb b/features/support/email.rb new file mode 120000 index 00000000..b081bbad --- /dev/null +++ b/features/support/email.rb @@ -0,0 +1 @@ +../../rails_generators/pickle/templates/email.rb \ No newline at end of file diff --git a/rails_generators/pickle/pickle_generator.rb b/rails_generators/pickle/pickle_generator.rb index d9c812d1..aa44e561 100644 --- a/rails_generators/pickle/pickle_generator.rb +++ b/rails_generators/pickle/pickle_generator.rb @@ -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') diff --git a/rails_generators/pickle/templates/email.rb b/rails_generators/pickle/templates/email.rb new file mode 100644 index 00000000..77938778 --- /dev/null +++ b/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) \ No newline at end of file diff --git a/rails_generators/pickle/templates/email_steps.rb b/rails_generators/pickle/templates/email_steps.rb index 72381828..6f88fe31 100755 --- a/rails_generators/pickle/templates/email_steps.rb +++ b/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 @@ -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 @@ -16,8 +19,7 @@ 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| @@ -25,8 +27,7 @@ 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|