email_spec 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,16 @@
1
1
  == 1.2 (git)
2
2
 
3
+ === New features
4
+ * [he|she] options for steps. (Dan Croak)
5
+ * cc_to RSpec matcher. (Arie on github)
6
+ * Check both html and text parts of multipart emails in Cucumber step. (Charles Barbier)
7
+ * delivery_method is not set by email_spec to allow for SMTP (e.g. MockSMTP) delivery (Donald Piret)
8
+
9
+ === Bugfixes
10
+ * delivered_to matcher now compares both sender name and email address. (Jason Garber)
11
+ * find_email now matches with_subject and with_text containing text with regex sensitive characters. Issue #31. (Curtis Miller)
12
+ * current_email_address to work outside of the context of Cucumber. (Szymon Przybył)
13
+
3
14
  == 1.1.1 2010-12-29
4
15
  * Require "action_mailer" to avoid deprecation warnings. (Ryan Bigg)
5
16
  * Relaxes pessimistic version dependency on RSpec. (GH-41 Dan Pickett)
@@ -44,6 +44,16 @@ Then:
44
44
 
45
45
  This will give you a bunch of steps to get started with in step_definitions/email_steps.rb
46
46
 
47
+ By default, the generated file will look for email to example@example.com. You can either change this
48
+ by editing the current_email_address method in email_steps.rb, or by simply specifying the target
49
+ email in your features:
50
+
51
+ Scenario: A new person signs up
52
+ Given I am at "/"
53
+ When I fill in "Email" with "quentin@example.com"
54
+ And I press "Sign up"
55
+ And "quentin@example.com" should receive an email # Specify who should receive the email
56
+
47
57
  === RSpec
48
58
 
49
59
  First you need to require email_spec in your spec_helper.rb:
@@ -85,7 +95,7 @@ For more examples, check out examples/rails_root in the source for a small examp
85
95
  === RSpec
86
96
 
87
97
  ==== Testing In Isolation
88
- 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:
98
+ 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 focused examples for the actual mailer. This is a simple example from the sample app found in the gem:
89
99
 
90
100
  Verify that the mailer is used correctly in the controller (this would apply to a model as well):
91
101
 
data/Rakefile CHANGED
@@ -22,6 +22,7 @@ begin
22
22
  s.has_rdoc = true
23
23
  s.extra_rdoc_files = %w(README.rdoc MIT-LICENSE.txt)
24
24
  s.rubyforge_project = 'email-spec'
25
+ s.add_runtime_dependency "mail", "~> 2.2"
25
26
  s.add_runtime_dependency "rspec", "~> 2.0"
26
27
  end
27
28
  rescue LoadError
@@ -40,14 +41,7 @@ end
40
41
  require 'rspec/core/rake_task'
41
42
  RSpec::Core::RakeTask.new
42
43
 
43
- namespace :example_app do
44
- RSpec::Core::RakeTask.new do |spec|
45
- desc "Specs for Example app"
46
- spec.pattern = './examples/rails3_root/spec/**/*_spec.rb'
47
- end
48
- end
49
-
50
- task :default => [:features, :spec, 'example_app:spec']
44
+ task :default => [:features, :spec]
51
45
 
52
46
  desc "Cleans the project of any tmp file that should not be included in the gemspec."
53
47
  task :clean do
@@ -61,7 +55,7 @@ task :clean do
61
55
  FileUtils.rm_rf("examples/#{ver}_root/vendor")
62
56
  end
63
57
 
