File: mailbox_example_group.rb

package info (click to toggle)
ruby-rspec-rails 8.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,804 kB
  • sloc: ruby: 10,881; sh: 198; makefile: 6
file content (80 lines) | stat: -rw-r--r-- 2,145 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
module RSpec
  module Rails
    # @api public
    # Container module for mailbox spec functionality.
    module MailboxExampleGroup
      extend ActiveSupport::Concern

      if RSpec::Rails::FeatureCheck.has_action_mailbox?
        require 'action_mailbox/test_helper'
        extend ::ActionMailbox::TestHelper

        # @private
        def self.create_inbound_email(arg)
          case arg
          when Hash
            create_inbound_email_from_mail(**arg)
          else
            create_inbound_email_from_source(arg.to_s)
          end
        end
      else
        def self.create_inbound_email(_arg)
          raise "Could not load ActionMailer::TestHelper"
        end
      end

      class_methods do
        # @private
        def mailbox_class
          described_class
        end
      end

      included do
        subject { described_class }
      end

      # @api public
      # Passes if the inbound email was delivered
      #
      # @example
      #       inbound_email = process(args)
      #       expect(inbound_email).to have_been_delivered
      def have_been_delivered
        satisfy('have been delivered', &:delivered?)
      end

      # @api public
      # Passes if the inbound email bounced during processing
      #
      # @example
      #       inbound_email = process(args)
      #       expect(inbound_email).to have_bounced
      def have_bounced
        satisfy('have bounced', &:bounced?)
      end

      # @api public
      # Passes if the inbound email failed to process
      #
      # @example
      #       inbound_email = process(args)
      #       expect(inbound_email).to have_failed
      def have_failed
        satisfy('have failed', &:failed?)
      end

      # Process an inbound email message directly, bypassing routing.
      #
      # @param message [Hash, Mail::Message] a mail message or hash of
      #   attributes used to build one
      # @return [ActionMailbox::InboundMessage]
      def process(message)
        MailboxExampleGroup.create_inbound_email(message).tap do |mail|
          self.class.mailbox_class.receive(mail)
        end
      end
    end
  end
end