Module: Shoulda::ActionMailer::Assertions
- Includes:
- ExpectationSerializer
- Defined in:
- lib/expected_mail.rb
Instance Attribute Summary
Attributes included from ExpectationSerializer
Instance Method Summary collapse
-
#assert_sent_email ⇒ Object
Asserts that an email was delivered.
- #binary? ⇒ Boolean
- #save_mail(path = '', bat = '_') ⇒ Object
Methods included from ExpectationSerializer
#expected_response_root, #file_path, #meth_name
Instance Method Details
#assert_sent_email ⇒ Object
Asserts that an email was delivered. Can take a block that can further narrow down the types of emails you're expecting.
assert_sent_email
Passes if ActionMailer::Base.deliveries has an email
assert_sent_email do |email| email.subject =~ /hi there/ && email.to.include?('[email protected]') end
Passes if there is an email with subject containing 'hi there' and '[email protected]' as one of the recipients.
19 20 21 22 23 24 25 26 27 |
# File 'lib/expected_mail.rb', line 19 def assert_sent_email emails = ::ActionMailer::Base.deliveries assert !emails.empty?, "No emails were sent" if block_given? matching_emails = emails.select {|email| yield email } assert !matching_emails.empty?, "None of the emails matched." end save_mail end |
#binary? ⇒ Boolean
29 30 31 |
# File 'lib/expected_mail.rb', line 29 def binary? false end |
#save_mail(path = '', bat = '_') ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/expected_mail.rb', line 32 def save_mail path = '', bat = '_' self.output ||= 'expected_responses' format = 'eml' binary = binary? ? "wb" : "w" FileUtils.mkdir_p "#{expected_response_root}/#{output}/#{self.file_path}/" unless File.exists? "#{expected_response_root}/#{output}/#{self.file_path}/" unless batch f = File.new("#{expected_response_root}/#{output}/#{file_path}/#{meth_name}#{path}.#{format}", binary) else f = File.new("#{expected_response_root}/#{output}/#{file_path}/#{meth_name}_#{@request.path_parameters['id']||@request.path_parameters['payment_id']||@request.path_parameters['congress_id']}#{path}.#{format}", binary) end f.write(::ActionMailer::Base.deliveries.last.to_s) f.close end |