Module: Webhookdb::SpecHelpers::Message

Defined in:
lib/webhookdb/spec_helpers/message.rb

Class Method Summary collapse

Class Method Details

.fetch_last_emailObject

Retrieve the last sent email from the local mailpit service.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/webhookdb/spec_helpers/message.rb', line 25

module_function def fetch_last_email
  old = WebMock::Config.instance.allow
  mpurl = Webhookdb::Message::EmailTransport.mailpit_url
  getopts = {timeout: 5, logger: nil}
  WebMock::Config.instance.allow = mpurl
  begin
    list_resp = Webhookdb::Http.get("#{mpurl}/api/v1/messages", {limit: 1}, **getopts)
    msg = list_resp.parsed_response.fetch("messages").first
    msgid = msg.fetch("ID")
    headers_resp = Webhookdb::Http.get("#{mpurl}/api/v1/message/#{msgid}/headers", **getopts)
    msg["Headers"] = headers_resp.parsed_response
    return msg
  ensure
    WebMock::Config.instance.allow = old
  end
end

.included(context) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/webhookdb/spec_helpers/message.rb', line 6

def self.included(context)
  context.before(:each) do |example|
    if example.[:messaging]
      Webhookdb::Message::Transport.override = :fake
      Webhookdb::Message::FakeTransport.reset!
    end
  end

  context.after(:each) do |example|
    if example.[:messaging]
      Webhookdb::Message::Transport.override = nil
      Webhookdb::Message::FakeTransport.reset!
    end
  end

  super
end