Class: Allure::AllureLifecycle
- Inherits:
-
Object
- Object
- Allure::AllureLifecycle
- Extended by:
- Forwardable
- Defined in:
- lib/allure_ruby_commons/allure_lifecycle.rb
Overview
Main class for creating and writing allure results
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#add_attachment(name:, source:, type:, test_case: false) ⇒ void
Add attachment to current test or step.
-
#add_test_step(step_result) ⇒ Allure::StepResult
Add step to current fixture|step|test case.
-
#clean_results_dir ⇒ void
Clean results directory.
-
#initialize(config = Config.instance) ⇒ AllureLifecycle
constructor
Allure lifecycle instance.
-
#start_fixture(fixture_result) ⇒ Allure::FixtureResult
Start fixture.
-
#start_prepare_fixture(fixture_result) ⇒ Allure::FixtureResult
Start prepare fixture.
-
#start_tear_down_fixture(fixture_result) ⇒ Allure::FixtureResult
Start tear down fixture.
-
#start_test_case(test_result) ⇒ Allure::TestResult
Start test case and add to current test container.
-
#start_test_container(test_result_container) ⇒ Allure::TestResultContainer
Start test result container.
-
#start_test_step(step_result) ⇒ Allure::StepResult
Start test step and add to current test case.
-
#stop_fixture ⇒ void
Stop current test fixture.
-
#stop_test_case ⇒ void
Stop current test case and write result.
-
#stop_test_container ⇒ void
Stop current test container and write result.
-
#stop_test_step ⇒ void
Stop current test step.
- #update_fixture {|current| ... } ⇒ void
- #update_test_case {|current| ... } ⇒ void
- #update_test_container {|current| ... } ⇒ void
- #update_test_step {|current| ... } ⇒ void
-
#write_categories(categories = config.categories) ⇒ void
Add categories.json.
-
#write_environment(env = config.environment_properties) ⇒ void
Add environment.properties file.
Constructor Details
#initialize(config = Config.instance) ⇒ AllureLifecycle
Allure lifecycle instance
14 15 16 17 18 19 |
# File 'lib/allure_ruby_commons/allure_lifecycle.rb', line 14 def initialize(config = Config.instance) @test_context = [] @step_context = [] @config = config @logger = config.logger end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
21 22 23 |
# File 'lib/allure_ruby_commons/allure_lifecycle.rb', line 21 def config @config end |
Instance Method Details
#add_attachment(name:, source:, type:, test_case: false) ⇒ void
This method returns an undefined value.
Add attachment to current test or step
211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/allure_ruby_commons/allure_lifecycle.rb', line 211 def (name:, source:, type:, test_case: false) = ResultUtils.(name, type) return logger.error { "Can't add attachment, unrecognized mime type: #{type}" } unless executable_item = test_case ? @current_test_case : current_executable return logger.error { "Can't add attachment, no test, step or fixture is running" } unless executable_item executable_item..push() logger.debug { "Adding attachment '#{name}' to '#{executable_item.name}'" } (source, ) end |
#add_test_step(step_result) ⇒ Allure::StepResult
Add step to current fixture|step|test case
247 248 249 250 251 |
# File 'lib/allure_ruby_commons/allure_lifecycle.rb', line 247 def add_test_step(step_result) current_executable.steps.push(step_result) @step_context.push(step_result) step_result end |
#clean_results_dir ⇒ void
This method returns an undefined value.
Clean results directory
255 256 257 |
# File 'lib/allure_ruby_commons/allure_lifecycle.rb', line 255 def clean_results_dir FileUtils.rm_f(Dir.glob("#{config.results_directory}/**/*")) if config.clean_results_directory end |
#start_fixture(fixture_result) ⇒ Allure::FixtureResult
Start fixture
168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/allure_ruby_commons/allure_lifecycle.rb', line 168 def start_fixture(fixture_result) clear_step_context unless current_test_result_container logger.error("Could not start fixture, test container is not started") return false end logger.debug { "Starting fixture: #{fixture_result.name}" } fixture_result.start = ResultUtils. fixture_result.stage = Stage::RUNNING end |
#start_prepare_fixture(fixture_result) ⇒ Allure::FixtureResult
Start prepare fixture
150 151 152 153 154 |
# File 'lib/allure_ruby_commons/allure_lifecycle.rb', line 150 def start_prepare_fixture(fixture_result) start_fixture(fixture_result) || return current_test_result_container.befores.push(fixture_result) @current_fixture = fixture_result end |
#start_tear_down_fixture(fixture_result) ⇒ Allure::FixtureResult
Start tear down fixture
159 160 161 162 163 |
# File 'lib/allure_ruby_commons/allure_lifecycle.rb', line 159 def start_tear_down_fixture(fixture_result) start_fixture(fixture_result) || return current_test_result_container.afters.push(fixture_result) @current_fixture = fixture_result end |
#start_test_case(test_result) ⇒ Allure::TestResult
Start test case and add to current test container
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/allure_ruby_commons/allure_lifecycle.rb', line 70 def start_test_case(test_result) clear_step_context unless current_test_result_container return logger.error { "Could not start test case, test container is not started" } end logger.debug("Starting test case: #{test_result.name}") test_result.start = ResultUtils. test_result.stage = Stage::RUNNING test_result.labels.push(ResultUtils.thread_label, ResultUtils.host_label, ResultUtils.language_label) current_test_result_container.children.push(test_result.uuid) @current_test_case = test_result end |
#start_test_container(test_result_container) ⇒ Allure::TestResultContainer
Start test result container
28 29 30 31 32 33 34 35 |
# File 'lib/allure_ruby_commons/allure_lifecycle.rb', line 28 def start_test_container(test_result_container) test_result_container.tap do |container| logger.debug { "Starting test container: #{container.name}" } container.start = ResultUtils. @test_context.push(container) end end |
#start_test_step(step_result) ⇒ Allure::StepResult
Start test step and add to current test case
113 114 115 116 117 118 119 120 121 |
# File 'lib/allure_ruby_commons/allure_lifecycle.rb', line 113 def start_test_step(step_result) return logger.error { "Could not start test step, no test case is running" } unless @current_test_case logger.debug { "Starting test step: #{step_result.name}" } step_result.start = ResultUtils. step_result.stage = Stage::RUNNING add_test_step(step_result) step_result end |
#stop_fixture ⇒ void
This method returns an undefined value.
Stop current test fixture
195 196 197 198 199 200 201 202 203 |
# File 'lib/allure_ruby_commons/allure_lifecycle.rb', line 195 def stop_fixture return logger.error { "Could not stop fixture, fixture is not started" } unless @current_fixture logger.debug { "Stopping fixture: #{@current_fixture.name}" } @current_fixture.stop = ResultUtils. @current_fixture.stage = Stage::FINISHED clear_current_fixture clear_step_context end |
#stop_test_case ⇒ void
This method returns an undefined value.
Stop current test case and write result
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/allure_ruby_commons/allure_lifecycle.rb', line 99 def stop_test_case return logger.error { "Could not stop test case, no test case is running" } unless @current_test_case logger.debug { "Stopping test case: #{@current_test_case.name}" } @current_test_case.stop = ResultUtils. @current_test_case.stage = Stage::FINISHED file_writer.write_test_result(@current_test_case) clear_current_test_case clear_step_context end |
#stop_test_container ⇒ void
This method returns an undefined value.
Stop current test container and write result
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/allure_ruby_commons/allure_lifecycle.rb', line 54 def stop_test_container unless current_test_result_container return logger.error { "Could not stop test container, no container is running." } end current_test_result_container.tap do |container| logger.debug { "Stopping container: #{container.name}" } container.stop = ResultUtils. file_writer.write_test_result_container(container) clear_last_test_container end end |
#stop_test_step ⇒ void
This method returns an undefined value.
Stop current test step
138 139 140 141 142 143 144 145 |
# File 'lib/allure_ruby_commons/allure_lifecycle.rb', line 138 def stop_test_step return logger.error { "Could not stop test step, no step is running" } unless current_test_step logger.debug { "Stopping test step: #{current_test_step.name}" } current_test_step.stop = ResultUtils. current_test_step.stage = Stage::FINISHED clear_last_test_step end |
#update_fixture {|current| ... } ⇒ void
This method returns an undefined value.
187 188 189 190 191 |
# File 'lib/allure_ruby_commons/allure_lifecycle.rb', line 187 def update_fixture return logger.error { "Could not update fixture, fixture is not started" } unless @current_fixture yield(@current_fixture) end |
#update_test_case {|current| ... } ⇒ void
This method returns an undefined value.
91 92 93 94 95 |
# File 'lib/allure_ruby_commons/allure_lifecycle.rb', line 91 def update_test_case return logger.error { "Could not update test case, no test case running" } unless @current_test_case yield(@current_test_case) end |
#update_test_container {|current| ... } ⇒ void
This method returns an undefined value.
44 45 46 47 48 49 50 |
# File 'lib/allure_ruby_commons/allure_lifecycle.rb', line 44 def update_test_container unless current_test_result_container return logger.error { "Could not update test container, no container is running." } end yield(current_test_result_container) end |
#update_test_step {|current| ... } ⇒ void
This method returns an undefined value.
130 131 132 133 134 |
# File 'lib/allure_ruby_commons/allure_lifecycle.rb', line 130 def update_test_step return logger.error { "Could not update test step, no step is running" } unless current_test_step yield(current_test_step) end |
#write_categories(categories = config.categories) ⇒ void
This method returns an undefined value.
Add categories.json
238 239 240 241 242 |
# File 'lib/allure_ruby_commons/allure_lifecycle.rb', line 238 def write_categories(categories = config.categories) return unless categories file_writer.write_categories(categories) end |
#write_environment(env = config.environment_properties) ⇒ void
This method returns an undefined value.
Add environment.properties file
227 228 229 230 231 232 |
# File 'lib/allure_ruby_commons/allure_lifecycle.rb', line 227 def write_environment(env = config.environment_properties) return unless env env_properties = env.respond_to?(:call) ? env.call : env file_writer.write_environment(env_properties) end |