Sha256: de5e990f6614aaa96ae8ad5afdcaf1f7bc1cee72bc595994f84f6a4f12a92236

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

RSpec.configure do |config|
  config.before(:each) do
    ActionMailer::Base.deliveries.clear
  end
end

# A set of helpers meant to make your life easier when testing
# emails, especially given the fact that ActionMailer's API can
# be a bit inconsistent.
module MailerHelpers
  def emails
    ActionMailer::Base.deliveries
  end

  def last_email
    emails.last
  end

  def last_email_body
    last_email.body.encoded
  end

  def last_email_link
    URI.extract(last_email_body.to_s, %w(http https)).last
  end
end

RSpec.configure do |config|
  config.include MailerHelpers
end

RSpec.configure do |config|
  config.before :example, perform_enqueued: true do
    @old_perform_enqueued_jobs = ActiveJob::Base.queue_adapter.perform_enqueued_jobs
    @old_perform_enqueued_at_jobs = ActiveJob::Base.queue_adapter.perform_enqueued_at_jobs
    ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
    ActiveJob::Base.queue_adapter.perform_enqueued_at_jobs = true
  end

  config.after :example, perform_enqueued: true do
    ActiveJob::Base.queue_adapter.perform_enqueued_jobs = @old_perform_enqueued_jobs
    ActiveJob::Base.queue_adapter.perform_enqueued_at_jobs = @old_perform_enqueued_at_jobs
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
decidim-0.0.1.alpha4 decidim-dev/lib/decidim/test/rspec_support/action_mailer.rb
decidim-0.0.1.alpha3 decidim-dev/lib/decidim/test/rspec_support/action_mailer.rb