Class: Fakes::MethodStub
- Inherits:
-
Object
- Object
- Fakes::MethodStub
- Defined in:
- lib/fakes/method_stub.rb
Instance Method Summary collapse
- #and_return(item) ⇒ Object
- #called_with(*args) ⇒ Object
- #ignore_arg ⇒ Object
-
#initialize(arg_sets = []) ⇒ MethodStub
constructor
A new instance of MethodStub.
- #invoke(args) ⇒ 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 6 7 8 9 10 11 |
# File 'lib/fakes/method_stub.rb', line 3 def initialize(arg_sets = []) array :arg_sets do|a| a.mutator :add_new_set do|set| @arg_sets << set set end end @arg_sets = arg_sets end |
Instance Method Details
#and_return(item) ⇒ Object
22 23 24 |
# File 'lib/fakes/method_stub.rb', line 22 def and_return(item) ignore_arg.and_return(item) end |
#called_with(*args) ⇒ Object
33 34 35 |
# File 'lib/fakes/method_stub.rb', line 33 def called_with(*args) return @arg_sets.find{|item| item.was_called_with?(args)} end |
#ignore_arg ⇒ Object
18 19 20 |
# File 'lib/fakes/method_stub.rb', line 18 def ignore_arg return add_new_set(IgnoreSet.new) end |
#invoke(args) ⇒ Object
27 28 29 30 31 |
# File 'lib/fakes/method_stub.rb', line 27 def invoke(args) set = @arg_sets.find{|item| item.matches?(args)} || ignore_arg set.capture_args(args) return set.return_value end |
#times?(value) ⇒ Boolean
41 42 43 |
# File 'lib/fakes/method_stub.rb', line 41 def times?(value) return total_times_called == value end |
#total_times_called ⇒ Object
37 38 39 |
# File 'lib/fakes/method_stub.rb', line 37 def total_times_called return @arg_sets.inject(0){|sum,item|sum += item.times_called} end |