Class: Contextual::Node Abstract
- Inherits:
-
Object
- Object
- Contextual::Node
- Defined in:
- lib/contextual/node.rb
Overview
This class is abstract.
Base class for testing nodes, like TestRunner, Group, and Test.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#skip ⇒ Object
readonly
Returns the value of attribute skip.
Instance Method Summary collapse
- #get_result(_filter_settings) ⇒ TestResult abstract
-
#initialize(title, setup: nil, teardown: nil, options: nil, skip: false) ⇒ Node
constructor
A new instance of Node.
- #run(current_context, filter_settings) ⇒ TestResult
-
#run_setup ⇒ TestResult, Nil
Runs the setup hook.
-
#run_teardown ⇒ TestResult, Nil
Runs the teardown hook.
-
#should_run_with_search_term(filter_settings) ⇒ Boolean
Should this run with the current filter settings, checking general search.
Constructor Details
#initialize(title, setup: nil, teardown: nil, options: nil, skip: false) ⇒ Node
Returns a new instance of Node.
10 11 12 13 14 15 16 17 |
# File 'lib/contextual/node.rb', line 10 def initialize(title, setup: nil, teardown: nil, options: nil, skip: false) @title = title @setup = setup @teardown = teardown @options = .nil? ? TestOptions.new : @skip = skip @context = Context.new end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
8 9 10 |
# File 'lib/contextual/node.rb', line 8 def result @result end |
#skip ⇒ Object (readonly)
Returns the value of attribute skip.
8 9 10 |
# File 'lib/contextual/node.rb', line 8 def skip @skip end |
Instance Method Details
#get_result(_filter_settings) ⇒ TestResult
This method is abstract.
Override this method in your subclass
65 66 67 68 |
# File 'lib/contextual/node.rb', line 65 def get_result(_filter_settings) # This has been marked as skipped - do nothing TestNeutral.new(@title, 'Skipped') if @skip end |
#run(current_context, filter_settings) ⇒ TestResult
22 23 24 25 26 27 28 29 30 |
# File 'lib/contextual/node.rb', line 22 def run(current_context, filter_settings) if @skip @result = TestNeutral.new(@title, 'Skipped') else @context.apply(current_context) @result = get_result(filter_settings) end @result end |
#run_setup ⇒ TestResult, Nil
Runs the setup hook
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/contextual/node.rb', line 34 def run_setup return if @setup.nil? begin @setup.call(@context) nil rescue StandardError => e @result = TestFailure.new(@title, 'Failed during setup', e) end end |
#run_teardown ⇒ TestResult, Nil
Runs the teardown hook
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/contextual/node.rb', line 47 def run_teardown return if @teardown.nil? begin @teardown.call(@context) nil rescue StandardError => e if @result.successes.positive? TestFailure.new(@title, 'Tests passed, but failed during teardown.', e) else TestFailure.new(@title, 'Failed during teardown', e) end end end |
#should_run_with_search_term(filter_settings) ⇒ Boolean
Should this run with the current filter settings, checking general search
73 74 75 76 77 78 |
# File 'lib/contextual/node.rb', line 73 def should_run_with_search_term(filter_settings) # Check if the general search term applies here return @title.include?(filter_settings.general_search_term) if filter_settings.has_general_search_term true end |