bmabey-email_spec 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,4 +1,12 @@
1
- == 0.0.1 2008-12-18
1
+ (In Git)
2
+ === New features
2
3
 
3
- * 1 major enhancement:
4
- * Initial release
4
+
5
+ == 0.0.6 2008-12-23
6
+ === New features
7
+ * Improved RSpec documentaioni and refactorings. (Ben Mabey)
8
+ === Bugfixes
9
+ * Removed sample app Rake Tasks to have it play nice with environments that use Cucumber as plugin- not gem. (Ben Mabey, Ivor- on github)
10
+
11
+ == 0.0.5 2008-12-18
12
+ * Initial release - see this post for full history and contributos: http://www.benmabey.com/2008/12/18/github-rocks/
data/README.rdoc CHANGED
@@ -31,14 +31,28 @@ Then:
31
31
  This will give you a bunch of steps to get started with in step_definitions/email_steps.rb
32
32
 
33
33
  === RSpec
34
-
35
- The matchers and helpers should be available for your specs by default, but you need to include them into the example groups you want to use them in. To include them in all of your specs you can do this in your spec_helper.rb:
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:
36
42
 
37
43
  Spec::Runner.configure do |config|
38
44
  config.include(EmailSpec::Helpers)
39
45
  config.include(EmailSpec::Matchers)
40
46
  end
41
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
+
42
56
  == Usage
43
57
 
44
58
  === Cucumber
@@ -55,12 +69,59 @@ The matchers and helpers should be available for your specs by default, but you
55
69
 
56
70
  For more examples, check out spec/rails_root in the source for a small example app that implements these steps.
57
71
 
58
- == TODO:
59
-
60
- - refactor!
61
- - provide custom matchers to give better messages
72
+ === RSpec
62
73
 