64
- %w[*.sqlite3 *.log].each do |pattern|
58
+ %w[*.sqlite3 *.log #*#].each do |pattern|
65
59
  `find . -name "#{pattern}" -delete`
66
60
  end
67
61
  end
@@ -11,7 +11,7 @@ group :test do
11
11
  gem "cucumber-rails"
12
12
  gem "database_cleaner"
13
13
  gem 'capybara'
14
- gem "rspec", ">= 2.0.0.beta.19"
15
- gem "rspec-rails", ">= 2.0.0.beta.19"
14
+ gem "rspec", ">= 2.0.1"
15
+ gem "rspec-rails", ">= 2.0.1"
16
16
  gem "email_spec", :path => "../../"
17
17
  end
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- email_spec (1.0.0)
5
- rspec (~> 2.0.0)
4
+ email_spec (1.1.1)
5
+ mail (~> 2.2)
6
+ rspec (~> 2.0)
6
7
 
7
8
  GEM
8
9
  remote: http://gemcutter.org/
@@ -93,17 +94,16 @@ GEM
93
94
  rake (>= 0.8.3)
94
95
  thor (~> 0.14.0)
95
96
  rake (0.8.7)
96
- rspec (2.0.0.beta.19)
97
- rspec-core (= 2.0.0.beta.19)
98
- rspec-expectations (= 2.0.0.beta.19)
99
- rspec-mocks (= 2.0.0.beta.19)
100
- rspec-core (2.0.0.beta.19)
101
- rspec-expectations (2.0.0.beta.19)
102
- diff-lcs (>= 1.1.2)
103
- rspec-mocks (2.0.0.beta.19)
104
- rspec-rails (2.0.0.beta.19)
105
- rspec (= 2.0.0.beta.19)
106
- webrat (>= 0.7.2.beta.1)
97
+ rspec (2.1.0)
98
+ rspec-core (~> 2.1.0)
99
+ rspec-expectations (~> 2.1.0)
100
+ rspec-mocks (~> 2.1.0)
101
+ rspec-core (2.1.0)
102
+ rspec-expectations (2.1.0)
103
+ diff-lcs (~> 1.1.2)
104
+ rspec-mocks (2.1.0)
105
+ rspec-rails (2.1.0)
106
+ rspec (~> 2.1.0)
107
107
  rubyzip (0.9.4)
108
108
  selenium-webdriver (0.0.27)
109
109
  ffi (>= 0.6.1)
@@ -117,10 +117,6 @@ GEM
117
117
  polyglot (>= 0.3.1)
118
118
  trollop (1.16.2)
119
119
  tzinfo (0.3.22)
120
- webrat (0.7.2.beta.1)
121
- nokogiri (>= 1.2.0)
122
- rack (>= 1.0)
123
- rack-test (>= 0.5.3)
124
120
 
125
121
  PLATFORMS
126
122
  ruby
@@ -133,7 +129,7 @@ DEPENDENCIES
133
129
  email_spec!
134
130
  mimetype-fu
135
131
  rails (= 3.0.0.rc)
136
- rspec (>= 2.0.0.beta.19)
137
- rspec-rails (>= 2.0.0.beta.19)
132
+ rspec (>= 2.0.1)
133
+ rspec-rails (>= 2.0.1)
138
134
  sqlite3-ruby
139
135
  test-unit
@@ -12,4 +12,5 @@ require 'email_spec/address_converter'
12
12
  require 'email_spec/email_viewer'
13
13
  require 'email_spec/helpers'
14
14
  require 'email_spec/matchers'
15
- require 'email_spec/mail_ext'
15
+ require 'email_spec/mail_ext'
16
+ require 'email_spec/test_observer'
@@ -3,7 +3,7 @@
3
3
  # Global Setup
4
4
  if defined?(ActionMailer)
5
5
  unless [:test, :activerecord, :cache, :file].include?(ActionMailer::Base.delivery_method)
6
- ActionMailer::Base.delivery_method = :test
6
+ ActionMailer::Base.register_observer(EmailSpec::TestObserver)
7
7
  end
8
8
  ActionMailer::Base.perform_deliveries = true
9
9
 
@@ -9,7 +9,7 @@ module EmailSpec
9
9
  end
10
10
 
11
11
  def reset_mailer
12
- if ActionMailer::Base.delivery_method == :cache
12
+ if defined?(ActionMailer) && ActionMailer::Base.delivery_method == :cache
13
13
  mailer.clear_cache
14
14
  else
15
15
  deliveries.clear
@@ -57,9 +57,9 @@ module EmailSpec
57
57
  def find_email(address, opts={})
58
58
  address = convert_address(address)
59
59
  if opts[:with_subject]
60
- mailbox_for(address).find { |m| m.subject =~ Regexp.new(opts[:with_subject]) }
60
+ mailbox_for(address).find { |m| m.subject =~ Regexp.new(Regexp.escape(opts[:with_subject])) }
61
61
  elsif opts[:with_text]
62
- mailbox_for(address).find { |m| m.default_part_body =~ Regexp.new(opts[:with_text]) }
62
+ mailbox_for(address).find { |m| m.default_part_body =~ Regexp.new(Regexp.escape(opts[:with_text])) }
63
63
  else
64
64
  mailbox_for(address).first
65
65
  end
@@ -148,6 +148,12 @@ module EmailSpec
148
148
  AddressConverter.instance.convert(@last_email_address)
149
149
  end
150
150
 
151
+ # Overwrite this method to set default email address, for example:
152
+ # last_email_address || @current_user.email
153
+ def current_email_address
154
+ last_email_address
155
+ end
156
+
151
157
 
152
158
  def mailbox_for(address)
153
159
  super(convert_address(address)) # super resides in Deliveries
@@ -37,25 +37,25 @@ module EmailSpec
37
37
  email_or_object.kind_of?(String) ? email_or_object : email_or_object.email
38
38
  end
39
39
 
40
- @expected_email_addresses = emails.sort
40
+ @expected_recipients = Mail::ToField.new(emails).addrs.map(&:to_s).sort
41
41
  end
42
42
 
43
43
  def description
44
- "be delivered to #{@expected_email_addresses.inspect}"
44
+ "be delivered to #{@expected_recipients.inspect}"
45
45
  end
46
46
 
47
47
  def matches?(email)
48
48
  @email = email
49
- @actual_recipients = (Array(email.to) || []).sort
50
- @actual_recipients == @expected_email_addresses
49
+ @actual_recipients = (email.header[:to].addrs || []).map(&:to_s).sort
50
+ @actual_recipients == @expected_recipients
51
51
  end
52
52
 
53
53
  def failure_message
54
- "expected #{@email.inspect} to deliver to #{@expected_email_addresses.inspect}, but it delivered to #{@actual_recipients.inspect}"
54
+ "expected #{@email.inspect} to deliver to #{@expected_recipients.inspect}, but it delivered to #{@actual_recipients.inspect}"
55
55
  end
56
56
 
57
57
  def negative_failure_message
58
- "expected #{@email.inspect} not to deliver to #{@expected_email_addresses.inspect}, but it did"
58
+ "expected #{@email.inspect} not to deliver to #{@expected_recipients.inspect}, but it did"
59
59
  end
60
60
  end
61
61
 
@@ -80,8 +80,7 @@ module EmailSpec
80
80
  @actual_sender = (email.header[:from].addrs || []).first
81
81
 
82
82
  !@actual_sender.nil? &&
83
- @actual_sender.address == @expected_sender.address &&
84
- @actual_sender.display_name == @expected_sender.display_name
83
+ @actual_sender.to_s == @expected_sender.to_s
85
84
  end
86
85
 
87
86
  def failure_message
@@ -132,6 +131,39 @@ module EmailSpec
132
131
  BccTo.new(expected_email_addresses_or_objects_that_respond_to_email.flatten)
133
132
  end
134
133
 
134
+ class CcTo
135
+
136
+ def initialize(expected_email_addresses_or_objects_that_respond_to_email)
137
+ emails = expected_email_addresses_or_objects_that_respond_to_email.map do |email_or_object|
138
+ email_or_object.kind_of?(String) ? email_or_object : email_or_object.email
139
+ end
140
+
141
+ @expected_email_addresses = emails.sort
142
+ end
143
+
144
+ def description
145
+ "be cc'd to #{@expected_email_addresses.inspect}"
146
+ end
147
+
148
+ def matches?(email)
149
+ @email = email
150
+ @actual_recipients = (Array(email.cc) || []).sort
151
+ @actual_recipients == @expected_email_addresses
152
+ end
153
+
154
+ def failure_message
155
+ "expected #{@email.inspect} to cc to #{@expected_email_addresses.inspect}, but it was cc'd to #{@actual_recipients.inspect}"
156
+ end
157
+
158
+ def negative_failure_message
159
+ "expected #{@email.inspect} not to cc to #{@expected_email_addresses.inspect}, but it did"
160
+ end
161
+ end
162
+
163
+ def cc_to(*expected_email_addresses_or_objects_that_respond_to_email)
164
+ CcTo.new(expected_email_addresses_or_objects_that_respond_to_email.flatten)
165
+ end
166
+
135
167
  RSpec::Matchers.define :have_subject do
136
168
  match do |given|
137
169
  given_subject = given.subject
@@ -0,0 +1,7 @@
1
+ module EmailSpec
2
+ class TestObserver
3
+ def self.delivered_email(message)
4
+ ActionMailer::Base.deliveries << message
5
+ end
6
+ end
7
+ end
@@ -57,7 +57,7 @@ Then /^(?:I|they|"([^"]*?)") should have (an|no|\d+) emails?$/ do |address, amou
57
57
  end
