Sha256: 2644076990d9580b7c0b8fbda8fd45af44fb1cefae28b5399a48f92f28832168

Contents?: true

Size: 1.71 KB

Versions: 10

Compression:

Stored size: 1.71 KB

Contents

module RSpec
  module Rails
    module Matchers
      # Namespace for various implementations of ActionMailbox features
      #
      # @api private
      module ActionMailbox
        # @private
        class Base < RSpec::Rails::Matchers::BaseMatcher
          private

          def create_inbound_email(message)
            RSpec::Rails::MailboxExampleGroup.create_inbound_email(message)
          end
        end

        # @private
        class ReceiveInboundEmail < Base
          def initialize(message)
            super()

            @inbound_email = create_inbound_email(message)
          end

          def matches?(mailbox)
            @mailbox  = mailbox
            @receiver = ApplicationMailbox.router.send(:match_to_mailbox, inbound_email)

            @receiver == @mailbox
          end

          def failure_message
            "expected #{describe_inbound_email} to route to #{mailbox}".tap do |msg|
              if receiver
                msg << ", but routed to #{receiver} instead"
              end
            end
          end

          def failure_message_when_negated
            "expected #{describe_inbound_email} not to route to #{mailbox}"
          end

        private

          attr_reader :inbound_email, :mailbox, :receiver

          def describe_inbound_email
            "mail to #{inbound_email.mail.to.to_sentence}"
          end
        end
      end

      # @api public
      # Passes if the given inbound email would be routed to the subject inbox.
      #
      # @param message [Hash, Mail::Message] a mail message or hash of
      #   attributes used to build one
      def receive_inbound_email(message)
        ActionMailbox::ReceiveInboundEmail.new(message)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/rspec-rails-4.1.2/lib/rspec/rails/matchers/action_mailbox.rb
rspec-rails-4.1.2 lib/rspec/rails/matchers/action_mailbox.rb
rspec-rails-4.1.1 lib/rspec/rails/matchers/action_mailbox.rb
rspec-rails-4.1.0 lib/rspec/rails/matchers/action_mailbox.rb
rspec-rails-4.0.2 lib/rspec/rails/matchers/action_mailbox.rb
rspec-rails-4.0.1 lib/rspec/rails/matchers/action_mailbox.rb
rspec-rails-4.0.0 lib/rspec/rails/matchers/action_mailbox.rb
rspec-rails-4.0.0.rc1 lib/rspec/rails/matchers/action_mailbox.rb
rspec-rails-4.0.0.beta4 lib/rspec/rails/matchers/action_mailbox.rb
rspec-rails-4.0.0.beta3 lib/rspec/rails/matchers/action_mailbox.rb