63
- == Authors
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.body.should have_text(/Jojo Binks/)
105
+ end
106
+
107
+ it "should contain a link to the confirmation link" do
108
+ @email.body.should have_text(/#{confirm_account_url}/)
109
+ end
110
+
111
+ it "should have the correct subject" do
112
+ @email.subject.should =~ /Account confirmation/
113
+ end
114
+
115
+ end
116
+
117
+ ==== Using the helpers when not testing in isolation ====
118
+
119
+ WRITE ME
120
+ For now take a look at Email::Helpers to see what you can do.
121
+
122
+ == Original Authors
64
123
 
65
124
  Ben Mabey, Aaron Gibralter, Mischa Fierer
66
125
 
126
+ Please see History.txt for upcoming changsets and other contributors.
127
+
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ spec = Gem::Specification.new do |s|
6
6
  s.version = EmailSpec::VERSION
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ['Ben Mabrey', 'Aaron Gibralter', 'Mischa Fierer']
9
- s.email = "f.mischa@gmail.com"
9
+ s.email = "ben@benmabey.com"
10
10
  s.homepage = "http://github.com/bmabey/email-spec/"
11
11
  s.summary = "Easily test email in rspec and cucumber"
12
12
  s.bindir = "bin"
@@ -50,7 +50,7 @@ task :generate do
50
50
  end
51
51
 
52
52
  task :features => [:generate] do
53
- system("cd spec/rails_root; rake features; cd ../..")
53
+ system("cucumber spec/rails_root/features")
54
54
  end
55
55
 
56
56
  task :default => :features
data/lib/email_spec.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module EmailSpec
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -1,7 +1,7 @@
1
1
  # require this in your env.rb file after you require cucumber/rails/world
2
2
 
3
3
  %w[helpers matchers].each do |file|
4
- require File.join(File.dirname(__FILE__), "email_spec_#{file}.rb")
4
+ require File.join(File.dirname(__FILE__), file)
5
5
  end
6
6
 
7
7
  # Global Setup
@@ -3,21 +3,12 @@ require 'uri'
3
3
  module EmailSpec
4
4
 
5
5
  module Helpers
6
-
7
- def self.extended(base)
8
- base.instance_eval do
9
- @email_spec_hash = {}
10
- @email_spec_hash[:read_emails] = {}
11
- @email_spec_hash[:unread_emails] = {}
12
- @email_spec_hash[:current_emails] = {}
13
- @email_spec_hash[:current_email] = nil
14
- end
15
- end
16
6
 
17
7
  def reset_mailer
18
8
  ActionMailer::Base.deliveries.clear
19
9
  end
20
10
 
11
+
21
12
  def visit_in_email(link_text)
22
13
  visit(parse_email_for_link(current_email, link_text))
23
14
  end
@@ -35,7 +26,7 @@ module EmailSpec
35
26
  end
36
27
 
37
28
  def current_email(address=nil)
38
- email = address ? @email_spec_hash[:current_emails][address] : @email_spec_hash[:current_email]
29
+ email = address ? email_spec_hash[:current_emails][address] : email_spec_hash[:current_email]
39
30
  raise Spec::Expectations::ExpectationNotMetError, "Expected an open email but none was found. Did you forget to call open_email?" unless email
40
31
  email
41
32
  end
@@ -45,7 +36,7 @@ module EmailSpec
45
36
  end
46
37
 
47
38
  def read_emails_for(address)
48
- @email_spec_hash[:read_emails][address] ||= []
39
+ email_spec_hash[:read_emails][address] ||= []
49
40
  end
50
41
 
51
42
  def mailbox_for(address)
@@ -63,6 +54,10 @@ module EmailSpec
63
54
  end
64
55
 
65
56
  private
57
+
58
+ def email_spec_hash
59
+ @email_spec_hash ||= {:read_emails => {}, :unread_emails => {}, :current_emails => {}, :current_email => nil}
60
+ end
66
61
 
67
62
  def find_email!(address, opts={})
68
63
  email = find_email(address, opts)
@@ -76,8 +71,8 @@ module EmailSpec
76
71
  def set_current_email(email)
77
72
  return unless email
78
73
  read_emails_for(email.to) << email
79
- @email_spec_hash[:current_emails][email.to] = email
80
- @email_spec_hash[:current_email] = email
74
+ email_spec_hash[:current_emails][email.to] = email
75
+ email_spec_hash[:current_email] = email
81
76
  end
82
77
 
83
78
  def parse_email_for_link(email, link_text)
@@ -0,0 +1,15 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe WelcomeController do
4
+
5
+ describe "POST /signup (#signup)" do
6
+ it "should deliver the signup email" do
7
+ # expect
8
+ UserMailer.should_receive(:deliver_signup).with("email@example.com", "Jimmy Bean")
9
+ # when
10
+ post :signup, "Email" => "email@example.com", "Name" => "Jimmy Bean"
11
+ end
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,30 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "Signup Email" do
4
+ include EmailSpec::Helpers
5
+ include EmailSpec::Matchers
6
+ include ActionController::UrlWriter
7
+
8
+ before(:all) do
9
+ @email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks")
10
+ end
11
+
12
+ it "should be set to be delivered to the email passed in" do
13
+ @email.should deliver_to("jojo@yahoo.com")
14
+ end
15
+
16
+ it "should contain the user's message in the mail body" do
17
+ @email.body.should have_text(/Jojo Binks/)
18
+ end
19
+
20
+ it "should contain a link to the confirmation link" do
21
+ @email.body.should have_text(/#{confirm_account_url}/)
22
+ end
23
+
24
+ it "should have the correct subject" do
25
+ @email.subject.should =~ /Account confirmation/
26
+ end
27
+
28
+
29
+ end
30
+
@@ -5,6 +5,9 @@ require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
5
5
  require 'spec'
6
6
  require 'spec/rails'
7
7
 
8
+ require File.expand_path(File.dirname(__FILE__) + '/../../../lib/email_spec/helpers.rb')
9
+ require File.expand_path(File.dirname(__FILE__) + '/../../../lib/email_spec/matchers.rb')
10
+
8
11
  Spec::Runner.configure do |config|
9
12
  # If you're not using ActiveRecord you should remove these
10
13
  # lines, delete config/database.yml and disable :active_record
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bmabey-email_spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Mabrey
@@ -11,12 +11,12 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2008-12-18 00:00:00 -08:00
14
+ date: 2008-12-23 00:00:00 -08:00
15
15
  default_executable:
16
16
  dependencies: []
17
17
 
18
18
  description: Easily test email in rspec and cucumber
19
- email: f.mischa@gmail.com
19
+ email: ben@benmabey.com
20
20
  executables: []
21
21
 
22
22
  extensions: []
@@ -32,8 +32,8 @@ files:
32
32
  - Rakefile
33
33
  - lib/email_spec
34
34
  - lib/email_spec/cucumber.rb
35
- - lib/email_spec/email_spec_helpers.rb
36
- - lib/email_spec/email_spec_matchers.rb
35
+ - lib/email_spec/helpers.rb
36
+ - lib/email_spec/matchers.rb
37
37
  - lib/email_spec.rb
38
38
  - generators/email_spec
39
39
  - generators/email_spec/email_spec_generator.rb
@@ -86,8 +86,6 @@ files:
86
86
  - spec/rails_root/features/support/env.rb
87
87
  - spec/rails_root/lib
88
88
  - spec/rails_root/lib/tasks
89
- - spec/rails_root/lib/tasks/cucumber.rake
90
- - spec/rails_root/lib/tasks/rspec.rake
91
89
  - spec/rails_root/log
92
90
  - spec/rails_root/log/development.log
93
91
  - spec/rails_root/log/test.log
@@ -129,6 +127,10 @@ files:
129
127
  - spec/rails_root/script/spec
130
128
  - spec/rails_root/script/spec_server
131
129
  - spec/rails_root/spec
130
+ - spec/rails_root/spec/controllers
131
+ - spec/rails_root/spec/controllers/welcome_controller_spec.rb
132
+ - spec/rails_root/spec/models
133
+ - spec/rails_root/spec/models/user_mailer_spec.rb
132
134
  - spec/rails_root/spec/rcov.opts
133
135
  - spec/rails_root/spec/spec.opts
134
136
  - spec/rails_root/spec/spec_helper.rb
@@ -1,7 +0,0 @@
1
- $:.unshift(RAILS_ROOT + '/vendor/plugins/cucumber/lib')
2
- require 'cucumber/rake/task'
3
-
4
- Cucumber::Rake::Task.new(:features) do |t|
5
- t.cucumber_opts = "--format pretty"
6
- end
7
- task :features => 'db:test:prepare'
@@ -1,153 +0,0 @@
1
- raise "To avoid rake task loading problems: run 'rake clobber' in vendor/plugins/rspec" if File.directory?(File.join(File.dirname(__FILE__), *%w[.. .. vendor plugins rspec pkg]))
2
- raise "To avoid rake task loading problems: run 'rake clobber' in vendor/plugins/rspec-rails" if File.directory?(File.join(File.dirname(__FILE__), *%w[.. .. vendor plugins rspec-rails pkg]))
3
-
4
- # In rails 1.2, plugins aren't available in the path until they're loaded.
5
- # Check to see if the rspec plugin is installed first and require
6
- # it if it is. If not, use the gem version.
7
- rspec_base = File.expand_path(File.dirname(__FILE__) + '/../../vendor/plugins/rspec/lib')
8
- $LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
9
-
10
- begin
11
- require 'spec/rake/spectask'
12
- Rake.application.instance_variable_get('@tasks').delete('default')
13
-
14
- spec_prereq = File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml')) ? "db:test:prepare" : :noop
15
- task :noop do
16
- end
17
-
18
- task :default => :spec
19
- task :stats => "spec:statsetup"
20
-
21
- desc "Run all specs in spec directory (excluding plugin specs)"
22
- Spec::Rake::SpecTask.new(:spec => spec_prereq) do |t|
23
- t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
24
- t.spec_files = FileList['spec/**/*/*_spec.rb']
25
- end
26
-
27
- namespace :spec do
28
- desc "Run all specs in spec directory with RCov (excluding plugin specs)"
29
- Spec::Rake::SpecTask.new(:rcov) do |t|
30
- t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
31
- t.spec_files = FileList['spec/**/*/*_spec.rb']
32
- t.rcov = true
33
- t.rcov_opts = lambda do
34
- IO.readlines("#{RAILS_ROOT}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
35
- end
36
- end
37
-
38
- desc "Print Specdoc for all specs (excluding plugin specs)"
39
- Spec::Rake::SpecTask.new(:doc) do |t|
40
- t.spec_opts = ["--format", "specdoc", "--dry-run"]
41
- t.spec_files = FileList['spec/**/*/*_spec.rb']
42
- end
43
-
44
- desc "Print Specdoc for all plugin examples"
45
- Spec::Rake::SpecTask.new(:plugin_doc) do |t|
46
- t.spec_opts = ["--format", "specdoc", "--dry-run"]
47
- t.spec_files = FileList['vendor/plugins/**/spec/**/*/*_spec.rb'].exclude('vendor/plugins/rspec/*')
48
- end
49
-
50
- [:models, :controllers, :views, :helpers, :lib].each do |sub|
51
- desc "Run the code examples in spec/#{sub}"
52
- Spec::Rake::SpecTask.new(sub => spec_prereq) do |t|
53
- t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
54
- t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
55
- end
56
- end
57
-
58
- desc "Run the code examples in vendor/plugins (except RSpec's own)"
59
- Spec::Rake::SpecTask.new(:plugins => spec_prereq) do |t|
60
- t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
61
- t.spec_files = FileList['vendor/plugins/**/spec/**/*/*_spec.rb'].exclude('vendor/plugins/rspec/*').exclude("vendor/plugins/rspec-rails/*")
62
- end
63
-
64
- namespace :plugins do
65
- desc "Runs the examples for rspec_on_rails"
66
- Spec::Rake::SpecTask.new(:rspec_on_rails) do |t|
67
- t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
68
- t.spec_files = FileList['vendor/plugins/rspec-rails/spec/**/*/*_spec.rb']
69
- end
70
- end
71
-
72
- # Setup specs for stats
73
- task :statsetup do
74
- require 'code_statistics'
75
- ::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models')
76
- ::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views')
77
- ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers')
78
- ::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers')
79
- ::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib')
80
- ::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models')
81
- ::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views')
82
- ::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers')
83
- ::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers')
84
- ::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib')
85
- ::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
86
- end
87
-
88
- namespace :db do
89
- namespace :fixtures do
90
- desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
91
- task :load => :environment do
92
- require 'active_record/fixtures'
93
- ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
94
- (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
95
- Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
96
- end
97
- end
98
- end
99
- end
100
-
101
- namespace :server do
102
- daemonized_server_pid = File.expand_path("spec_server.pid", RAILS_ROOT + "/tmp")
103
-
104
- desc "start spec_server."
105
- task :start do
106
- if File.exist?(daemonized_server_pid)
107
- $stderr.puts "spec_server is already running."
108
- else
109
- $stderr.puts "Starting up spec server."
110
- system("ruby", "script/spec_server", "--daemon", "--pid", daemonized_server_pid)
111
- end
112
- end
113
-
114
- desc "stop spec_server."
115
- task :stop do
116
- unless File.exist?(daemonized_server_pid)
117
- $stderr.puts "No server running."
118
- else
119
- $stderr.puts "Shutting down spec_server."
120
- system("kill", "-s", "TERM", File.read(daemonized_server_pid).strip) &&
121
- File.delete(daemonized_server_pid)
122
- end
123
- end
124
-
125
- desc "reload spec_server."
126
- task :restart do
127
- unless File.exist?(daemonized_server_pid)
128
- $stderr.puts "No server running."
129
- else
130
- $stderr.puts "Reloading down spec_server."
131
- system("kill", "-s", "USR2", File.read(daemonized_server_pid).strip)
132
- end
133
- end
134
- end
135
- end
136
- rescue MissingSourceFile
137
- # if rspec-rails is a configured gem, this will output helpful material and exit ...
138
- require File.expand_path(File.dirname(__FILE__) + "/../../config/environment")
139
-
140
- # ... otherwise, do this:
141
- raise <<-MSG
142
-
143
- You have rspec-rails rake tasks installed in
144
- #{__FILE__},
145
- but rspec-rails is not configured as a gem in
146
- config/environment.rb
147
-
148
- Either remove #{__FILE__}
149
- or configure the rspec-rails gem in config/environment.rb.
150
-
151
- MSG
152
- end
153
-