58
58
 
59
59
  Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails? with subject "([^"]*?)"$/ do |address, amount, subject|
60
- unread_emails_for(address).select { |m| m.subject =~ Regexp.new(subject) }.size.should == parse_email_count(amount)
60
+ unread_emails_for(address).select { |m| m.subject =~ Regexp.new(Regexp.escape(subject)) }.size.should == parse_email_count(amount)
61
61
  end
62
62
 
63
63
  Then /^(?:I|they|"([^"]*?)") should receive an email with the following body:$/ do |address, expected_body|
@@ -48,19 +48,19 @@ end
48
48
  # Check how many emails have been sent/received
49
49
  #
50
50
 
51
- Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails?$/ do |address, amount|
51
+ Then /^(?:I|they|he|she|"([^"]*?)") should receive (an|no|\d+) emails?$/ do |address, amount|
52
52
  unread_emails_for(address).size.should == parse_email_count(amount)
53
53
  end
54
54
 
55
- Then /^(?:I|they|"([^"]*?)") should have (an|no|\d+) emails?$/ do |address, amount|
55
+ Then /^(?:I|they|he|she|"([^"]*?)") should have (an|no|\d+) emails?$/ do |address, amount|
56
56
  mailbox_for(address).size.should == parse_email_count(amount)
57
57
  end
