Class: DeliveryMatchers::BeDelivered

Inherits:
Object
  • Object
show all
Defined in:
lib/delivery_matchers/be_delivered.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(first = {}, second = {}) ⇒ BeDelivered

Returns a new instance of BeDelivered.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/delivery_matchers/be_delivered.rb', line 5

def initialize(first={}, second={})
  case first
  when Time
    # Allow user to specify the :on date as the first argument:
    # be_delivered 1.day.from_now, via_queue: 'priority'
    options = second
    options[:on] = first
  when Hash
    options = first
  end

  # Rename the hash keys used by this matcher to match the keys used by
  # ActionMailer::MessageDelivery#deliver_later
  options[:wait]       ||= options[:in]
  options[:wait_until] ||= options[:on]
  options[:queue]      ||= options[:via_queue]

  @options = options
end

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



3
4
5
# File 'lib/delivery_matchers/be_delivered.rb', line 3

def email
  @email
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/delivery_matchers/be_delivered.rb', line 3

def options
  @options
end

Instance Method Details

#failure_messageObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/delivery_matchers/be_delivered.rb', line 30

def failure_message
  enqueued = enqueued_jobs.map(&:inspect).join("\n  ")

  [
    "expected to find this mail delivery job in queue:",
    "  #{expected_job}",
    "instead found these jobs:",
    "  #{enqueued}"
  ].join("\n")
end

#failure_message_when_negatedObject



41
42
43
44
45
46
# File 'lib/delivery_matchers/be_delivered.rb', line 41

def failure_message_when_negated
  [
    "expected NOT to find this mail delivery job in queue:",
    "  #{expected_job}"
  ].join("\n")
end

#matches?(email) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/delivery_matchers/be_delivered.rb', line 25

def matches?(email)
  @email = email
  enqueued_jobs.any? { |job| match_expected?(job) }
end