shoulda-matchers 1.4.2 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. data/.travis.yml +11 -3
  2. data/Appraisals +3 -3
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +69 -70
  5. data/MIT-LICENSE +1 -1
  6. data/NEWS.md +22 -4
  7. data/README.md +3 -1
  8. data/Rakefile +9 -5
  9. data/features/step_definitions/rails_steps.rb +7 -7
  10. data/features/support/env.rb +1 -1
  11. data/gemfiles/3.0.gemfile +1 -1
  12. data/gemfiles/3.0.gemfile.lock +25 -22
  13. data/gemfiles/3.1.gemfile +1 -1
  14. data/gemfiles/3.1.gemfile.lock +27 -24
  15. data/gemfiles/3.2.gemfile +1 -1
  16. data/gemfiles/3.2.gemfile.lock +56 -52
  17. data/lib/shoulda/matchers/action_controller.rb +3 -2
  18. data/lib/shoulda/matchers/action_controller/assign_to_matcher.rb +10 -8
  19. data/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +2 -4
  20. data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +3 -4
  21. data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +3 -4
  22. data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +6 -6
  23. data/lib/shoulda/matchers/action_controller/respond_with_content_type_matcher.rb +5 -2
  24. data/lib/shoulda/matchers/action_controller/respond_with_matcher.rb +2 -2
  25. data/lib/shoulda/matchers/action_controller/route_matcher.rb +12 -12
  26. data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +3 -4
  27. data/lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb +10 -11
  28. data/lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb +121 -0
  29. data/lib/shoulda/matchers/action_mailer/have_sent_email_matcher.rb +7 -4
  30. data/lib/shoulda/matchers/active_model.rb +1 -1
  31. data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +8 -8
  32. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +5 -4
  33. data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +3 -3
  34. data/lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb +2 -2
  35. data/lib/shoulda/matchers/active_model/exception_message_finder.rb +0 -1
  36. data/lib/shoulda/matchers/active_model/helpers.rb +16 -7
  37. data/lib/shoulda/matchers/active_model/only_integer_matcher.rb +3 -3
  38. data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +8 -6
  39. data/lib/shoulda/matchers/active_model/validate_format_of_matcher.rb +19 -10
  40. data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +4 -4
  41. data/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb +19 -21
  42. data/lib/shoulda/matchers/active_model/validation_matcher.rb +7 -7
  43. data/lib/shoulda/matchers/active_model/validation_message_finder.rb +1 -1
  44. data/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +5 -5
  45. data/lib/shoulda/matchers/active_record/association_matcher.rb +3 -3
  46. data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +11 -7
  47. data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +2 -2
  48. data/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +5 -5
  49. data/lib/shoulda/matchers/active_record/query_the_database_matcher.rb +5 -2
  50. data/lib/shoulda/matchers/active_record/serialize_matcher.rb +3 -3
  51. data/lib/shoulda/matchers/assertion_error.rb +4 -1
  52. data/lib/shoulda/matchers/independent/delegate_matcher.rb +17 -7
  53. data/lib/shoulda/matchers/integrations/rspec.rb +19 -33
  54. data/lib/shoulda/matchers/version.rb +1 -1
  55. data/shoulda-matchers.gemspec +6 -4
  56. data/spec/shoulda/matchers/action_controller/assign_to_matcher_spec.rb +66 -0
  57. data/spec/shoulda/matchers/action_controller/filter_param_matcher_spec.rb +22 -0
  58. data/spec/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb +42 -0
  59. data/spec/shoulda/matchers/action_controller/render_template_matcher_spec.rb +78 -0
  60. data/spec/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +58 -0
  61. data/spec/shoulda/matchers/action_controller/respond_with_content_type_matcher_spec.rb +31 -0
  62. data/spec/shoulda/matchers/action_controller/respond_with_matcher_spec.rb +31 -0
  63. data/spec/shoulda/matchers/action_controller/route_matcher_spec.rb +65 -0
  64. data/spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb +51 -0
  65. data/spec/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb +153 -0
  66. data/spec/shoulda/matchers/action_controller/strong_parameters_matcher_spec.rb +142 -0
  67. data/spec/shoulda/matchers/action_mailer/have_sent_email_spec.rb +324 -0
  68. data/spec/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +111 -0
  69. data/spec/shoulda/matchers/active_model/allow_value_matcher_spec.rb +124 -0
  70. data/spec/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +43 -0
  71. data/spec/shoulda/matchers/active_model/ensure_exclusion_of_matcher_spec.rb +74 -0
  72. data/spec/shoulda/matchers/active_model/ensure_inclusion_of_matcher_spec.rb +171 -0
  73. data/spec/shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb +113 -0
  74. data/spec/shoulda/{active_model → matchers/active_model}/exception_message_finder_spec.rb +2 -2
  75. data/spec/shoulda/matchers/active_model/helpers_spec.rb +158 -0
  76. data/spec/shoulda/matchers/active_model/only_integer_matcher_spec.rb +52 -0
  77. data/spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +41 -0
  78. data/spec/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +41 -0
  79. data/spec/shoulda/matchers/active_model/validate_format_of_matcher_spec.rb +75 -0
  80. data/spec/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +73 -0
  81. data/spec/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +127 -0
  82. data/spec/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +175 -0
  83. data/spec/shoulda/{active_model → matchers/active_model}/validation_message_finder_spec.rb +0 -1
  84. data/spec/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +106 -0
  85. data/spec/shoulda/matchers/active_record/association_matcher_spec.rb +534 -0
  86. data/spec/shoulda/matchers/active_record/have_db_column_matcher_spec.rb +111 -0
  87. data/spec/shoulda/matchers/active_record/have_db_index_matcher_spec.rb +78 -0
  88. data/spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb +41 -0
  89. data/spec/shoulda/{active_record → matchers/active_record}/query_the_database_matcher_spec.rb +10 -10
  90. data/spec/shoulda/matchers/active_record/serialize_matcher_spec.rb +86 -0
  91. data/spec/shoulda/{independent → matchers/independent}/delegate_matcher_spec.rb +55 -34
  92. data/spec/spec_helper.rb +1 -2
  93. data/spec/support/active_model_versions.rb +4 -0
  94. data/spec/support/activemodel_helpers.rb +19 -0
  95. data/spec/support/controller_builder.rb +38 -12
  96. data/spec/support/model_builder.rb +8 -2
  97. metadata +106 -98
  98. data/spec/fixtures/addresses.yml +0 -3
  99. data/spec/fixtures/friendships.yml +0 -0
  100. data/spec/fixtures/posts.yml +0 -5
  101. data/spec/fixtures/products.yml +0 -0
  102. data/spec/fixtures/taggings.yml +0 -0
  103. data/spec/fixtures/tags.yml +0 -9
  104. data/spec/fixtures/users.yml +0 -6
  105. data/spec/shoulda/action_controller/assign_to_matcher_spec.rb +0 -63
  106. data/spec/shoulda/action_controller/filter_param_matcher_spec.rb +0 -20
  107. data/spec/shoulda/action_controller/redirect_to_matcher_spec.rb +0 -40
  108. data/spec/shoulda/action_controller/render_template_matcher_spec.rb +0 -69
  109. data/spec/shoulda/action_controller/render_with_layout_matcher_spec.rb +0 -55
  110. data/spec/shoulda/action_controller/respond_with_content_type_matcher_spec.rb +0 -28
  111. data/spec/shoulda/action_controller/respond_with_matcher_spec.rb +0 -83
  112. data/spec/shoulda/action_controller/route_matcher_spec.rb +0 -65
  113. data/spec/shoulda/action_controller/set_session_matcher_spec.rb +0 -46
  114. data/spec/shoulda/action_controller/set_the_flash_matcher_spec.rb +0 -130
  115. data/spec/shoulda/action_mailer/have_sent_email_spec.rb +0 -333
  116. data/spec/shoulda/active_model/allow_mass_assignment_of_matcher_spec.rb +0 -115
  117. data/spec/shoulda/active_model/allow_value_matcher_spec.rb +0 -131
  118. data/spec/shoulda/active_model/disallow_value_matcher_spec.rb +0 -65
  119. data/spec/shoulda/active_model/ensure_exclusion_of_matcher_spec.rb +0 -79
  120. data/spec/shoulda/active_model/ensure_inclusion_of_matcher_spec.rb +0 -181
  121. data/spec/shoulda/active_model/ensure_length_of_matcher_spec.rb +0 -138
  122. data/spec/shoulda/active_model/helpers_spec.rb +0 -129
  123. data/spec/shoulda/active_model/only_integer_matcher_spec.rb +0 -69
  124. data/spec/shoulda/active_model/validate_acceptance_of_matcher_spec.rb +0 -43
  125. data/spec/shoulda/active_model/validate_confirmation_of_matcher_spec.rb +0 -48
  126. data/spec/shoulda/active_model/validate_format_of_matcher_spec.rb +0 -79
  127. data/spec/shoulda/active_model/validate_numericality_of_matcher_spec.rb +0 -112
  128. data/spec/shoulda/active_model/validate_presence_of_matcher_spec.rb +0 -135
  129. data/spec/shoulda/active_model/validate_uniqueness_of_matcher_spec.rb +0 -154
  130. data/spec/shoulda/active_record/accept_nested_attributes_for_matcher_spec.rb +0 -84
  131. data/spec/shoulda/active_record/association_matcher_spec.rb +0 -642
  132. data/spec/shoulda/active_record/have_db_column_matcher_spec.rb +0 -185
  133. data/spec/shoulda/active_record/have_db_index_matcher_spec.rb +0 -105
  134. data/spec/shoulda/active_record/have_readonly_attributes_matcher_spec.rb +0 -46
  135. data/spec/shoulda/active_record/serialize_matcher_spec.rb +0 -81
