Sha256: c2991525508d0bdb639542de25e0bb4585001d7b1310300e565a52aebb203274

Contents?: true

Size: 1.28 KB

Versions: 16

Compression:

Stored size: 1.28 KB

Contents

module RSpec
  module Mocks
    class ArgumentExpectation
      attr_reader :args
      
      def initialize(*args, &block)
        @args = args
        @matchers_block = block if args.empty?
        @match_any_args = false
        @matchers = nil
        
        if ArgumentMatchers::AnyArgsMatcher === args.first
          @match_any_args = true
        elsif ArgumentMatchers::NoArgsMatcher === args.first
          @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)
        return obj.respond_to?(:matches?) & obj.respond_to?(:description)
      end
      
      def args_match?(*args)
        match_any_args? || matchers_block_matches?(*args) || matchers_match?(*args)
      end
      
      def matchers_block_matches?(*args)
        @matchers_block ? @matchers_block.call(*args) : nil
      end
      
      def matchers_match?(*args)
        @matchers == args
      end
      
      def match_any_args?
        @match_any_args
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
rspec-mocks-2.0.1 lib/rspec/mocks/argument_expectation.rb
gemrage-1.0.0 vendor/ruby/1.8/gems/rspec-mocks-2.0.0/lib/rspec/mocks/argument_expectation.rb
gemrage-0.4.1 vendor/ruby/1.8/gems/rspec-mocks-2.0.0/lib/rspec/mocks/argument_expectation.rb
gemrage-0.4.0 vendor/ruby/1.8/gems/rspec-mocks-2.0.0/lib/rspec/mocks/argument_expectation.rb
gemrage-0.3.2 vendor/ruby/1.8/gems/rspec-mocks-2.0.0/lib/rspec/mocks/argument_expectation.rb
gemrage-0.3.1 vendor/ruby/1.8/gems/rspec-mocks-2.0.0/lib/rspec/mocks/argument_expectation.rb
gemrage-0.3.0 vendor/ruby/1.8/gems/rspec-mocks-2.0.0/lib/rspec/mocks/argument_expectation.rb
gemrage-0.2.0 vendor/ruby/1.8/gems/rspec-mocks-2.0.0/lib/rspec/mocks/argument_expectation.rb
gemrage-0.1.2 vendor/ruby/1.8/gems/rspec-mocks-2.0.0/lib/rspec/mocks/argument_expectation.rb
gemrage-0.1.1 vendor/ruby/1.8/gems/rspec-mocks-2.0.0/lib/rspec/mocks/argument_expectation.rb
gemrage-0.1.0 vendor/ruby/1.8/gems/rspec-mocks-2.0.0/lib/rspec/mocks/argument_expectation.rb
gemrage-0.0.0 vendor/ruby/1.8/gems/rspec-mocks-2.0.0/lib/rspec/mocks/argument_expectation.rb
rspec-mocks-2.0.0 lib/rspec/mocks/argument_expectation.rb
rspec-mocks-2.0.0.rc lib/rspec/mocks/argument_expectation.rb
rspec-mocks-2.0.0.beta.22 lib/rspec/mocks/argument_expectation.rb
rspec-mocks-2.0.0.beta.20 lib/rspec/mocks/argument_expectation.rb