Class: Mockr::CallMatcher
- Inherits:
-
Object
- Object
- Mockr::CallMatcher
- Defined in:
- lib/mockr.rb
Overview
:nodoc:
Instance Method Summary collapse
- #===(args) ⇒ Object
- #as(&block) ⇒ Object
- #call ⇒ Object
-
#initialize(method_name, argspec, &listener) ⇒ CallMatcher
constructor
A new instance of CallMatcher.
- #to_s ⇒ Object
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 |
#call ⇒ Object
142 143 144 145 |
# File 'lib/mockr.rb', line 142 def call @listener.call(self) if @listener @response.call end |
#to_s ⇒ Object
147 148 149 |
# File 'lib/mockr.rb', line 147 def to_s "call to #{@method_name} with args #{@argspec.inspect}" end |