58
58
 
59
- Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails? with subject "([^"]*?)"$/ do |address, amount, subject|
59
+ Then /^(?:I|they|he|she|"([^"]*?)") should receive (an|no|\d+) emails? with subject "([^"]*?)"$/ do |address, amount, subject|
60
60
  unread_emails_for(address).select { |m| m.subject =~ Regexp.new(Regexp.escape(subject)) }.size.should == parse_email_count(amount)
61
61
  end
62
62
 
63
- Then /^(?:I|they|"([^"]*?)") should receive an email with the following body:$/ do |address, expected_body|
63
+ Then /^(?:I|they|he|she|"([^"]*?)") should receive an email with the following body:$/ do |address, expected_body|
64
64
  open_email(address, :with_text => expected_body)
65
65
  end
66
66
 
@@ -69,15 +69,15 @@ end
69
69
  #
70
70
 
71
71
  # Opens the most recently received email
72
- When /^(?:I|they|"([^"]*?)") opens? the email$/ do |address|
72
+ When /^(?:I|they|he|she|"([^"]*?)") opens? the email$/ do |address|
73
73
  open_email(address)
74
74
  end
75
75
 
76
- When /^(?:I|they|"([^"]*?)") opens? the email with subject "([^"]*?)"$/ do |address, subject|
76
+ When /^(?:I|they|he|she|"([^"]*?)") opens? the email with subject "([^"]*?)"$/ do |address, subject|
77
77
  open_email(address, :with_subject => subject)
78
78
  end
79
79
 
80
- When /^(?:I|they|"([^"]*?)") opens? the email with text "([^"]*?)"$/ do |address, text|
80
+ When /^(?:I|they|he|she|"([^"]*?)") opens? the email with text "([^"]*?)"$/ do |address, text|
81
81
  open_email(address, :with_text => text)
82
82
  end
83
83
 
@@ -85,31 +85,44 @@ end
85
85
  # Inspect the Email Contents
86
86
  #
87
87
 
88
- Then /^(?:I|they) should see "([^"]*?)" in the email subject$/ do |text|
88
+ Then /^(?:I|they|he|she) should see "([^"]*?)" in the email subject$/ do |text|
89
89
  current_email.should have_subject(text)
90
90
  end
91
91
 
92
- Then /^(?:I|they) should see \/([^"]*?)\/ in the email subject$/ do |text|
93
- current_email.should have_subject(Regexp.new(text))
92
+ Then /^(?:I|they|he|she) should see "([^"]*?)" in the email body$/ do |text|
93
+ if current_email.multipart?
94
+ Then %(I should see "#{text}" in the html part of the email body)
95
+ Then %(I should see "#{text}" in the text part of the email body)
96
+ else
97
+ current_email.body.should =~ Regexp.new(text)
98
+ end
99
+ end
100
+
101
+ Then /^(?:I|they|he|she) should see "([^"]*?)" in the html part of the email body$/ do |text|
102
+ current_email.html_part.body.should =~ Regexp.new(text)
103
+ end
104
+
105
+ Then /^(?:I|they|he|she) should see "([^"]*?)" in the text part of the email body$/ do |text|
106
+ current_email.text_part.body.should =~ Regexp.new(text)
94
107
  end
