Sha256: 30ae6c3887ce1bf7263509b046c85191ebcac4ff6fc788548b3d24b8dd95e0da
Contents?: true
Size: 1.13 KB
Versions: 5
Compression:
Stored size: 1.13 KB
Contents
def assert_html(html, *args, &block) assert_select(HTML::Document.new(html).root, *args, &block) end def emails_for_assertion(attributes) ::ActionMailer::Base.deliveries.select do |email| attributes.all? do |name, value| case name when 'body' value.split(',').map(&:strip).all? { |value| email.body.include?(value) } else email.send(name).to_s == value end end end end def assert_email_sent(attributes) emails = ::ActionMailer::Base.deliveries assert !emails.empty?, "No emails were sent" assert !emails_for_assertion(attributes).empty?, begin msg = ["None of the #{emails.size} emails matched #{attributes.inspect}.\nInstead, there are the following emails:"] msg += emails.map { |email| attributes.keys.map { |key| [key, email.send(key)] }.map { |key, value| "#{key}: #{value}" }.join(',') } msg.join("\n") end end def assert_no_email_sent(attributes = {}) if attributes.empty? assert ::ActionMailer::Base.deliveries.empty? else assert emails_for_assertion(attributes).empty?, "Expected none of the emails to match #{attributes.inspect}, but one did." end end
Version data entries
5 entries across 5 versions & 1 rubygems