Module Shoulda::ActionMailer::Assertions
In: lib/shoulda/action_mailer/assertions.rb
ValidationMatcher ValidatePresenceOfMatcher ValidateAcceptanceOfMatcher EnsureLengthOfMatcher ValidateFormatOfMatcher EnsureInclusionOfMatcher ValidateUniquenessOfMatcher ValidateNumericalityOfMatcher Context SetSessionMatcher RespondWithContentTypeMatcher SetTheFlashMatcher RenderWithLayout RespondWithMatcher AssignToMatcher FilterParamMatcher RouteMatcher HaveNamedScopeMatcher HaveDbIndexMatcher HaveDbColumnMatcher AllowMassAssignmentOfMatcher AllowValueMatcher AssociationMatcher HaveReadonlyAttributeMatcher lib/shoulda/context.rb lib/shoulda/action_controller/matchers/set_session_matcher.rb lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb lib/shoulda/action_controller/matchers/respond_with_matcher.rb lib/shoulda/action_controller/matchers/assign_to_matcher.rb lib/shoulda/action_controller/matchers/filter_param_matcher.rb lib/shoulda/action_controller/matchers/route_matcher.rb Matchers Macros ActionController lib/shoulda/active_record/matchers/validation_matcher.rb lib/shoulda/active_record/matchers/have_named_scope_matcher.rb lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb lib/shoulda/active_record/matchers/have_db_index_matcher.rb lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb lib/shoulda/active_record/matchers/validate_format_of_matcher.rb lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb lib/shoulda/active_record/matchers/have_db_column_matcher.rb lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb lib/shoulda/active_record/matchers/allow_value_matcher.rb lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb lib/shoulda/active_record/matchers/association_matcher.rb lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb Matchers Helpers Assertions Macros ActiveRecord ClassMethods Macros ActionView Private Helpers Assertions ActionMailer InstanceMethods Assertions Macros Shoulda dot/m_47_0.png

Methods

Public Instance methods

Asserts that no ActionMailer mails were delivered

 assert_did_not_send_email

[Source]

    # File lib/shoulda/action_mailer/assertions.rb, line 30
30:       def assert_did_not_send_email
31:         msg = "Sent #{::ActionMailer::Base.deliveries.size} emails.\n"
32:         ::ActionMailer::Base.deliveries.each { |m| msg << "  '#{m.subject}' sent to #{m.to.to_sentence}\n" }
33:         assert ::ActionMailer::Base.deliveries.empty?, msg
34:       end

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?('none@none.com')
 end

Passes if there is an email with subject containing ‘hi there’ and ‘none@none.com’ as one of the recipients.

[Source]

    # File lib/shoulda/action_mailer/assertions.rb, line 18
18:       def assert_sent_email
19:         emails = ::ActionMailer::Base.deliveries
20:         assert !emails.empty?, "No emails were sent"
21:         if block_given?
22:           matching_emails = emails.select {|email| yield email }
23:           assert !matching_emails.empty?, "None of the emails matched."
24:         end
25:       end

[Validate]