123456789_123456789_123456789_123456789_123456789_

Module: ActionMailer::TestCase::Behavior

Relationships & Source Files
Namespace Children
Modules:
Extension / Inclusion / Inheritance Descendants
Included In:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
self, Rails::Dom::Testing::Assertions::DomAssertions, Rails::Dom::Testing::Assertions::SelectorAssertions, ::ActionMailer::TestHelper, ::ActiveJob::TestHelper, ::ActiveSupport::Testing::Assertions, ::ActiveSupport::Testing::ConstantLookup
Defined in: actionmailer/lib/action_mailer/test_case.rb

Constant Summary

::ActiveSupport::Testing::Assertions - Included

UNTRACKED

Class Method Summary

::ActiveSupport::Concern - Extended

class_methods

Define class methods from given block.

included

Evaluate given block in context of base class, so that you can write class macros here.

prepended

Evaluate given block in context of base class, so that you can write class macros here.

append_features, prepend_features

Instance Attribute Summary

Instance Method Summary

::ActionMailer::TestHelper - Included

#assert_emails

Asserts that the number of emails sent matches the given number.

#assert_enqueued_email_with

Asserts that a specific email has been enqueued, optionally matching arguments and/or params.

#assert_enqueued_emails

Asserts that the number of emails enqueued for later delivery matches the given number.

#assert_no_emails

Asserts that no emails have been sent.

#assert_no_enqueued_emails

Asserts that no emails are enqueued for later delivery.

#capture_emails

Returns any emails that are sent in the block.

#deliver_enqueued_emails

Delivers all enqueued emails.

#delivery_job_filter

::ActiveJob::TestHelper - Included

#assert_enqueued_jobs

Asserts that the number of enqueued jobs matches the given number.

#assert_enqueued_with

Asserts that the job has been enqueued with the given arguments.

#assert_no_enqueued_jobs

Asserts that no jobs have been enqueued.

#assert_no_performed_jobs

Asserts that no jobs have been performed.

#assert_performed_jobs

Asserts that the number of performed jobs matches the given number.

#assert_performed_with

Asserts that the job has been performed with the given arguments.

#perform_enqueued_jobs

Performs all enqueued jobs.

#queue_adapter

Accesses the queue_adapter set by ::ActiveJob::Base.

#queue_adapter_for_test

Returns a queue adapter instance to use with all Active Job test helpers.

#clear_enqueued_jobs, #clear_performed_jobs, #deserialize_args_for_assertion, #enqueued_jobs_with, #filter_as_proc, #flush_enqueued_jobs, #instantiate_job, #jobs_with, #performed_jobs_with, #prepare_args_for_assertion, #queue_adapter_changed_jobs, #require_active_job_test_adapter!, #validate_option, #after_teardown, #before_setup

::ActiveSupport::Testing::Assertions - Included

#assert_changes

Assertion that the result of evaluating an expression is changed before and after invoking the passed in block.

#assert_difference

Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block.

#assert_no_changes

Assertion that the result of evaluating an expression is not changed before and after invoking the passed in block.

#assert_no_difference

Assertion that the numeric result of evaluating an expression is not changed before and after invoking the passed in block.

#assert_not

Asserts that an expression is not truthy.

#assert_nothing_raised

Assertion that the block should not raise an exception.

#assert_raise
#assert_raises

Asserts that a block raises one of exp.

#_assert_nothing_raised_or_warn, #_callable_to_source_string

DSL Calls

included

[ GitHub ]


40
41
42
43
44
45
46
# File 'actionmailer/lib/action_mailer/test_case.rb', line 40

included do
  class_attribute :_mailer_class
  setup :initialize_test_deliveries
  setup :set_expected_mail
  teardown :restore_test_deliveries
  ActiveSupport.run_load_hooks(:action_mailer_test_case, self)
end

Instance Method Details

#charset (private)

[ GitHub ]

  
# File 'actionmailer/lib/action_mailer/test_case.rb', line 115

def charset
  "UTF-8"
end

#encode(subject) (private)

[ GitHub ]

  
# File 'actionmailer/lib/action_mailer/test_case.rb', line 119

def encode(subject)
  Mail::Encodings.q_value_encode(subject, charset)
end

#initialize_test_deliveries (private)

[ GitHub ]

  
# File 'actionmailer/lib/action_mailer/test_case.rb', line 87

def initialize_test_deliveries
  set_delivery_method :test
  @old_perform_deliveries = ActionMailer::Base.perform_deliveries
  ActionMailer::Base.perform_deliveries = true
  ActionMailer::Base.deliveries.clear
end

#read_fixture(action)

Reads the fixture file for the given mailer.

This is useful when testing mailers by being able to write the body of an email inside a fixture. See the testing guide for a concrete example: guides.rubyonrails.org/testing.html#revenge-of-the-fixtures

[ GitHub ]

  
# File 'actionmailer/lib/action_mailer/test_case.rb', line 82

def read_fixture(action)
  IO.readlines(File.join(Rails.root, "test", "fixtures", self.class.mailer_class.name.underscore, action))
end

#restore_delivery_method (private)

[ GitHub ]

  
# File 'actionmailer/lib/action_mailer/test_case.rb', line 104

def restore_delivery_method
  ActionMailer::Base.deliveries.clear
  ActionMailer::Base.delivery_method = @old_delivery_method
end

#restore_test_deliveries (private)

[ GitHub ]

  
# File 'actionmailer/lib/action_mailer/test_case.rb', line 94

def restore_test_deliveries
  restore_delivery_method
  ActionMailer::Base.perform_deliveries = @old_perform_deliveries
end

#set_delivery_method(method) (private)

[ GitHub ]

  
# File 'actionmailer/lib/action_mailer/test_case.rb', line 99

def set_delivery_method(method)
  @old_delivery_method = ActionMailer::Base.delivery_method
  ActionMailer::Base.delivery_method = method
end

#set_expected_mail (private)

[ GitHub ]

  
# File 'actionmailer/lib/action_mailer/test_case.rb', line 109

def set_expected_mail
  @expected = Mail.new
  @expected.content_type ["text", "plain", { "charset" => charset }]
  @expected.mime_version = "1.0"
end