Class: CucumberFormatter
- Inherits:
-
Object
- Object
- CucumberFormatter
- Defined in:
- lib/cucumber_formatter.rb
Overview
Copyright © 2015, Salesforce.com, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
-
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
-
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
-
Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Instance Method Summary collapse
-
#after_feature_element(scenario) ⇒ Object
finish saving the test run.
-
#after_step(step) ⇒ Object
save the step.
- #before_feature_element(scenario) ⇒ Object
-
#initialize(step_mother, io, options) ⇒ CucumberFormatter
constructor
A new instance of CucumberFormatter.
Constructor Details
#initialize(step_mother, io, options) ⇒ CucumberFormatter
Returns a new instance of CucumberFormatter.
33 34 35 |
# File 'lib/cucumber_formatter.rb', line 33 def initialize(step_mother, io, ) puts "Initializing CucumberMetrics ...\n\n\n" end |
Instance Method Details
#after_feature_element(scenario) ⇒ Object
finish saving the test run
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/cucumber_formatter.rb', line 83 def after_feature_element(scenario) scenario.failed? ? passed = 0 : passed = 1 sql = "UPDATE scenario_test_runs SET elapsed_time = #{Time.now - @scenario_time_start}, passed = #{passed}, updated_at = now() WHERE id = #{@str_id}" @dbm.query sql if scenario.failed? save_links(scenario) end #reset step counter when scenario is finished @step_counter = 0 end |
#after_step(step) ⇒ Object
save the step
72 73 74 75 76 77 78 79 80 |
# File 'lib/cucumber_formatter.rb', line 72 def after_step(step) step_name = get_step_name(@scenario).strip[0..255].gsub('\'', '') @start_time = @end_time @end_time = Time.now sql = "INSERT INTO scenario_steps (scenario_test_run_id, name, elapsed_time, created_at, updated_at) VALUES (#{@str_id}, \'#{step_name}\', #{(@end_time - @start_time).round}, now(), now())" @dbm.query sql end |
#before_feature_element(scenario) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/cucumber_formatter.rb', line 37 def before_feature_element(scenario) @scenario = scenario @scenario_time_start = Time.now @start_time = Time.now @end_time = Time.now machine_name = Socket.gethostname @dbm ||= dbm if scenario == nil fail "The scenario did not run" end get_scenario_id(scenario) get_environment_id get_browser_id # save the test run sql = "INSERT INTO scenario_test_runs (scenario_id, test_run_at, test_environment_id, browser_id, machine_name, created_at, updated_at) VALUES (#{@scenario_id}, now(), #{@env_id}, #{@browser_id}, \'#{machine_name}\', now(), now())" @dbm.query(sql) @str_id = @dbm.last_id # extract and save the tags = (scenario) .each do |t| sql = "INSERT INTO scenario_tags (scenario_test_run_id, tag_name, created_at, updated_at) VALUES (#{@str_id}, \'#{t}\', now(), now())" @dbm.query(sql) end end |