email_spec 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/History.txt +79 -0
  2. data/MIT-LICENSE.txt +19 -0
  3. data/README.rdoc +125 -0
  4. data/Rakefile +51 -0
  5. data/examples/rails_root/Rakefile +7 -0
  6. data/examples/rails_root/app/controllers/application.rb +15 -0
  7. data/examples/rails_root/app/controllers/welcome_controller.rb +9 -0
  8. data/examples/rails_root/app/helpers/application_helper.rb +3 -0
  9. data/examples/rails_root/app/helpers/welcome_helper.rb +2 -0
  10. data/examples/rails_root/app/models/user.rb +2 -0
  11. data/examples/rails_root/app/models/user_mailer.rb +12 -0
  12. data/examples/rails_root/app/views/user_mailer/signup.erb +3 -0
  13. data/examples/rails_root/app/views/welcome/confirm.html.erb +1 -0
  14. data/examples/rails_root/app/views/welcome/index.html.erb +8 -0
  15. data/examples/rails_root/app/views/welcome/signup.html.erb +1 -0
  16. data/examples/rails_root/config/boot.rb +109 -0
  17. data/examples/rails_root/config/database.yml +22 -0
  18. data/examples/rails_root/config/environment.rb +22 -0
  19. data/examples/rails_root/config/environments/development.rb +17 -0
  20. data/examples/rails_root/config/environments/production.rb +24 -0
  21. data/examples/rails_root/config/environments/test.rb +33 -0
  22. data/examples/rails_root/config/initializers/inflections.rb +10 -0
  23. data/examples/rails_root/config/initializers/mime_types.rb +5 -0
  24. data/examples/rails_root/config/initializers/new_rails_defaults.rb +17 -0
  25. data/examples/rails_root/config/routes.rb +43 -0
  26. data/examples/rails_root/cucumber.yml +1 -0
  27. data/examples/rails_root/db/migrate/20090125013728_create_users.rb +11 -0
  28. data/examples/rails_root/db/schema.rb +19 -0
  29. data/examples/rails_root/doc/README_FOR_APP +5 -0
  30. data/examples/rails_root/features/errors.feature +42 -0
  31. data/examples/rails_root/features/example.feature +59 -0
  32. data/examples/rails_root/features/step_definitions/email_steps.rb +74 -0
  33. data/examples/rails_root/features/step_definitions/user_steps.rb +23 -0
  34. data/examples/rails_root/features/step_definitions/webrat_steps.rb +104 -0
  35. data/examples/rails_root/features/support/env.rb +21 -0
  36. data/examples/rails_root/log/development.log +1 -0
  37. data/examples/rails_root/log/test.log +224 -0
  38. data/examples/rails_root/public/404.html +30 -0
  39. data/examples/rails_root/public/422.html +30 -0
  40. data/examples/rails_root/public/500.html +33 -0
  41. data/examples/rails_root/public/dispatch.rb +10 -0
  42. data/examples/rails_root/public/favicon.ico +0 -0
  43. data/examples/rails_root/public/images/rails.png +0 -0
  44. data/examples/rails_root/public/javascripts/application.js +2 -0
  45. data/examples/rails_root/public/javascripts/controls.js +963 -0
  46. data/examples/rails_root/public/javascripts/dragdrop.js +973 -0
  47. data/examples/rails_root/public/javascripts/effects.js +1128 -0
  48. data/examples/rails_root/public/javascripts/prototype.js +4320 -0
  49. data/examples/rails_root/public/robots.txt +5 -0
  50. data/examples/rails_root/script/about +4 -0
  51. data/examples/rails_root/script/autospec +5 -0
  52. data/examples/rails_root/script/console +3 -0
  53. data/examples/rails_root/script/cucumber +7 -0
  54. data/examples/rails_root/script/dbconsole +3 -0
  55. data/examples/rails_root/script/destroy +3 -0
  56. data/examples/rails_root/script/generate +3 -0
  57. data/examples/rails_root/script/performance/benchmarker +3 -0
  58. data/examples/rails_root/script/performance/profiler +3 -0
  59. data/examples/rails_root/script/performance/request +3 -0
  60. data/examples/rails_root/script/plugin +3 -0
  61. data/examples/rails_root/script/process/inspector +3 -0
  62. data/examples/rails_root/script/process/reaper +3 -0
  63. data/examples/rails_root/script/process/spawner +3 -0
  64. data/examples/rails_root/script/runner +3 -0
  65. data/examples/rails_root/script/server +3 -0
  66. data/examples/rails_root/script/spec +5 -0
  67. data/examples/rails_root/script/spec_server +125 -0
  68. data/examples/rails_root/spec/controllers/welcome_controller_spec.rb +15 -0
  69. data/examples/rails_root/spec/model_factory.rb +6 -0
  70. data/examples/rails_root/spec/models/user_mailer_spec.rb +58 -0
  71. data/examples/rails_root/spec/models/user_spec.rb +5 -0
  72. data/examples/rails_root/spec/rcov.opts +2 -0
  73. data/examples/rails_root/spec/spec.opts +4 -0
  74. data/examples/rails_root/spec/spec_helper.rb +51 -0
  75. data/examples/rails_root/stories/all.rb +4 -0
  76. data/examples/rails_root/stories/helper.rb +3 -0
  77. data/examples/rails_root/vendor/plugins/email_spec/rails_generators/email_spec/email_spec_generator.rb +17 -0
  78. data/examples/rails_root/vendor/plugins/email_spec/rails_generators/email_spec/templates/email_steps.rb +74 -0
  79. data/install.rb +0 -0
  80. data/lib/email-spec.rb +1 -0
  81. data/lib/email_spec.rb +14 -0
  82. data/lib/email_spec/address_converter.rb +27 -0
  83. data/lib/email_spec/cucumber.rb +19 -0
  84. data/lib/email_spec/deliveries.rb +55 -0
  85. data/lib/email_spec/email_viewer.rb +70 -0
  86. data/lib/email_spec/helpers.rb +129 -0
  87. data/lib/email_spec/matchers.rb +122 -0
  88. data/rails_generators/email_spec/email_spec_generator.rb +17 -0
  89. data/rails_generators/email_spec/templates/email_steps.rb +74 -0
  90. data/spec/email_spec/matchers_spec.rb +159 -0
  91. data/spec/spec.opts +4 -0
  92. data/spec/spec_helper.rb +4 -0
  93. metadata +181 -0
