Sha256: 150554c64f352f4b763edb90990868305a6d54892acc3317cb0253cbead12d99

Contents?: true

Size: 1.28 KB

Versions: 122

Compression:

Stored size: 1.28 KB

Contents

module RSpec
  module Mocks
    # @api private
    class ArgumentExpectation
      attr_reader :args

      def initialize(*args, &block)
        @args = args
        @block = args.empty? ? block : nil
        @match_any_args = false
        @matchers = nil

        case args.first
        when ArgumentMatchers::AnyArgsMatcher
          @match_any_args = true
        when ArgumentMatchers::NoArgsMatcher
          @matchers = []
        else
          @matchers = args.collect {|arg| matcher_for(arg)}
        end
      end

      def matcher_for(arg)
        return ArgumentMatchers::MatcherMatcher.new(arg) if is_matcher?(arg)
        return ArgumentMatchers::RegexpMatcher.new(arg)  if arg.is_a?(Regexp)
        return ArgumentMatchers::EqualityProxy.new(arg)
      end

      def is_matcher?(obj)
        !obj.null_object? & obj.respond_to?(:matches?) & [:failure_message_for_should, :failure_message].any? { |m| obj.respond_to?(m) }
      end

      def args_match?(*args)
        match_any_args? || block_passes?(*args) || matchers_match?(*args)
      end

      private

      def block_passes?(*args)
        @block.call(*args) if @block
      end

      def matchers_match?(*args)
        @matchers == args
      end

      def match_any_args?
        @match_any_args
      end
    end
  end
end

Version data entries

122 entries across 71 versions & 9 rubygems

Version Path
classiccms-0.6.6 vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/argument_expectation.rb
classiccms-0.6.5 vendor/bundle/gems/rspec-mocks-2.10.1/lib/rspec/mocks/argument_expectation.rb
classiccms-0.6.5 vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/argument_expectation.rb
classiccms-0.6.4 vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/argument_expectation.rb
classiccms-0.6.4 vendor/bundle/gems/rspec-mocks-2.10.1/lib/rspec/mocks/argument_expectation.rb
classiccms-0.6.3 vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/argument_expectation.rb
classiccms-0.6.3 vendor/bundle/gems/rspec-mocks-2.10.1/lib/rspec/mocks/argument_expectation.rb
classiccms-0.6.2 vendor/bundle/gems/rspec-mocks-2.10.1/lib/rspec/mocks/argument_expectation.rb
classiccms-0.6.2 vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/argument_expectation.rb
classiccms-0.6.1 vendor/bundle/gems/rspec-mocks-2.10.1/lib/rspec/mocks/argument_expectation.rb
classiccms-0.6.1 vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/argument_expectation.rb
classiccms-0.6.0 vendor/bundle/gems/rspec-mocks-2.10.1/lib/rspec/mocks/argument_expectation.rb
classiccms-0.6.0 vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/argument_expectation.rb
classiccms-0.5.17 vendor/bundle/gems/rspec-mocks-2.10.1/lib/rspec/mocks/argument_expectation.rb
classiccms-0.5.17 vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/argument_expectation.rb
classiccms-0.5.16 vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/argument_expectation.rb
classiccms-0.5.16 vendor/bundle/gems/rspec-mocks-2.10.1/lib/rspec/mocks/argument_expectation.rb
classiccms-0.5.15 vendor/bundle/gems/rspec-mocks-2.10.1/lib/rspec/mocks/argument_expectation.rb
classiccms-0.5.15 vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/argument_expectation.rb
classiccms-0.5.14 vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/argument_expectation.rb