Class: Gimme::Verifies

Inherits:
BlankSlate show all
Defined in:
lib/gimme/verifies.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(double, times = 1) ⇒ Verifies

Returns a new instance of Verifies.



5
6
7
8
9
# File 'lib/gimme/verifies.rb', line 5

def initialize(double,times=1)
  @double = double
  @times = times
  @raises_no_method_error = true
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gimme/verifies.rb', line 11

def method_missing(sym, *args, &block)
  sym = MethodResolver.resolve_sent_method(@double,sym,args,@raises_no_method_error)
                    
  #gosh, this loop sure looks familiar. just like another ugly loop I know. TODO.
  invoked = 0
  if @double.invocations[sym]
     @double.invocations[sym].each do |invoke_args,count|
       matching = args.size == invoke_args.size
       invoke_args.each_index do |i|
         unless invoke_args[i] == args[i]  || (args[i].respond_to?(:matches?) && args[i].matches?(invoke_args[i]))
           matching = false
           break
         end
       end
       invoked += count if matching
     end
  end
                
  if invoked != @times
    raise Errors::VerificationFailedError.new("expected #{sym} to have been called with #{args}")
  end
end

Instance Attribute Details

#raises_no_method_errorObject

Returns the value of attribute raises_no_method_error.



4
5
6
# File 'lib/gimme/verifies.rb', line 4

def raises_no_method_error
  @raises_no_method_error
end