Module: Fakes::ArgBehaviour

Included in:
ArgSet, IgnoreSet
Defined in:
lib/fakes/arg_behaviour.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#arg_matcherObject

Returns the value of attribute arg_matcher.



3
4
5
# File 'lib/fakes/arg_behaviour.rb', line 3

def arg_matcher
  @arg_matcher
end

#callback_blockObject (readonly)

Returns the value of attribute callback_block.



4
5
6
# File 'lib/fakes/arg_behaviour.rb', line 4

def callback_block
  @callback_block
end

#return_valueObject

Returns the value of attribute return_value.



3
4
5
# File 'lib/fakes/arg_behaviour.rb', line 3

def return_value
  @return_value
end

#times_calledObject

Returns the value of attribute times_called.



3
4
5
# File 'lib/fakes/arg_behaviour.rb', line 3

def times_called
  @times_called
end

Instance Method Details

#and_return(item) ⇒ Object



10
11
12
# File 'lib/fakes/arg_behaviour.rb', line 10

def and_return(item)
  @return_value = item
end

#capture_args(args) ⇒ Object



18
19
20
21
22
# File 'lib/fakes/arg_behaviour.rb', line 18

def capture_args(args)
  @arguments_provided = true
  @times_called += 1
  @called_args = args
end

#initialize_matcher_using(args) ⇒ Object



6
7
8
# File 'lib/fakes/arg_behaviour.rb', line 6

def initialize_matcher_using(args)
  @arg_matcher = ArgMatchFactory.create_arg_matcher_using(args)
end

#matches?(args) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/fakes/arg_behaviour.rb', line 28

def matches?(args)
  return @arg_matcher.matches?(args)
end

#processObject



36
37
38
39
40
41
42
43
# File 'lib/fakes/arg_behaviour.rb', line 36

def process
  if callback_block
    @arguments_provided ? callback_block.call(*@called_args) : callback_block.call
  else
    raise @exception if @exception
    @return_value 
  end
end

#run(&callback_block) ⇒ Object



24
25
26
# File 'lib/fakes/arg_behaviour.rb', line 24

def run(&callback_block)
  @callback_block = callback_block
end

#throws(exception) ⇒ Object



14
15
16
# File 'lib/fakes/arg_behaviour.rb', line 14

def throws(exception)
  @exception = exception
end

#was_called_with?(args) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/fakes/arg_behaviour.rb', line 32

def was_called_with?(args)
  ArgMatchFactory.create_arg_matcher_using(args).matches?(@called_args)
end