@@ -0,0 +1,79 @@
1
+ (In Git)
2
+
3
+ === New features
4
+ === Bufixes
5
+
6
+ == 0.2.0 2009-6-08
7
+ No changes. Bumping version for RubyForge release.
8
+
9
+
10
+ == 0.1.4 2009-5-29
11
+
12
+ === Bufixes
13
+ * Require deliveries in the helpers so it doesn't blow up with RSpec. (Craig Webster)
14
+
15
+ == 0.1.3 2009-4-15
16
+
17
+ === Bufixes
18
+ * Fixed regular expressions in genertaed steps. (Ben Mabey)
19
+ * World semantics changed in cucumber (0.2.3.2), email_spec now uses the new API. (Hector Morales)
20
+
21
+ == 0.1.2 2009-4-05
22
+
23
+ === New features
24
+ === Bufixes
25
+ * Actually added the renamed generators to the gem so people could use it! D'oh! (Ben Mabey)
26
+ * You can either use "./script generate email_spec" or "rubigen rails email_spec"
27
+ * Removed Rake tasks from example application to prevent conflicts when used as a plugin. (Ben Mabey)
28
+
29
+ == 0.1.1 2009-3-26
30
+ === New features
31
+ * Switched dir structure over to support rubigen. (Dr. Nic)
32
+
33
+ === Bufixes
34
+
35
+ == 0.1.0 2009-3-25
36
+ === New features
37
+ * Change Rakefile to run all specs and features, as well as prepare the db (Mischa Fierer)
38
+ * Allow for array to be passed into deliver_to matcher. (Diego Carrion)
39
+ * Added matcher for checking if a collection of emails includes an email with a particular subject (Luke Melia, Noah Davis)
40
+ * Introduced hook to convert objects to email addresses (Luke Melia and Lee Bankewitz)
41
+
42
+ This allows you, in your step matcher, to say something like:
43
+ maillbox_for(some_user)
44
+
45
+ Use it in your cucumber env.rb like so:
46
+
47
+ EmailSpec::AddressConverter.instance.conversion do |input|
48
+ if input.is_a?(User)
49
+ input.email
50
+ else
51
+ input
52
+ end
53
+ end
54
+
55
+ === Bufixes
56
+ * Revert parse_email_for_link helper method to allow for text links as well as explicit link finding. (Mischa Fierer)
57
+ * Isolated variances between using email-spec with an ARMailer project. (Luke Melia)
58
+
59
+
60
+ == 0.0.9 2009-2-15
61
+ === New features
62
+ * have_body_text, have_header matchers (Luke Melia)
63
+ * EmailViewer - opens all sent emails in a given scenario when the environment variables are set. (Luke Melia)
64
+ * Added compatibility with using ARMailer in test mode. (Luke Melia)
65
+ === Bugfixes
66
+ * set_current_email now works with multiple addresses in To field. (Brian McManus, Ben Mabey)
67
+
68
+ == 0.0.7 2009-1-20
69
+ === New features
70
+ * have_subject matcher (Ben Mabey)
71
+
72
+ == 0.0.6 2008-12-23
73
+ === New features
74
+ * Improved RSpec documentation and refactorings. (Ben Mabey)
75
+ === Bugfixes
76
+ * Removed sample app Rake Tasks to have it play nice with environments that use Cucumber as plugin- not gem. (Ben Mabey, Ivor- on github)
77
+
78
+ == 0.0.5 2008-12-18
79
+ * Initial release - see this post for full history and contributors: http://www.benmabey.com/2008/12/18/github-rocks/
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2008-2009 Ben Mabey
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,125 @@
1
+ = Email Spec
2
+
3
+ A collection of RSpec matchers and Cucumber steps to make testing emails go smoothly.
4
+
5
+
6
+ == Setup
7
+
8
+ script/plugin install git://github.com/bmabey/email-spec.git
9
+
10
+ === Gem Setup
11
+
12
+ gem install bmabey-email_spec
13
+
14
+ # config/environments/test.rb
15
+ config.gem 'bmabey-email_spec', :lib => 'email_spec'
16
+
17
+ === Cucumber
18
+
19
+ To use the steps in features put the following in your env.rb:
20
+
21
+ # Make sure this require is after you require cucumber/rails/world.
22
+ require 'email_spec/cucumber'
23
+
24
+ This will load all the helpers that the steps rely on.
25
+ It will also add a Before hook for Cucumber so that emails are cleared at the start of each scenario.
26
+
27
+ Then:
28
+
29
+ script/generate email_spec
30
+
31
+ This will give you a bunch of steps to get started with in step_definitions/email_steps.rb
32
+
33
+ === RSpec
34
+
35
+ First you need to require the helpers and matchers in your spec_helper.rb like so:
36
+
37
+ require "email_spec/helpers"
38
+ require "email_spec/matchers"
39
+
40
+ You will then need to include EmailSpec::Helpers and EmailSpec::Matchers in your example groups.
41
+ If you want to have access to the helpers and matchers in all of your examples you can do the following in your spec_helper.rb:
42
+
43
+ Spec::Runner.configure do |config|
44
+ config.include(EmailSpec::Helpers)
45
+ config.include(EmailSpec::Matchers)
46
+ end
47
+
48
+ Otherwise, you will need to include them in the example groups you wish to use them:
49
+
50
+ describe "Signup Email" do
51
+ include EmailSpec::Helpers
52
+ include EmailSpec::Matchers
53
+ ...
54
+ end
55
+
56
+ == Usage
57
+
58
+ === Cucumber
59
+
60
+ Scenario: A new person signs up
61
+ Given I am at "/"
62
+ When I fill in "Email" with "quentin@example.com"
63
+ And I press "Sign up"
64
+ And I should receive an email
65
+ When I open the email
66
+ Then I should see "confirm" in the email
67
+ When I follow "confirm" in the email
68
+ Then I should see "Confirm your new account"
69
+
70
+ For more examples, check out examples/rails_root in the source for a small example app that implements these steps.
71
+
72
+ === RSpec
73
+
74
+ ==== Testing In Isolation ====
75
+ It is often useful to test your mailers in isolation. You can accomplish this by using mocks to verify that the mailer is being called in the correct place and then write focued examples for the actual mailer. This is a simple example from the sample app found in the gem:
76
+
77
+ Verify that the mailer is used correctly in the controller (this would apply to a model as well):
78
+
79
+ describe "POST /signup (#signup)" do
80
+ it "should deliver the signup email" do
81
+ # expect
82
+ UserMailer.should_receive(:deliver_signup).with("email@example.com", "Jimmy Bean")
83
+ # when
84
+ post :signup, "Email" => "email@example.com", "Name" => "Jimmy Bean"
85
+ end
86
+ end
87
+
88
+ Examples for the #signup method in UserMailer:
89
+
90
+ describe "Signup Email" do
91
+ include EmailSpec::Helpers
92
+ include EmailSpec::Matchers
93
+ include ActionController::UrlWriter
94
+
95
+ before(:all) do
96
+ @email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks")
97
+ end
98
+
99
+ it "should be set to be delivered to the email passed in" do
100
+ @email.should deliver_to("jojo@yahoo.com")
101
+ end
102
+
103
+ it "should contain the user's message in the mail body" do
104
+ @email.should have_text(/Jojo Binks/)
105
+ end
106
+
107
+ it "should contain a link to the confirmation link" do
108
+ @email.should have_text(/#{confirm_account_url}/)
109
+ end
110
+
111
+ it "should have the correct subject" do
112
+ @email.should have_subject(/Account confirmation/)
113
+ end
114
+
115
+ end
116
+
117
+ ==== Using the helpers when not testing in isolation ====
118
+
119
+ Don't. :) Seriously, if you do just take a look at the helpers and use them as you wish.
120
+
121
+ == Original Authors
122
+
123
+ Ben Mabey, Aaron Gibralter, Mischa Fierer
124
+
125
+ Please see History.txt for upcoming changsets and other contributors.
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'spec/rake/spectask'
3
+
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |s|
8
+ s.name = "email_spec"
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ['Ben Mabey', 'Aaron Gibralter', 'Mischa Fierer']
11
+ s.email = "ben@benmabey.com"
12
+ s.homepage = "http://github.com/bmabey/email-spec/"
13
+ s.summary = "Easily test email in rspec and cucumber"
14
+ s.bindir = "bin"
15
+ s.description = s.summary
16
+ s.require_path = "lib"
17
+ s.files = %w(History.txt install.rb MIT-LICENSE.txt README.rdoc Rakefile) + Dir["lib/**/*"] + Dir["rails_generators/**/*"] + Dir["spec/**/*"] + Dir["examples/**/*"]
18
+ # rdoc
19
+ s.has_rdoc = true
20
+ s.extra_rdoc_files = %w(README.rdoc MIT-LICENSE.txt)
21
+ s.rubyforge_project = 'email-spec'
22
+ end
23
+ rescue LoadError
24
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
25
+ end
26
+
27
+ begin
28
+ require 'cucumber/rake/task'
29
+ Cucumber::Rake::Task.new(:features)
30
+ rescue LoadError
31
+ task :features do
32
+ abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
33
+ end
34
+ end
35
+
36
+ require 'spec/rake/spectask'
37
+ Spec::Rake::SpecTask.new(:spec) do |spec|
38
+ spec.libs << 'lib' << 'spec'
39
+ spec.spec_files = FileList['spec/**/*_spec.rb']
40
+ end
41
+
42
+ namespace :example_app do
43
+ Spec::Rake::SpecTask.new(:spec) do |spec|
44
+ desc "Specs for Example app"
45
+ spec.libs << 'lib' << 'spec'
46
+ spec.spec_files = FileList['examples/rails_root/spec/**/*_spec.rb']
47
+ end
48
+ end
49
+
50
+ task :default => [:features, :spec, 'example_app:spec']
51
+
@@ -0,0 +1,7 @@
1
+ require(File.join(File.dirname(__FILE__), 'config', 'boot'))
2
+
3
+ require 'rake'
4
+ require 'rake/testtask'
5
+ require 'rake/rdoctask'
6
+
7
+ require 'tasks/rails'
@@ -0,0 +1,15 @@
1
+ # Filters added to this controller apply to all controllers in the application.
2
+ # Likewise, all the methods added will be available for all controllers.
3
+
4
+ class ApplicationController < ActionController::Base
5
+ helper :all # include all helpers, all the time
6
+
7
+ # See ActionController::RequestForgeryProtection for details
8
+ # Uncomment the :secret if you're not using the cookie session store
9
+ protect_from_forgery # :secret => 'a74714b35b202f269f7a297709d555ce'
10
+
11
+ # See ActionController::Base for details
12
+ # Uncomment this to filter the contents of submitted sensitive data parameters
13
+ # from your application log (in this case, all fields with names like "password").
14
+ # filter_parameter_logging :password
15
+ end
@@ -0,0 +1,9 @@
1
+ class WelcomeController < ApplicationController
2
+ def signup
3
+ UserMailer.deliver_signup(params['Email'], params['Name'])
4
+ end
5
+
6
+ def confirm
7
+ end
8
+
9
+ end
@@ -0,0 +1,3 @@
1
+ # Methods added to this helper will be available to all templates in the application.
2
+ module ApplicationHelper
3
+ end
@@ -0,0 +1,2 @@
1
+ module WelcomeHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ class User < ActiveRecord::Base
2
+ end
@@ -0,0 +1,12 @@
1
+ class UserMailer < ActionMailer::Base
2
+ default_url_options[:host] = ''
3
+
4
+ def signup(email, name)
5
+ @recipients = email
6
+ @from = "admin@example.com"
7
+ @subject = "Account confirmation"
8
+ @sent_on = Time.now
9
+ @body[:name] = name
10
+ end
11
+
12
+ end
@@ -0,0 +1,3 @@
1
+ Hello <%= @name %>!
2
+
3
+ <%= link_to "Click here to confirm your account!", confirm_account_url %>
@@ -0,0 +1 @@
1
+ Confirm your new account!
@@ -0,0 +1,8 @@
1
+ <% form_tag '/welcome/signup' do -%>
2
+ <label for="Name">Name</label>
3
+ <%= text_field_tag 'Name' %>
4
+ <label for="Email">Email</label>
5
+ <%= text_field_tag 'Email' %>
6
+ <div><%= submit_tag 'Sign up' %></div>
7
+ <% end -%>
8
+
@@ -0,0 +1 @@
1
+ Thanks! Go check your email!
@@ -0,0 +1,109 @@
1
+ # Don't change this file!
2
+ # Configure your app in config/environment.rb and config/environments/*.rb
3
+
4
+ RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
5
+
6
+ module Rails
7
+ class << self
8
+ def boot!
9
+ unless booted?
10
+ preinitialize
11
+ pick_boot.run
12
+ end
13
+ end
14
+
15
+ def booted?
16
+ defined? Rails::Initializer
17
+ end
18
+
19
+ def pick_boot
20
+ (vendor_rails? ? VendorBoot : GemBoot).new
21
+ end
22
+
23
+ def vendor_rails?
24
+ File.exist?("#{RAILS_ROOT}/vendor/rails")
25
+ end
26
+
27
+ def preinitialize
28
+ load(preinitializer_path) if File.exist?(preinitializer_path)
29
+ end
30
+
31
+ def preinitializer_path
32
+ "#{RAILS_ROOT}/config/preinitializer.rb"
33
+ end
34
+ end
35
+
36
+ class Boot
37
+ def run
38
+ load_initializer
39
+ Rails::Initializer.run(:set_load_path)
40
+ end
41
+ end
42
+
43
+ class VendorBoot < Boot
44
+ def load_initializer
45
+ require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
46
+ Rails::Initializer.run(:install_gem_spec_stubs)
47
+ end
48
+ end
49
+
50
+ class GemBoot < Boot
51
+ def load_initializer
52
+ self.class.load_rubygems
53
+ load_rails_gem
54
+ require 'initializer'
55
+ end
56
+
57
+ def load_rails_gem
58
+ if version = self.class.gem_version
59
+ gem 'rails', version
60
+ else
61
+ gem 'rails'
62
+ end
63
+ rescue Gem::LoadError => load_error
64
+ $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
65
+ exit 1
66
+ end
67
+
68
+ class << self
69
+ def rubygems_version
70
+ Gem::RubyGemsVersion rescue nil
71
+ end
72
+
73
+ def gem_version
74
+ if defined? RAILS_GEM_VERSION
75
+ RAILS_GEM_VERSION
76
+ elsif ENV.include?('RAILS_GEM_VERSION')
77
+ ENV['RAILS_GEM_VERSION']
78
+ else
79
+ parse_gem_version(read_environment_rb)
80
+ end
81
+ end
82
+
83
+ def load_rubygems
84
+ require 'rubygems'
85
+ min_version = '1.3.1'
86
+ unless rubygems_version >= min_version
87
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
88
+ exit 1
89
+ end
90
+
91
+ rescue LoadError
92
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
93
+ exit 1
94
+ end
95
+
96
+ def parse_gem_version(text)
97
+ $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
98
+ end
99
+
100
+ private
101
+ def read_environment_rb
102
+ File.read("#{RAILS_ROOT}/config/environment.rb")
103
+ end
104
+ end
105
+ end
106
+ end
107
+
108
+ # All that for this:
109
+ Rails.boot!