Class: Fakes::MethodStub
- Inherits:
-
Object
- Object
- Fakes::MethodStub
- Defined in:
- lib/fakes/method_stub.rb
Instance Method Summary collapse
- #add_new_argument_set(set) ⇒ Object
- #and_return(item) ⇒ Object
- #called_with(*args) ⇒ Object
- #ignore_arg ⇒ Object
-
#initialize(arg_sets = []) ⇒ MethodStub
constructor
A new instance of MethodStub.
- #invoke(args) ⇒ Object
- #throws(exception) ⇒ Object
- #times?(value) ⇒ Boolean
- #total_times_called ⇒ Object
- #with(*args) ⇒ Object
Constructor Details
#initialize(arg_sets = []) ⇒ MethodStub
Returns a new instance of MethodStub.
3 4 5 |
# File 'lib/fakes/method_stub.rb', line 3 def initialize(arg_sets = []) @arg_sets = arg_sets end |
Instance Method Details
#add_new_argument_set(set) ⇒ Object
7 8 9 10 |
# File 'lib/fakes/method_stub.rb', line 7 def add_new_argument_set(set) @arg_sets << set set end |
#and_return(item) ⇒ Object
24 25 26 |
# File 'lib/fakes/method_stub.rb', line 24 def and_return(item) ignore_arg.and_return(item) end |
#called_with(*args) ⇒ Object
34 35 36 |
# File 'lib/fakes/method_stub.rb', line 34 def called_with(*args) return @arg_sets.find{|item| item.was_called_with?(args)} end |
#ignore_arg ⇒ Object
20 21 22 |
# File 'lib/fakes/method_stub.rb', line 20 def ignore_arg return add_new_argument_set(IgnoreSet.new) end |
#invoke(args) ⇒ Object
28 29 30 31 32 |
# File 'lib/fakes/method_stub.rb', line 28 def invoke(args) set = @arg_sets.find{|item| item.matches?(args)} || ignore_arg set.capture_args(args) return set.process end |
#throws(exception) ⇒ Object
16 17 18 |
# File 'lib/fakes/method_stub.rb', line 16 def throws(exception) ignore_arg.throws(exception) end |
#times?(value) ⇒ Boolean
42 43 44 |
# File 'lib/fakes/method_stub.rb', line 42 def times?(value) return total_times_called == value end |
#total_times_called ⇒ Object
38 39 40 |
# File 'lib/fakes/method_stub.rb', line 38 def total_times_called return @arg_sets.inject(0){|sum,item|sum += item.times_called} end |