Sha256: 8fb34c73e47e6e0ec62d11c0a8c7d2501568a13e29debf73fb11cbaa76ac00c9

Contents?: true

Size: 927 Bytes

Versions: 15

Compression:

Stored size: 927 Bytes

Contents

# frozen_string_literal: true

require "rspec/rails/matchers/base_matcher"

module Katalyst
  module Kpop
    module Matchers
      # @api private
      class ChainedMatcher < RSpec::Rails::Matchers::BaseMatcher
        Input = Struct.new(:matched)

        delegate :failure_message, :failure_message_when_negated, to: :@matcher

        def initialize(*matchers)
          super()
          matchers.each { |m| self << m }
        end

        def <<(matcher)
          matcher = matcher.new if matcher.is_a?(Class)
          (@matchers ||= []) << matcher
          self
        end

        def match(_, actual)
          @matcher = Input.new(actual)
          @matchers.all? do |matcher|
            input    = @matcher.matched
            @matcher = matcher
            matcher.matches?(input)
          end
        end

        def description
          @matchers.last.description
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
katalyst-kpop-3.1.3 lib/katalyst/kpop/matchers/chained_matcher.rb
katalyst-kpop-3.1.2 lib/katalyst/kpop/matchers/chained_matcher.rb
katalyst-kpop-3.1.1 lib/katalyst/kpop/matchers/chained_matcher.rb
katalyst-kpop-3.1.0 lib/katalyst/kpop/matchers/chained_matcher.rb
katalyst-kpop-3.0.2 lib/katalyst/kpop/matchers/chained_matcher.rb
katalyst-kpop-3.0.1 lib/katalyst/kpop/matchers/chained_matcher.rb
katalyst-kpop-3.0.0 lib/katalyst/kpop/matchers/chained_matcher.rb
katalyst-kpop-3.0.0.beta.8 lib/katalyst/kpop/matchers/chained_matcher.rb
katalyst-kpop-3.0.0.beta.7 lib/katalyst/kpop/matchers/chained_matcher.rb
katalyst-kpop-3.0.0.beta.6 lib/katalyst/kpop/matchers/chained_matcher.rb
katalyst-kpop-3.0.0.beta.5 lib/katalyst/kpop/matchers/chained_matcher.rb
katalyst-kpop-3.0.0.beta.4 lib/katalyst/kpop/matchers/chained_matcher.rb
katalyst-kpop-3.0.0.beta.3 lib/katalyst/kpop/matchers/chained_matcher.rb
katalyst-kpop-3.0.0.beta.2 lib/katalyst/kpop/matchers/chained_matcher.rb
katalyst-kpop-3.0.0.beta.1 lib/katalyst/kpop/matchers/chained_matcher.rb