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
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/rspec-mocks-2.10.1/lib/rspec/mocks/argument_expectation.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/rspec-mocks-2.10.1/lib/rspec/mocks/argument_expectation.rb
rails-uploader-0.0.1 vendor/bundle/ruby/1.9.1/gems/rspec-mocks-2.10.1/lib/rspec/mocks/argument_expectation.rb
resque-pool-0.3.0 vendor/bundle/ruby/1.8/gems/rspec-mocks-2.9.0/lib/rspec/mocks/argument_expectation.rb
ftl-0.2.0 vendor/bundle/gems/rspec-mocks-2.10.1/lib/rspec/mocks/argument_expectation.rb
classiccms-0.2.4.pre vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/argument_expectation.rb
classiccms-0.2.4.pre vendor/bundle/gems/rspec-mocks-2.10.1/lib/rspec/mocks/argument_expectation.rb
rspec-mocks-2.10.1 lib/rspec/mocks/argument_expectation.rb
rspec-mocks-2.10.0 lib/rspec/mocks/argument_expectation.rb
horseman-0.0.5 vendor/ruby/1.9.1/gems/rspec-mocks-2.9.0/lib/rspec/mocks/argument_expectation.rb
frameworks-capybara-0.2.0.rc6 vendor/bundle/ruby/1.8/gems/rspec-mocks-2.9.0/lib/rspec/mocks/argument_expectation.rb
frameworks-capybara-0.2.0.rc5 vendor/bundle/ruby/1.8/gems/rspec-mocks-2.9.0/lib/rspec/mocks/argument_expectation.rb
frameworks-capybara-0.2.0.rc4 vendor/bundle/ruby/1.8/gems/rspec-mocks-2.9.0/lib/rspec/mocks/argument_expectation.rb
frameworks-capybara-0.2.0.rc3 vendor/bundle/ruby/1.8/gems/rspec-mocks-2.9.0/lib/rspec/mocks/argument_expectation.rb
frameworks-capybara-0.2.0.rc2 vendor/bundle/ruby/1.8/gems/rspec-mocks-2.9.0/lib/rspec/mocks/argument_expectation.rb
classicCMS-0.2.3 vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/argument_expectation.rb
classicCMS-0.2.2 vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/argument_expectation.rb
classicCMS-0.2.1 vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/argument_expectation.rb
classicCMS-0.2.0 vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/argument_expectation.rb
classicCMS-0.1.2 vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/argument_expectation.rb