Class: Fakes::Fake
- Inherits:
-
Object
show all
- Defined in:
- lib/fakes/fake.rb
Instance Method Summary
collapse
Constructor Details
#initialize(invocation_set = {}) ⇒ Fake
Returns a new instance of Fake.
3
4
5
|
# File 'lib/fakes/fake.rb', line 3
def initialize(invocation_set = {})
@method_invocations = invocation_set
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
7
8
9
|
# File 'lib/fakes/fake.rb', line 7
def method_missing(name,*args,&block)
return @method_invocations.has_key?(name.to_sym) ? @method_invocations[name.to_sym].invoke(args) : handle_unexpected_method_invocation(name,args,block)
end
|
Instance Method Details
#handle_unexpected_method_invocation(name, args, block) ⇒ Object
15
16
17
18
19
|
# File 'lib/fakes/fake.rb', line 15
def handle_unexpected_method_invocation(name,args,block)
method = stub(name.to_sym)
method.ignore_arg
return method.invoke(args)
end
|
#never_received?(symbol, *args) ⇒ Boolean
29
30
31
|
# File 'lib/fakes/fake.rb', line 29
def never_received?(symbol, *args)
return !received?(symbol, *args)
end
|
#received(symbol) ⇒ Object
25
26
27
|
# File 'lib/fakes/fake.rb', line 25
def received(symbol)
return @method_invocations[symbol]
end
|
#received?(symbol, *args) ⇒ Boolean
33
34
35
36
37
38
39
|
# File 'lib/fakes/fake.rb', line 33
def received?(symbol, *args)
method = received(symbol)
return false if method.nil?
argument_set = method.called_with(*args)
return !argument_set.nil?
end
|
#send(name, *args, &block) ⇒ Object
11
12
13
|
# File 'lib/fakes/fake.rb', line 11
def send(name,*args,&block)
return method_missing(name,*args,&block)
end
|
#stub(symbol) ⇒ Object
21
22
23
|
# File 'lib/fakes/fake.rb', line 21
def stub(symbol)
return @method_invocations[symbol] || @method_invocations[symbol] = MethodStub.new
end
|