Sha256: 2f20fa514451fd0684c196169790f1c3e547329e070b6f2550ede1c5a86fed9c

Contents?: true

Size: 1.26 KB

Versions: 11

Compression:

Stored size: 1.26 KB

Contents

module Spec
  module Mocks
    
    class ArgumentExpectation
      attr_reader :args
      
      def initialize(args, &block)
        @args = args
        @matchers_block = block
        
        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?(given_args)
        match_any_args? || matchers_block_matches?(given_args) || matchers_match?(given_args)
      end
      
      def matchers_block_matches?(given_args)
        @matchers_block ? @matchers_block.call(*given_args) : nil
      end
      
      def matchers_match?(given_args)
        @matchers == given_args
      end
      
      def match_any_args?
        @match_any_args
      end
      
    end
    
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
dchelimsky-rspec-1.1.99.1 lib/spec/mocks/argument_expectation.rb
dchelimsky-rspec-1.1.99.13 lib/spec/mocks/argument_expectation.rb
dchelimsky-rspec-1.1.99.2 lib/spec/mocks/argument_expectation.rb
dchelimsky-rspec-1.1.99.3 lib/spec/mocks/argument_expectation.rb
dchelimsky-rspec-1.1.99.4 lib/spec/mocks/argument_expectation.rb
dchelimsky-rspec-1.1.99.5 lib/spec/mocks/argument_expectation.rb
dchelimsky-rspec-1.1.99.6 lib/spec/mocks/argument_expectation.rb
dchelimsky-rspec-1.1.99.7 lib/spec/mocks/argument_expectation.rb
dchelimsky-rspec-1.1.99.8 lib/spec/mocks/argument_expectation.rb
dchelimsky-rspec-1.1.99.9 lib/spec/mocks/argument_expectation.rb
rspec-1.2.0 lib/spec/mocks/argument_expectation.rb