Module: Tomo::Testing::HostExtensions
- Included in:
- Host
- Defined in:
- lib/tomo/testing/host_extensions.rb
Instance Attribute Summary collapse
-
#helper_values ⇒ Object
readonly
Returns the value of attribute helper_values.
-
#mocks ⇒ Object
readonly
Returns the value of attribute mocks.
-
#release ⇒ Object
readonly
Returns the value of attribute release.
-
#scripts ⇒ Object
readonly
Returns the value of attribute scripts.
Instance Method Summary collapse
- #initialize(**kwargs) ⇒ Object
- #mock(script, stdout: "", stderr: "", exit_status: 0) ⇒ Object
- #result_for(script) ⇒ Object
Instance Attribute Details
#helper_values ⇒ Object (readonly)
Returns the value of attribute helper_values.
6 7 8 |
# File 'lib/tomo/testing/host_extensions.rb', line 6 def helper_values @helper_values end |
#mocks ⇒ Object (readonly)
Returns the value of attribute mocks.
6 7 8 |
# File 'lib/tomo/testing/host_extensions.rb', line 6 def mocks @mocks end |
#release ⇒ Object (readonly)
Returns the value of attribute release.
6 7 8 |
# File 'lib/tomo/testing/host_extensions.rb', line 6 def release @release end |
#scripts ⇒ Object (readonly)
Returns the value of attribute scripts.
6 7 8 |
# File 'lib/tomo/testing/host_extensions.rb', line 6 def scripts @scripts end |
Instance Method Details
#initialize(**kwargs) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/tomo/testing/host_extensions.rb', line 8 def initialize(**kwargs) @mocks = [] @scripts = [] @helper_values = [] @release = {} super end |
#mock(script, stdout: "", stderr: "", exit_status: 0) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/tomo/testing/host_extensions.rb', line 16 def mock(script, stdout: "", stderr: "", exit_status: 0) mocks << [ script.is_a?(Regexp) ? script : /\A#{Regexp.quote(script)}\z/, Result.new(stdout: String.new(stdout), stderr: String.new(stderr), exit_status:) ] end |
#result_for(script) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/tomo/testing/host_extensions.rb', line 23 def result_for(script) match = mocks.find { |regexp, _| regexp.match?(script.to_s) } raise "Scripts cannot be mocked during dry_run" if match && Tomo.dry_run? match&.last || Result.empty_success end |