Class: RSpec::Mocks::ArgumentExpectation

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/mocks/argument_expectation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ ArgumentExpectation

Returns a new instance of ArgumentExpectation.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rspec/mocks/argument_expectation.rb', line 6

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

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



4
5
6
# File 'lib/rspec/mocks/argument_expectation.rb', line 4

def args
  @args
end

Instance Method Details

#args_match?(*args) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/rspec/mocks/argument_expectation.rb', line 32

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

#is_matcher?(obj) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/rspec/mocks/argument_expectation.rb', line 28

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

#matcher_for(arg) ⇒ Object



22
23
24
25
26
# File 'lib/rspec/mocks/argument_expectation.rb', line 22

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