Class: Taski::TestHelper::MockWrapper
- Inherits:
-
Object
- Object
- Taski::TestHelper::MockWrapper
- Defined in:
- lib/taski/test_helper/mock_wrapper.rb
Overview
Wraps a mocked task and returns pre-configured values without executing the task. Tracks which methods were accessed for verification in tests.
Instance Attribute Summary collapse
-
#mock_values ⇒ Object
readonly
Returns the value of attribute mock_values.
-
#task_class ⇒ Object
readonly
Returns the value of attribute task_class.
Instance Method Summary collapse
-
#access_count(method_name) ⇒ Integer
Returns the number of times a method was accessed.
-
#accessed?(method_name) ⇒ Boolean
Checks if a method was accessed at least once.
-
#get_exported_value(method_name) ⇒ Object
Returns the mocked value for a method and records the access.
-
#initialize(task_class, mock_values) ⇒ MockWrapper
constructor
A new instance of MockWrapper.
Constructor Details
#initialize(task_class, mock_values) ⇒ MockWrapper
Returns a new instance of MockWrapper.
12 13 14 15 16 |
# File 'lib/taski/test_helper/mock_wrapper.rb', line 12 def initialize(task_class, mock_values) @task_class = task_class @mock_values = mock_values @access_counts = Hash.new(0) end |
Instance Attribute Details
#mock_values ⇒ Object (readonly)
Returns the value of attribute mock_values.
8 9 10 |
# File 'lib/taski/test_helper/mock_wrapper.rb', line 8 def mock_values @mock_values end |
#task_class ⇒ Object (readonly)
Returns the value of attribute task_class.
8 9 10 |
# File 'lib/taski/test_helper/mock_wrapper.rb', line 8 def task_class @task_class end |
Instance Method Details
#access_count(method_name) ⇒ Integer
Returns the number of times a method was accessed.
41 42 43 |
# File 'lib/taski/test_helper/mock_wrapper.rb', line 41 def access_count(method_name) @access_counts[method_name] end |
#accessed?(method_name) ⇒ Boolean
Checks if a method was accessed at least once.
34 35 36 |
# File 'lib/taski/test_helper/mock_wrapper.rb', line 34 def accessed?(method_name) @access_counts[method_name] > 0 end |
#get_exported_value(method_name) ⇒ Object
Returns the mocked value for a method and records the access.
22 23 24 25 26 27 28 29 |
# File 'lib/taski/test_helper/mock_wrapper.rb', line 22 def get_exported_value(method_name) unless @mock_values.key?(method_name) raise KeyError, "No mock value for method :#{method_name} on #{@task_class}" end @access_counts[method_name] += 1 @mock_values[method_name] end |