Class: Grift::MockMethod::MockExecutions
- Inherits:
-
Object
- Object
- Grift::MockMethod::MockExecutions
- Defined in:
- lib/grift/mock_method/mock_executions.rb,
lib/grift/mock_method/mock_executions/mock_arguments.rb
Overview
An Array wrapper that tracks the calls and results for a Grift::MockMethod.
Defined Under Namespace
Classes: MockArguments
Instance Method Summary collapse
-
#calls ⇒ Array<Grift::MockMethod::MockExecutions::MockArguments>
Returns an array of the args used in each call to the mocked method.
-
#count ⇒ Number
Returns the count of executions.
-
#empty? ⇒ Boolean
Returns true if there have been no calls tracked.
-
#initialize ⇒ Grift::MockMethod::MockExecutions
constructor
A new instance of MockExecutions.
-
#results ⇒ Array
Returns an array of the results of each call to the mocked method.
-
#store(args: [], kwargs: {}, result: nil) ⇒ Array
Stores an args and result pair to the executions array.
Constructor Details
#initialize ⇒ Grift::MockMethod::MockExecutions
A new instance of MockExecutions.
14 15 16 |
# File 'lib/grift/mock_method/mock_executions.rb', line 14 def initialize @executions = [] end |
Instance Method Details
#calls ⇒ Array<Grift::MockMethod::MockExecutions::MockArguments>
Returns an array of the args used in each call to the mocked method
29 30 31 32 33 |
# File 'lib/grift/mock_method/mock_executions.rb', line 29 def calls @executions.map do |exec| exec[:arguments] end end |
#count ⇒ Number
Returns the count of executions.
67 68 69 |
# File 'lib/grift/mock_method/mock_executions.rb', line 67 def count @executions.count end |
#empty? ⇒ Boolean
Returns true if there have been no calls tracked.
49 50 51 |
# File 'lib/grift/mock_method/mock_executions.rb', line 49 def empty? @executions.empty? end |
#results ⇒ Array
Returns an array of the results of each call to the mocked method
82 83 84 85 86 |
# File 'lib/grift/mock_method/mock_executions.rb', line 82 def results @executions.map do |exec| exec[:result] end end |
#store(args: [], kwargs: {}, result: nil) ⇒ Array
Stores an args and result pair to the executions array.
101 102 103 |
# File 'lib/grift/mock_method/mock_executions.rb', line 101 def store(args: [], kwargs: {}, result: nil) @executions.push({ arguments: MockArguments.new(args: args, kwargs: kwargs), result: result }) end |