Sha256: ee33b5d46e404d20c9c72acd273d1210b42e644f827d48d29f728150e9d97d6a

Contents?: true

Size: 874 Bytes

Versions: 38

Compression:

Stored size: 874 Bytes

Contents

# frozen_string_literal: true

require "nokogiri"

RSpec.configure do |config|
  config.before { clear_emails }
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 clear_emails
    ActionMailer::Base.deliveries.clear
  end

  def last_email
    emails.last
  end

  def last_email_body
    email_body(last_email)
  end

  def email_body(email)
    (email.try(:html_part).try(:body) || email.body).encoded
  end

  def last_email_link
    Nokogiri::HTML(last_email_body).css("table.content a").last["href"]
  end

  def last_email_first_link
    Nokogiri::HTML(last_email_body).css("table.content a").first["href"]
  end
end

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

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
decidim-dev-0.23.6 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.23.5 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.23.4 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.23.3 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.23.2 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.23.1 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.23.1.rc1 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.23.0 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.22.0 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.21.0 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.20.1 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.20.0 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.19.1 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.18.1 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.19.0 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.17.2 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.18.0 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.17.1 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.16.1 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.17.0 lib/decidim/dev/test/rspec_support/action_mailer.rb