Class: Spec::Mocks::ArgumentExpectation

Inherits:
Object
  • Object
show all
Defined in:
lib/gems/rspec-1.1.12/lib/spec/mocks/argument_expectation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args, &block) ⇒ ArgumentExpectation

Returns a new instance of ArgumentExpectation.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/gems/rspec-1.1.12/lib/spec/mocks/argument_expectation.rb', line 7

def initialize(args, &block)
  @args = args
  @constraints_block = block
  
  if ArgumentConstraints::AnyArgsConstraint === args.first
    @match_any_args = true
  elsif ArgumentConstraints::NoArgsConstraint === args.first
    @constraints = []
  else
    @constraints = args.collect {|arg| constraint_for(arg)}
  end
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



5
6
7
# File 'lib/gems/rspec-1.1.12/lib/spec/mocks/argument_expectation.rb', line 5

def args
  @args
end

Instance Method Details

#args_match?(given_args) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/gems/rspec-1.1.12/lib/spec/mocks/argument_expectation.rb', line 30

def args_match?(given_args)
  match_any_args? || constraints_block_matches?(given_args) || constraints_match?(given_args)
end

#constraint_for(arg) ⇒ Object



20
21
22
23
24
# File 'lib/gems/rspec-1.1.12/lib/spec/mocks/argument_expectation.rb', line 20

def constraint_for(arg)
  return ArgumentConstraints::MatcherConstraint.new(arg)   if is_matcher?(arg)
  return ArgumentConstraints::RegexpConstraint.new(arg) if arg.is_a?(Regexp)
  return ArgumentConstraints::EqualityProxy.new(arg)
end

#constraints_block_matches?(given_args) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/gems/rspec-1.1.12/lib/spec/mocks/argument_expectation.rb', line 34

def constraints_block_matches?(given_args)
  @constraints_block ? @constraints_block.call(*given_args) : nil
end

#constraints_match?(given_args) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/gems/rspec-1.1.12/lib/spec/mocks/argument_expectation.rb', line 38

def constraints_match?(given_args)
  @constraints == given_args
end

#is_matcher?(obj) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/gems/rspec-1.1.12/lib/spec/mocks/argument_expectation.rb', line 26

def is_matcher?(obj)
  return obj.respond_to?(:matches?) && obj.respond_to?(:description)
end

#match_any_args?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/gems/rspec-1.1.12/lib/spec/mocks/argument_expectation.rb', line 42

def match_any_args?
  @match_any_args
end