Module: DromedaryInitializer
- Defined in:
- lib/dromedary_initializer.rb
Class Method Summary collapse
- .already_initialized? ⇒ Boolean
- .create_directory(dir_name) ⇒ Object
- .create_directory_or_file(file_name, directory) ⇒ Object
- .create_file(file_name) ⇒ Object
- .cucumber_config_content ⇒ Object
- .cucumber_config_structure ⇒ Object
- .cucumber_not_initialized? ⇒ Boolean
- .dromedary_after_hooks ⇒ Object
- .dromedary_afterstep_hooks ⇒ Object
- .dromedary_before_hooks ⇒ Object
- .dromedary_config_content ⇒ Object
- .dromedary_config_structure ⇒ Object
- .dromedary_hooks_content ⇒ Object
- .dromedary_hooks_structure ⇒ Object
- .gemfile_content ⇒ Object
- .gemfile_structure ⇒ Object
- .gitignore_content ⇒ Object
- .gitignore_structure ⇒ Object
- .rakefile_content ⇒ Object
- .rakefile_structure ⇒ Object
- .report_already_initialized ⇒ Object
- .report_creating(file) ⇒ Object
- .report_exists(file) ⇒ Object
- .report_no_cucumber_found ⇒ Object
- .report_updating(file) ⇒ Object
- .run ⇒ Object
- .update_file(file_name, content) ⇒ Object
Class Method Details
.already_initialized? ⇒ Boolean
59 60 61 |
# File 'lib/dromedary_initializer.rb', line 59 def self.already_initialized? File.exist?('config/dromedary.yml') || File.exist?('features/support/dromedary_hooks.rb') end |
.create_directory(dir_name) ⇒ Object
24 25 26 |
# File 'lib/dromedary_initializer.rb', line 24 def self.create_directory(dir_name) create_directory_or_file dir_name, true end |
.create_directory_or_file(file_name, directory) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dromedary_initializer.rb', line 32 def self.create_directory_or_file(file_name, directory) file_type = if directory :mkdir_p else :touch end report_exists(file_name) || return if File.exist?(file_name) report_creating(file_name) FileUtils.send file_type, file_name end |
.create_file(file_name) ⇒ Object
28 29 30 |
# File 'lib/dromedary_initializer.rb', line 28 def self.create_file(file_name) create_directory_or_file file_name, false end |
.cucumber_config_content ⇒ Object
174 175 176 177 178 179 180 |
# File 'lib/dromedary_initializer.rb', line 174 def self.cucumber_config_content ['', '# Following lines were generated by Dromedary gem', '# It contains required Cucumber profiles to ensure that all reporting works', '', cucumber_config_structure] end |
.cucumber_config_structure ⇒ Object
182 183 184 185 186 187 |
# File 'lib/dromedary_initializer.rb', line 182 def self.cucumber_config_structure ['junit_report: --format pretty --format junit --out artifacts/junit_xml_reports', 'run_json_report: --format json --out artifacts/cucumber_json_reports/run.json', 'rerun_json_report: --format json --out artifacts/cucumber_json_reports/rerun.json', 'rerun_formatter: --format rerun --out artifacts/final_test_reports/fails.log'] end |
.cucumber_not_initialized? ⇒ Boolean
55 56 57 |
# File 'lib/dromedary_initializer.rb', line 55 def self.cucumber_not_initialized? !File.exist?('features/support/env.rb') end |
.dromedary_after_hooks ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/dromedary_initializer.rb', line 144 def self.dromedary_after_hooks ['After do |scenario|', ' # updating results hash for TestRail after each scenario', ' feature_name = scenario.feature.name', ' scenario_name = scenario.name', '', ' scenario.test_steps.each do |step|', " if step.text != 'Before hook' && step.text != 'AfterStep hook'", " step_name = File.open(step.location.file).readlines[step.location.line-1].lstrip", " full_description = (feature_name + ' ' + scenario_name + ' ' + step_name).rstrip", ' status_id = []', ' status_id = @passed_steps_count > 0 ? (status_id.push 1) : (status_id.push 5)', ' if @results[ full_description ]', ' @results[ full_description ].push(status_id).flatten!', ' else', ' @results[ full_description ] = status_id', ' end', ' @passed_steps_count -= 1', ' end', ' end', '', ' # setting TestRail to generate reports at specific folder', " unless @local == 'true'", ' File.open("artifacts/testrail_reports/file_#{Time.now.to_i}.json}.json", "w") do |file|', ' file.puts @results.to_json', ' end', ' end', 'end'] end |
.dromedary_afterstep_hooks ⇒ Object
138 139 140 141 142 |
# File 'lib/dromedary_initializer.rb', line 138 def self.dromedary_afterstep_hooks ['AfterStep do |step|', ' @passed_steps_count += 1 if step.passed?', 'end'] end |
.dromedary_before_hooks ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/dromedary_initializer.rb', line 124 def self.dromedary_before_hooks ['Before do', " # setting environment to 'local' in order not to generate reporting", " # if you need individual reports, just put this variable to 'false'", " ENV['local'] ||= 'true'", " @local = ENV['local']", '', ' # creating results hash for TestRail', ' @results = {}', ' # and resetting passed steps count', ' @passed_steps_count = 0', 'end'] end |
.dromedary_config_content ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/dromedary_initializer.rb', line 86 def self.dromedary_config_content ['# This file was generated by Dromedary gem', '# It contains required settings to support TestRail integration', '# Fill in each line with credentials of your TestRail account', '', dromedary_config_structure, ' # By default Dromedary creates Test Runs on TestRail this way:', ' # test_run_default_name + Suite Type + on Environment', ' # So at the end you will get something like this:', ' # "My_project Regression on Staging"'] end |
.dromedary_config_structure ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'lib/dromedary_initializer.rb', line 98 def self.dromedary_config_structure ['testrail:', ' url:', ' user:', ' password:', ' project_id:', ' suite_id:', ' test_run_default_name:'] end |
.dromedary_hooks_content ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/dromedary_initializer.rb', line 108 def self.dromedary_hooks_content ['# This file was generated by Dromedary gem', '# It contains required Cucumber hooks to ensure that all reporting works', '# Do not edit this file', '', dromedary_hooks_structure] end |
.dromedary_hooks_structure ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/dromedary_initializer.rb', line 116 def self.dromedary_hooks_structure [dromedary_before_hooks, '', dromedary_afterstep_hooks, '', dromedary_after_hooks] end |
.gemfile_content ⇒ Object
220 221 222 223 |
# File 'lib/dromedary_initializer.rb', line 220 def self.gemfile_content ['', gemfile_structure] end |
.gemfile_structure ⇒ Object
225 226 227 |
# File 'lib/dromedary_initializer.rb', line 225 def self.gemfile_structure ["gem 'junit_merge'"] end |
.gitignore_content ⇒ Object
189 190 191 192 |
# File 'lib/dromedary_initializer.rb', line 189 def self.gitignore_content ['', gitignore_structure] end |
.gitignore_structure ⇒ Object
194 195 196 |
# File 'lib/dromedary_initializer.rb', line 194 def self.gitignore_structure ['artifacts/'] end |
.rakefile_content ⇒ Object
198 199 200 201 202 203 |
# File 'lib/dromedary_initializer.rb', line 198 def self.rakefile_content ['', '', '# require Dromedary gem dependencies', rakefile_structure] end |
.rakefile_structure ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/dromedary_initializer.rb', line 205 def self.rakefile_structure ["require 'dromedary/tasks'", '', '# describing Dromedary rake tasks', "desc 'Rake task to run all the Dromedary sequence'", 'task :run_dromedary, :run_on do |task, args|', ' ENV["RUN_ON"] = "#{args[:run_on]}"', ' %W[prepare_for_a_ride store_cases_titles run_cucumber merge_junit_reports get_case_ids[run] rerun_if_needed generate_cucumber_json_reports create_run[smoke,#{args[:run_on]}] close_run[#{args[:run_on]}] final_clean_ups].each do |task_name|', ' sh "rake #{task_name}" do', ' #ignore errors', ' end', ' end', 'end'] end |
.report_already_initialized ⇒ Object
81 82 83 84 |
# File 'lib/dromedary_initializer.rb', line 81 def self.report_already_initialized puts ' Our suspicious Dromedary says that you have already initialized it' puts " There is no need to run 'dromedary -- init' command more than once" end |
.report_creating(file) ⇒ Object
67 68 69 |
# File 'lib/dromedary_initializer.rb', line 67 def self.report_creating(file) puts " creating #{file}" end |
.report_exists(file) ⇒ Object
63 64 65 |
# File 'lib/dromedary_initializer.rb', line 63 def self.report_exists(file) puts " exist #{file}" end |
.report_no_cucumber_found ⇒ Object
75 76 77 78 79 |
# File 'lib/dromedary_initializer.rb', line 75 def self.report_no_cucumber_found puts " Dromedary had searched all Sahara desert for Cucumber, but didn't found it" puts ' Are you sure that you had initialized Cucumber project?' puts " If not, try to run 'cucumber --init' first" end |
.report_updating(file) ⇒ Object
71 72 73 |
# File 'lib/dromedary_initializer.rb', line 71 def self.report_updating(file) puts " updating #{file}" end |
.run ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/dromedary_initializer.rb', line 2 def self.run if cucumber_not_initialized? report_no_cucumber_found elsif already_initialized? report_already_initialized else create_directory 'config' create_file 'config/dromedary.yml' create_file 'features/support/dromedary_hooks.rb' create_file 'config/cucumber.yml' create_file 'Rakefile' update_file 'config/dromedary.yml', dromedary_config_content update_file 'features/support/dromedary_hooks.rb', dromedary_hooks_content update_file 'config/cucumber.yml', cucumber_config_content update_file '.gitignore', gitignore_content update_file 'Rakefile', rakefile_content update_file 'Gemfile', gemfile_content end end |
.update_file(file_name, content) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/dromedary_initializer.rb', line 45 def self.update_file(file_name, content) open(file_name, 'a') do |file| content.flatten!.each do |line| file.puts line end end report_updating(file_name) end |