95
108
 
96
- Then /^(?:I|they) should see "([^"]*?)" in the email body$/ do |text|
109
+ Then /^(?:I|they|he|she) should see "([^"]*?)" in the email body$/ do |text|
97
110
  current_email.body.should include(text)
98
111
  end
99
112
 
100
- Then /^(?:I|they) should see \/([^"]*?)\/ in the email body$/ do |text|
113
+ Then /^(?:I|they|he|she) should see \/([^"]*?)\/ in the email body$/ do |text|
101
114
  current_email.body.should =~ Regexp.new(text)
102
115
  end
103
116
 
104
- Then /^(?:I|they) should see the email delivered from "([^"]*?)"$/ do |text|
117
+ Then /^(?:I|they|he|she) should see the email delivered from "([^"]*?)"$/ do |text|
105
118
  current_email.should be_delivered_from(text)
106
119
  end
107
120
 
108
- Then /^(?:I|they) should see "([^\"]*)" in the email "([^"]*?)" header$/ do |text, name|
121
+ Then /^(?:I|they|he|she) should see "([^\"]*)" in the email "([^"]*?)" header$/ do |text, name|
109
122
  current_email.should have_header(name, text)
110
123
  end
111
124
 
112
- Then /^(?:I|they) should see \/([^\"]*)\/ in the email "([^"]*?)" header$/ do |text, name|
125
+ Then /^(?:I|they|he|she) should see \/([^\"]*)\/ in the email "([^"]*?)" header$/ do |text, name|
113
126
  current_email.should have_header(name, Regexp.new(text))
114
127
  end
115
128
 
@@ -117,7 +130,7 @@ end
117
130
  # Inspect the Email Attachments
118
131
  #
119
132
 
120
- Then /^(?:I|they) should see (an|no|\d+) attachments? with the email$/ do |amount|
133
+ Then /^(?:I|they|he|she) should see (an|no|\d+) attachments? with the email$/ do |amount|
121
134
  current_email_attachments.size.should == parse_email_count(amount)
122
135
  end
123
136
 
@@ -151,11 +164,11 @@ end
151
164
  # Interact with Email Contents
152
165
  #
153
166
 
154
- When /^(?:I|they) follow "([^"]*?)" in the email$/ do |link|
167
+ When /^(?:I|they|he|she) follow "([^"]*?)" in the email$/ do |link|
155
168
  visit_in_email(link)
156
169
  end
157
170
 
158
- When /^(?:I|they) click the first link in the email$/ do
171
+ When /^(?:I|they|he|she) click the first link in the email$/ do
159
172
  click_first_link_in_email
160
173
  end
161
174
 
@@ -133,4 +133,68 @@ describe EmailSpec::Helpers do
133
133
  it_should_behave_like 'something that sets the current email for recipients'
134
134
  end
135
135
  end
136
+
137
+ describe '#open_email' do
138
+ describe 'with subject' do
139
+ shared_examples_for 'something that opens the email with subject' do
140
+ before do
141
+ @to = "jimmy_bean@yahoo.com"
142
+ @email = Mail::Message.new(:to => @to, :subject => @subject)
143
+ stub!(:mailbox_for).with(@to).and_return([@email])
144
+ end
145
+
146
+ it "should open the email with subject" do
147
+ open_email(@to, :with_subject => @subject).should == @email
148
+ end
149
+ end
150
+
151
+ describe 'simple subject' do
152
+ before do
153
+ @subject = 'This is a simple subject'
154
+ end
155
+
156
+ it_should_behave_like 'something that opens the email with subject'
157
+ end
158
+
159
+ describe 'with regex sensitive characters' do
160
+ before do
161
+ @subject = '[app name] Contains regex characters?'
162
+ end
163
+
164
+ it_should_behave_like 'something that opens the email with subject'
165
+ end
166
+ end
167
+
168
+ describe 'with text' do
169
+ shared_examples_for 'something that opens the email with text' do
170
+ before do
171
+ @to = "jimmy_bean@yahoo.com"
172
+ @email = Mail::Message.new(:to => @to, :body => @body)
173
+ stub!(:mailbox_for).with(@to).and_return([@email])
174
+ end
175
+
176
+ it "should open the email with text" do
177
+ open_email(@to, :with_text => @text).should == @email
178
+ end
179
+ end
180
+
181
+ describe 'simple text' do
182
+ before do
183
+ @body = 'This is an email body that is very simple'
184
+ @text = 'email body'
185
+ end
186
+
187
+ it_should_behave_like 'something that opens the email with text'
188
+ end
189
+
190
+ describe 'with regex sensitive characters' do
191
+ before do
192
+ @body = 'This is an email body. It contains some [regex] characters?'
193
+ @text = '[regex] characters?'
194
+ end
195
+
196
+ it_should_behave_like 'something that opens the email with text'
197
+ end
198
+ end
199
+ end
136
200
  end
@@ -54,12 +54,17 @@ describe EmailSpec::Matchers do
54
54
  end
55
55
 
56
56
  describe "#deliver_to" do
57
- it "should match when the email is set to deliver to the specidied address" do
57
+ it "should match when the email is set to deliver to the specified address" do
58
58
  email = Mail::Message.new(:to => "jimmy_bean@yahoo.com")
59
59
 
60
60
  deliver_to("jimmy_bean@yahoo.com").should match(email)
61
61
  end
62
62
 
63
+ it "should match when the email is set to deliver to the specified name and address" do
64
+ email = Mail::Message.new(:to => "Jimmy Bean <jimmy_bean@yahoo.com>")
65
+ deliver_to("Jimmy Bean <jimmy_bean@yahoo.com>").should match(email)
66
+ end
67
+
63
68
  it "should match when a list of emails is exact same as all of the email's recipients" do
64
69
  email = Mail::Message.new(:to => ["james@yahoo.com", "karen@yahoo.com"])
65
70
 
@@ -72,6 +77,12 @@ describe EmailSpec::Matchers do
72
77
  email = Mail::Message.new(:to => addresses)
73
78
  deliver_to(addresses).should match(email)
74
79
  end
80
+
81
+ it "should match when the names and email addresses match in any order" do
82
+ addresses = ["James <james@yahoo.com>", "Karen <karen@yahoo.com>"]
83
+ email = Mail::Message.new(:to => addresses.reverse)
84
+ deliver_to(addresses).should match(email)
85
+ end
75
86
 
76
87
  it "should use the passed in objects :email method if not a string" do
77
88
  email = Mail::Message.new(:to => "jimmy_bean@yahoo.com")
@@ -80,6 +91,21 @@ describe EmailSpec::Matchers do
80
91
  deliver_to(user).should match(email)
81
92
  end
82
93
 
94
+ it "should not match when the email does not have a recipient" do
95
+ email = Mail::Message.new(:to => nil)
96
+ deliver_to("jimmy_bean@yahoo.com").should_not match(email)
97
+ end
98
+
99
+ it "should not match when the email addresses match but the names do not" do
100
+ email = Mail::Message.new(:to => "Jimmy Bean <jimmy_bean@yahoo.com>")
101
+ deliver_to("Freddy Noe <jimmy_bean@yahoo.com>").should_not match(email)
102
+ end
103
+
104
+ it "should not match when the names match but the email addresses do not" do
105
+ email = Mail::Message.new(:to => "Jimmy Bean <jimmy_bean@yahoo.com>")
106
+ deliver_to("Jimmy Bean <freddy_noe@yahoo.com>").should_not match(email)
107
+ end
108
+
83
109
  it "should give correct failure message when the email is not set to deliver to the specified address" do
84
110
  matcher = deliver_to("jimmy_bean@yahoo.com")
85
111
  message = Mail::Message.new(:to => 'freddy_noe@yahoo.com')
@@ -159,6 +185,36 @@ describe EmailSpec::Matchers do
159
185
 
160
186
  end
161
187
 
188
+ describe "#cc_to" do
189
+
190
+ it "should match when the email is set to deliver to the specified address" do
191
+ email = Mail::Message.new(:cc => "jimmy_bean@yahoo.com")
192
+
193
+ cc_to("jimmy_bean@yahoo.com").should match(email)
194
+ end
195
+
196
+ it "should match when a list of emails is exact same as all of the email's recipients" do
197
+ email = Mail::Message.new(:cc => ["james@yahoo.com", "karen@yahoo.com"])
198
+
199
+ cc_to("karen@yahoo.com", "james@yahoo.com").should match(email)
200
+ cc_to("karen@yahoo.com").should_not match(email)
201
+ end
202
+
203
+ it "should match when an array of emails is exact same as all of the email's recipients" do
204
+ addresses = ["james@yahoo.com", "karen@yahoo.com"]
205
+ email = Mail::Message.new(:cc => addresses)
206
+ cc_to(addresses).should match(email)
207
+ end
208
+
209
+ it "should use the passed in objects :email method if not a string" do
210
+ email = Mail::Message.new(:cc => "jimmy_bean@yahoo.com")
211
+ user = mock("user", :email => "jimmy_bean@yahoo.com")
212
+
213
+ cc_to(user).should match(email)
214
+ end
215
+
216
+ end
217
+
162
218
  describe "#have_subject" do
163
219
 
164
220
  describe "when regexps are used" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: email_spec
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 1
9
- - 1
10
- version: 1.1.1
8
+ - 2
9
+ - 0
10
+ version: 1.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ben Mabey
@@ -17,13 +17,29 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-12-29 00:00:00 -07:00
20
+ date: 2011-06-16 00:00:00 -06:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
24
- name: rspec
24
+ type: :runtime
25
+ prerelease: false
26
+ name: mail
27
+ version_requirements: &id001 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ hash: 7
33
+ segments:
34
+ - 2
35
+ - 2
36
+ version: "2.2"
37
+ requirement: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ type: :runtime
25
40
  prerelease: false
26
- requirement: &id001 !ruby/object:Gem::Requirement
41
+ name: rspec
42
+ version_requirements: &id002 !ruby/object:Gem::Requirement
27
43
  none: false
28
44
  requirements:
29
45
  - - ~>
@@ -33,8 +49,7 @@ dependencies:
33
49
  - 2
34
50
  - 0
35
51
  version: "2.0"
36
- type: :runtime
37
- version_requirements: *id001
52
+ requirement: *id002
38
53
  description: Easily test email in rspec and cucumber
39
54
  email: ben@benmabey.com
40
55
  executables: []
@@ -60,6 +75,7 @@ files:
60
75
  - lib/email_spec/helpers.rb
61
76
  - lib/email_spec/mail_ext.rb
62
77
  - lib/email_spec/matchers.rb
78
+ - lib/email_spec/test_observer.rb
63
79
  - lib/generators/email_spec/steps/USAGE
64
80
  - lib/generators/email_spec/steps/steps_generator.rb
65
81
  - lib/generators/email_spec/steps/templates/email_steps.rb