@@ -1,46 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Shoulda::Matchers::ActionController::SetSessionMatcher do
4
- context "a controller that sets a session variable" do
5
- let(:controller) do
6
- build_response do
7
- session[:var] = 'value'
8
- session[:false_var] = false
9
- end
10
- end
11
-
12
- it "should accept assigning to that variable" do
13
- controller.should set_session(:var)
14
- end
15
-
16
- it "should accept assigning the correct value to that variable" do
17
- controller.should set_session(:var).to('value')
18
- end
19
-
20
- it "should reject assigning another value to that variable" do
21
- controller.should_not set_session(:var).to('other')
22
- end
23
-
24
- it "should reject assigning to another variable" do
25
- controller.should_not set_session(:other)
26
- end
27
-
28
- it "should accept assigning nil to another variable" do
29
- controller.should set_session(:other).to(nil)
30
- end
31
-
32
- it "should accept assigning false to that variable" do
33
- controller.should set_session(:false_var).to(false)
34
- end
35
-
36
- it "should accept assigning to the same value in the test context" do
37
- expected = 'value'
38
- controller.should set_session(:var).in_context(self).to { expected }
39
- end
40
-
41
- it "should reject assigning to the another value in the test context" do
42
- expected = 'other'
43
- controller.should_not set_session(:var).in_context(self).to { expected }
44
- end
45
- end
46
- end
@@ -1,130 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Shoulda::Matchers::ActionController::SetTheFlashMatcher do
4
- it "should fail with unmatchable to" do
5
- expect{
6
- set_the_flash.to(1).should
7
- }.to raise_error("cannot match against 1")
8
- end
9
-
10
- context "a controller that sets a flash message" do
11
- let(:controller) { build_response { flash[:notice] = 'value' } }
12
-
13
- it "should accept setting any flash message" do
14
- controller.should set_the_flash
15
- end
16
-
17
- it "should accept setting the exact flash message" do
18
- controller.should set_the_flash.to('value')
19
- end
20
-
21
- it "should accept setting a matched flash message" do
22
- controller.should set_the_flash.to(/value/)
23
- end
24
-
25
- it "should reject setting a different flash message" do
26
- controller.should_not set_the_flash.to('other')
27
- end
28
-
29
- it "should reject setting a different pattern" do
30
- controller.should_not set_the_flash.to(/other/)
31
- end
32
- end
33
-
34
- context "a controller that sets a flash.now message" do
35
- let(:controller) { build_response { flash.now[:notice] = 'value' } }
36
-
37
- it "should reject setting any flash message" do
38
- controller.should_not set_the_flash
39
- end
40
-
41
- it "should accept setting any flash.now message" do
42
- controller.should set_the_flash.now
43
- end
44
-
45
- it "should accept setting the exact flash.now message" do
46
- controller.should set_the_flash.to('value').now
47
- end
48
-
49
- it "should accept setting a matched flash.now message" do
50
- controller.should set_the_flash.to(/value/).now
51
- end
52
-
53
- it "should reject setting a different flash.now message" do
54
- controller.should_not set_the_flash.to('other').now
55
- end
56
-
57
- it "should reject setting a different flash.now pattern" do
58
- controller.should_not set_the_flash.to(/other/).now
59
- end
60
- end
61
-
62
- context "a controller that sets a flash message of notice and alert" do
63
- let(:controller) do
64
- build_response do
65
- flash[:notice] = 'value'
66
- flash[:alert] = 'other'
67
- end
68
- end
69
-
70
- it "should accept flash message of notice" do
71
- controller.should set_the_flash[:notice]
72
- end
73
-
74
- it "should accept flash message of alert" do
75
- controller.should set_the_flash[:notice]
76
- end
77
-
78
- it "should reject flash message of warning" do
79
- controller.should_not set_the_flash[:warning]
80
- end
81
-
82
- it "should accept exact flash message of notice" do
83
- controller.should set_the_flash[:notice].to('value')
84
- end
85
-
86
- it "should accept setting a matched flash message of notice" do
87
- controller.should set_the_flash[:notice].to(/value/)
88
- end
89
-
90
- it "should reject setting a different flash message of notice" do
91
- controller.should_not set_the_flash[:notice].to('other')
92
- end
93
-
94
- it "should reject setting a different pattern" do
95
- controller.should_not set_the_flash[:notice].to(/other/)
96
- end
97
- end
98
-
99
- context "a controller that sets multiple flash messages" do
100
- let(:controller) do
101
- build_response do
102
- flash.now[:notice] = 'value'
103
- flash[:success] = 'great job'
104
- end
105
- end
106
-
107
- it "should accept setting any flash.now message" do
108
- controller.should set_the_flash.now
109
- controller.should set_the_flash
110
- end
111
-
112
- it "should accept setting a matched flash.now message" do
113
- controller.should set_the_flash.to(/value/).now
114
- controller.should set_the_flash.to(/great/)
115
- end
116
-
117
- it "should reject setting a different flash.now message" do
118
- controller.should_not set_the_flash.to('other').now
119
- controller.should_not set_the_flash.to('other')
120
- end
121
- end
122
-
123
- context "a controller that doesn't set a flash message" do
124
- let(:controller) { build_response }
125
-
126
- it "should reject setting any flash message" do
127
- controller.should_not set_the_flash
128
- end
129
- end
130
- end
@@ -1,333 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Shoulda::Matchers::ActionMailer::HaveSentEmailMatcher do
4
- subject { Shoulda::Matchers::ActionMailer::HaveSentEmailMatcher.new(self) }
5
-
6
- def add_mail_to_deliveries(params = nil)
7
- ::ActionMailer::Base.deliveries << Mailer.the_email(params)
8
- end
9
-
10
- context "testing with instance variables with no multipart" do
11
- let(:info) do
12
- {
13
- :from => "do-not-reply@example.com",
14
- :reply_to => "reply-to-me@example.com",
15
- :to => "myself@me.com",
16
- :cc => ["you@you.com", "joe@bob.com", "hello@goodbye.com"],
17
- :bcc => ["test@example.com", "sam@bob.com", "goodbye@hello.com"],
18
- :subject => "This is spam",
19
- :body => "Every email is spam."
20
- }
21
- end
22
-
23
- before do
24
- define_mailer(:mailer, [:the_email]) do
25
- def the_email(params)
26
- mail params
27
- end
28
- end
29
- add_mail_to_deliveries(info)
30
- end
31
-
32
- after { ::ActionMailer::Base.deliveries.clear }
33
-
34
- it "should send an e-mail based on subject" do
35
- should have_sent_email.with_subject{ info[:subject] }
36
- end
37
-
38
- it "should send an e-mail based on recipient" do
39
- should have_sent_email.to(nil) { info[:to] }
40
- end
41
-
42
- it "should send an e-mail based on sender" do
43
- should have_sent_email.from{ info[:from] }
44
- end
45
-
46
- it "should send an e-email based on reply_to" do
47
- should have_sent_email.reply_to { info[:reply_to] }
48
- end
49
-
50
- it "should send an e-mail based on cc" do
51
- should have_sent_email.cc{ info[:cc][0] }
52
- end
53
-
54
- it "should send an e-mail based on cc list" do
55
- should have_sent_email.with_cc{ info[:cc] }
56
- end
57
-
58
- it "should send an e-mail based on bcc" do
59
- should have_sent_email.bcc{ info[:bcc][0] }
60
- end
61
-
62
- it "should send an e-mail based on bcc list" do
63
- should have_sent_email.with_bcc{ info[:bcc] }
64
- end
65
-
66
- it "should send an e-mail based on body" do
67
- should have_sent_email.with_body{ info[:body] }
68
- end
69
- end
70
-
71
- context "testing with instance variables with multiple parts" do
72
- let(:info) do
73
- {
74
- :from => "do-not-reply@example.com",
75
- :to => "myself@me.com",
76
- :cc => ["you@you.com", "joe@bob.com", "hello@goodbye.com"],
77
- :bcc => ["test@example.com", "sam@bob.com", "goodbye@hello.com"],
78
- :subject => "This is spam",
79
- :text => "Every email is spam.",
80
- :html => "<h1>HTML is spam.</h1><p>Notably.</p>"
81
- }
82
- end
83
-
84
- before do
85
- define_mailer(:mailer, [:the_email]) do
86
- def the_email(params)
87
- mail params do |format|
88
- format.text { render :text => params[:text] }
89
- format.html { render :text => params[:html] }
90
- end
91
- end
92
- end
93
- add_mail_to_deliveries(info)
94
- end
95
-
96
- after { ::ActionMailer::Base.deliveries.clear }
97
-
98
- it "should send emails with text and html parts" do
99
- should have_sent_email.with_part('text/plain') { info[:text] }.with_part('text/html') { info[:html] }
100
- end
101
-
102
- it "should have the block override the method argument" do
103
- should have_sent_email.with_part('text/plain', 'foo') { info[:text] }.with_part('text/html', /bar/) { info[:html] }
104
- end
105
- end
106
-
107
- context "an email without multiple parts" do
108
- before do
109
- define_mailer :mailer, [:the_email] do
110
- def the_email(params)
111
- mail :from => "do-not-reply@example.com",
112
- :to => "myself@me.com",
113
- :subject => "This is spam",
114
- :cc => ["you@you.com", "joe@bob.com", "hello@goodbye.com"],
115
- :bcc => ["test@example.com", "sam@bob.com", "goodbye@hello.com"],
116
- :body => "Every email is spam."
117
- end
118
- end
119
- add_mail_to_deliveries
120
- end
121
-
122
- after { ::ActionMailer::Base.deliveries.clear }
123
-
124
- it "accepts sent-email when it is not multipart" do
125
- should_not have_sent_email.multipart
126
- matcher = have_sent_email.multipart(true)
127
- matcher.matches?(Mailer.the_email(nil))
128
- matcher.failure_message.should =~ /Expected sent email being multipart/
129
- end
130
-
131
- it "matches the body with a regexp" do
132
- should have_sent_email.with_body(/email is spam/)
133
- end
134
-
135
- it "matches the body with a string" do
136
- should have_sent_email.with_body("Every email is spam.")
137
- should_not have_sent_email.with_body("emails is")
138
- end
139
- end
140
-
141
- context "an email with both a text/plain and text/html part" do
142
- before do
143
- define_mailer :mailer, [:the_email] do
144
- def the_email(params)
145
- mail :from => "do-not-reply@example.com",
146
- :to => "myself@me.com",
147
- :cc => ["you@you.com", "joe@bob.com", "hello@goodbye.com"],
148
- :bcc => ["test@example.com", "sam@bob.com", "goodbye@hello.com"],
149
- :subject => "This is spam" do |format|
150
-
151
- format.text { render :text => "Every email is spam." }
152
- format.html { render :text => "<h1>HTML is spam.</h1><p>Notably.</p>" }
153
- end
154
- end
155
- end
156
- add_mail_to_deliveries
157
- end
158
-
159
- after { ::ActionMailer::Base.deliveries.clear }
160
-
161
- it "accepts sent e-mail based on the subject" do
162
- should have_sent_email.with_subject(/is spam$/)
163
- matcher = have_sent_email.with_subject(/totally safe/)
164
- matcher.matches?(nil)
165
- matcher.failure_message.should =~ /Expected sent email with subject/
166
- end
167
-
168
- it "accepts sent e-mail based on a string sender" do
169
- should have_sent_email.from('do-not-reply@example.com')
170
- matcher = have_sent_email.from('you@example.com')
171
- matcher.matches?(nil)
172
- matcher.failure_message.should =~ /Expected sent email from/
173
- end
174
-
175
- it "accepts sent e-mail based on a regexp sender" do
176
- should have_sent_email.from(/@example\.com/)
177
- matcher = have_sent_email.from(/you@/)
178
- matcher.matches?(nil)
179
- matcher.failure_message.should =~ /Expected sent email from/
180
- end
181
-
182
- it "accepts sent e-mail based on the body" do
183
- should have_sent_email.with_body(/is spam\./)
184
- matcher = have_sent_email.with_body(/totally safe/)
185
- matcher.matches?(nil)
186
- matcher.failure_message.should =~ /Expected sent email with body/
187
- end
188
-
189
- it "accepts sent e-mail based on a text/plain part" do
190
- should have_sent_email.with_part('text/plain', /is spam\./)
191
- matcher = have_sent_email.with_part('text/plain', /HTML is spam/)
192
- matcher.matches?(nil)
193
- matcher.failure_message.should =~ /Expected sent email with a text\/plain part containing/
194
- end
195
-
196
- it "accepts sent e-mail based on a text/html part" do
197
- should have_sent_email.with_part('text/html', /HTML is spam/)
198
- matcher = have_sent_email.with_part('text/html', /HTML is not spam\./)
199
- matcher.matches?(nil)
200
- matcher.failure_message.should =~ /Expected sent email with a text\/html part containing/
201
- end
202
-
203
- it "accept sent e-mail based on the recipient" do
204
- should have_sent_email.to('myself@me.com')
205
- matcher = have_sent_email.to('you@example.com')
206
- matcher.matches?(nil)
207
- matcher.failure_message.should =~ /Expected sent email to/
208
- end
209
-
210
- it "accepts sent e-mail based on cc string" do
211
- should have_sent_email.cc('joe@bob.com')
212
- matcher = have_sent_email.cc('you@example.com')
213
- matcher.matches?(nil)
214
- matcher.failure_message.should =~ /Expected sent email cc/
215
- end
216
-
217
- it "accepts sent-email based on cc regex" do
218
- should have_sent_email.cc(/@bob\.com/)
219
- matcher = have_sent_email.cc(/us@/)
220
- matcher.matches?(nil)
221
- matcher.failure_message.should =~ /Expected sent email cc/
222
- end
223
-
224
- it "accepts sent e-mail based on cc list" do
225
- should have_sent_email.with_cc(['you@you.com', 'joe@bob.com'])
226
- matcher = have_sent_email.with_cc(['you@example.com'])
227
- matcher.matches?(nil)
228
- matcher.failure_message.should =~ /Expected sent email with cc/
229
- end
230
-
231
- it "accepts sent e-mail based on bcc string" do
232
- should have_sent_email.bcc("goodbye@hello.com")
233
- matcher = have_sent_email.bcc("test@hello.com")
234
- matcher.matches?(nil)
235
- matcher.failure_message.should =~ /Expected sent email bcc/
236
- end
237
-
238
- it "accepts sent e-mail based on bcc regex" do
239
- should have_sent_email.bcc(/@example\.com/)
240
- matcher = have_sent_email.bcc(/you@/)
241
- matcher.matches?(nil)
242
- matcher.failure_message.should =~ /Expected sent email bcc/
243
- end
244
-
245
- it "accepts sent e-mail based on bcc list" do
246
- should have_sent_email.with_bcc(['sam@bob.com', 'test@example.com'])
247
- matcher = have_sent_email.with_bcc(['you@you.com', 'joe@bob.com'])
248
- matcher.matches?(nil)
249
- matcher.failure_message.should =~ /Expected sent email with bcc/
250
- end
251
-
252
- it "accepts sent-email when it is multipart" do
253
- should have_sent_email.multipart
254
- matcher = have_sent_email.multipart(false)
255
- matcher.matches?(nil)
256
- matcher.failure_message.should =~ /Expected sent email not being multipart/
257
- end
258
-
259
- it "lists all the deliveries within failure message" do
260
- add_mail_to_deliveries
261
-
262
- matcher = have_sent_email.to('you@example.com')
263
- matcher.matches?(nil)
264
- matcher.failure_message.should =~ /Deliveries:\n"This is spam" to \["myself@me\.com"\]\n"This is spam" to \["myself@me\.com"\]/
265
- end
266
-
267
- it "allows chaining" do
268
- should have_sent_email.with_subject(/spam/).from('do-not-reply@example.com').with_body(/spam/).
269
- with_part('text/plain', /is spam\./).with_part('text/html', /HTML is spam/).to('myself@me.com')
270
- should_not have_sent_email.with_subject(/ham/).from('you@example.com').with_body(/ham/).
271
- with_part('text/plain', /is ham/).with_part('text/html', /HTML is ham/).to('them@example.com')
272
- end
273
- end
274
-
275
- context "testing multiple email deliveries at once" do
276
- let(:info1) do
277
- {
278
- :from => "do-not-reply@example.com",
279
- :to => "one@me.com",
280
- :subject => "subject",
281
- :body => "body"
282
- }
283
- end
284
-
285
- let(:info2) do
286
- {
287
- :from => "do-not-reply@example.com",
288
- :to => "two@me.com",
289
- :subject => "subject",
290
- :body => "body"
291
- }
292
- end
293
-
294
- before do
295
- define_mailer(:mailer, [:the_email]) do
296
- def the_email(params)
297
- mail params
298
- end
299
- end
300
- add_mail_to_deliveries(info1)
301
- add_mail_to_deliveries(info2)
302
- end
303
-
304
- after { ::ActionMailer::Base.deliveries.clear }
305
-
306
- it "should send an e-mail based on recipient 1" do
307
- should have_sent_email.to("one@me.com")
308
- end
309
-
310
- it "should send an e-mail based on recipient 2" do
311
- should have_sent_email.to("two@me.com")
312
- end
313
- end
314
-
315
- it "provides a detailed description of the e-mail expected to be sent" do
316
- matcher = have_sent_email
317
- matcher.description.should == 'send an email'
318
- matcher = matcher.with_subject("Welcome!")
319
- matcher.description.should == 'send an email with a subject of "Welcome!"'
320
- matcher = matcher.with_body("Welcome, human!")
321
- matcher.description.should == 'send an email with a subject of "Welcome!" containing "Welcome, human!"'
322
- matcher = matcher.with_part('text/plain', 'plain')
323
- matcher.description.should == 'send an email with a subject of "Welcome!" containing "Welcome, human!" having a text/plain part containing "plain"'
324
- matcher = matcher.with_part('text/html', 'html')
325
- matcher.description.should == 'send an email with a subject of "Welcome!" containing "Welcome, human!" having a text/plain part containing "plain" having a text/html part containing "html"'
326
- matcher = matcher.from("alien@example.com")
327
- matcher.description.should == 'send an email with a subject of "Welcome!" containing "Welcome, human!" having a text/plain part containing "plain" having a text/html part containing "html" from "alien@example.com"'
328
- matcher = matcher.to("human@example.com")
329
- matcher.description.should == 'send an email with a subject of "Welcome!" containing "Welcome, human!" having a text/plain part containing "plain" having a text/html part containing "html" from "alien@example.com" to "human@example.com"'
330
- matcher = matcher.reply_to("reply-to-me@example.com")
331
- matcher.description.should == 'send an email with a subject of "Welcome!" containing "Welcome, human!" having a text/plain part containing "plain" having a text/html part containing "html" from "alien@example.com" reply to "reply-to-me@example.com" to "human@example.com"'
332
- end
333
- end