Sha256: 8930b0de1a8ac932efab4fc13ed43ac40480abde1ee4980d88f506350f48e24f

Contents?: true

Size: 881 Bytes

Versions: 50

Compression:

Stored size: 881 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.try(: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

50 entries across 50 versions & 1 rubygems

Version Path
decidim-dev-0.29.1 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.28.4 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.27.9 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.29.0 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.28.3 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.27.8 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.29.0.rc4 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.29.0.rc3 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.29.0.rc2 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.29.0.rc1 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.28.2 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.27.7 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.28.1 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.27.6 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.26.10 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.26.9 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.28.0 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.27.5 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.28.0.rc5 lib/decidim/dev/test/rspec_support/action_mailer.rb
decidim-dev-0.28.0.rc4 lib/decidim/dev/test/rspec_support/action_mailer.rb