Class: Lookout::Mock::Method

Inherits:
Stub::Method show all
Defined in:
lib/lookout/mock/method.rb

Defined Under Namespace

Modules: Calls Classes: Arguments

Instance Method Summary collapse

Methods inherited from Stub::Method

#define, #each, #undefine, #yield

Constructor Details

#initialize(object, method, *args, &body) ⇒ Method

Returns a new instance of Method.



7
8
9
10
11
# File 'lib/lookout/mock/method.rb', line 7

def initialize(object, method, *args, &body)
  super object, method, &body
  @args = Arguments.new(*args)
  at_least_once
end

Instance Method Details

#at_least(times) ⇒ Object



43
44
45
46
# File 'lib/lookout/mock/method.rb', line 43

def at_least(times)
  @calls = Calls::Lower.new(self, times)
  self
end

#at_least_onceObject



25
26
27
# File 'lib/lookout/mock/method.rb', line 25

def at_least_once
  at_least(1)
end

#at_most(times) ⇒ Object



33
34
35
36
# File 'lib/lookout/mock/method.rb', line 33

def at_most(times)
  @calls = Calls::Upper.new(self, times)
  self
end

#at_most_onceObject



17
18
19
# File 'lib/lookout/mock/method.rb', line 17

def at_most_once
  at_most(1)
end

#call(*args, &block) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/lookout/mock/method.rb', line 48

def call(*args, &block)
  @calls.call
  @args.verify(*args)
  super
rescue Lookout::Mock::Error => e
  raise e, '%s: %s' % [self, e]
end

#exactly(times) ⇒ Object



38
39
40
41
# File 'lib/lookout/mock/method.rb', line 38

def exactly(times)
  @calls = Calls::Exactly.new(self, times)
  self
end

#neverObject



13
14
15
# File 'lib/lookout/mock/method.rb', line 13

def never
  exactly(0)
end

#onceObject



21
22
23
# File 'lib/lookout/mock/method.rb', line 21

def once
  exactly(1)
end

#to_sObject



61
62
63
# File 'lib/lookout/mock/method.rb', line 61

def to_s
  '%p.%s%p' % [@object, @method, @args]
end

#twiceObject



29
30
31
# File 'lib/lookout/mock/method.rb', line 29

def twice
  exactly(2)
end

#verifyObject



56
57
58
59
# File 'lib/lookout/mock/method.rb', line 56

def verify
  @calls.verify
  self
end