Class: Mockr::CallMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/mockr.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(method_name, argspec, &listener) ⇒ CallMatcher

Returns a new instance of CallMatcher.



127
128
129
130
131
132
# File 'lib/mockr.rb', line 127

def initialize(method_name, argspec, &listener)
  @method_name = method_name
  @argspec = argspec
  @response = lambda { }
  @listener = listener
end

Instance Method Details

#===(args) ⇒ Object



134
135
136
137
138
139
140
# File 'lib/mockr.rb', line 134

def ===(args)
  return false if args.size > @argspec.size
  @argspec.zip(args).each do |expected, actual|
    return false unless expected === actual
  end
  true
end

#as(&block) ⇒ Object



151
152
153
# File 'lib/mockr.rb', line 151

def as(&block)
  @response = block
end

#callObject



142
143
144
145
# File 'lib/mockr.rb', line 142

def call
  @listener.call(self) if @listener
  @response.call
end

#to_sObject



147
148
149
# File 'lib/mockr.rb', line 147

def to_s
  "call to #{@method_name} with args #{@argspec.inspect}"
end