Class: DevelopWithPassion::Fakes::Fake
- Inherits:
-
Object
- Object
- DevelopWithPassion::Fakes::Fake
show all
- Defined in:
- lib/developwithpassion_fakes/fake.rb
Instance Method Summary
collapse
Constructor Details
#initialize(invocation_set = {}) ⇒ Fake
Returns a new instance of Fake.
4
5
6
|
# File 'lib/developwithpassion_fakes/fake.rb', line 4
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
8
9
10
|
# File 'lib/developwithpassion_fakes/fake.rb', line 8
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
12
13
14
15
16
|
# File 'lib/developwithpassion_fakes/fake.rb', line 12
def handle_unexpected_method_invocation(name,args,block)
method = stub(name.to_sym)
method.ignore_arg
return method.invoke(args)
end
|
#never_received?(symbol) ⇒ Boolean
26
27
28
|
# File 'lib/developwithpassion_fakes/fake.rb', line 26
def never_received?(symbol)
return !@method_invocations.has_key?(symbol)
end
|
#received(symbol) ⇒ Object
22
23
24
|
# File 'lib/developwithpassion_fakes/fake.rb', line 22
def received(symbol)
return @method_invocations[symbol]
end
|
#stub(symbol) ⇒ Object
18
19
20
|
# File 'lib/developwithpassion_fakes/fake.rb', line 18
def stub(symbol)
return @method_invocations[symbol] || @method_invocations[symbol] = MethodStub.new
end
|