Class: RspecHtmlReporter
- Inherits:
-
RSpec::Core::Formatters::BaseFormatter
- Object
- RSpec::Core::Formatters::BaseFormatter
- RspecHtmlReporter
- Defined in:
- lib/rspec_html_reporter.rb
Constant Summary collapse
- DEFAULT_REPORT_PATH =
File.join(Bundler.root, 'reports', Time.now.strftime('%Y%m%d-%H%M%S'))
- REPORT_PATH =
ENV['REPORT_PATH'] || DEFAULT_REPORT_PATH
- SCREENRECORD_DIR =
File.join(REPORT_PATH, 'screenrecords')
- SCREENSHOT_DIR =
File.join(REPORT_PATH, 'screenshots')
- RESOURCE_DIR =
File.join(REPORT_PATH, 'resources')
Instance Method Summary collapse
- #close(notification) ⇒ Object
- #example_failed(notification) ⇒ Object
- #example_group_finished(notification) ⇒ Object
- #example_group_started(notification) ⇒ Object
- #example_passed(notification) ⇒ Object
- #example_pending(notification) ⇒ Object
- #example_started(notification) ⇒ Object
-
#initialize(io_standard_out) ⇒ RspecHtmlReporter
constructor
A new instance of RspecHtmlReporter.
Constructor Details
#initialize(io_standard_out) ⇒ RspecHtmlReporter
Returns a new instance of RspecHtmlReporter.
171 172 173 174 175 176 177 178 179 |
# File 'lib/rspec_html_reporter.rb', line 171 def initialize(io_standard_out) create_reports_dir create_screenshots_dir create_screenrecords_dir copy_resources @all_groups = {} @group_level = 0 end |
Instance Method Details
#close(notification) ⇒ Object
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/rspec_html_reporter.rb', line 258 def close(notification) File.open("#{REPORT_PATH}/overview.html", 'w') do |f| @overview = @all_groups @passed = @overview.values.map { |g| g[:passed].size }.inject(0) { |sum, i| sum + i } @failed = @overview.values.map { |g| g[:failed].size }.inject(0) { |sum, i| sum + i } @pending = @overview.values.map { |g| g[:pending].size }.inject(0) { |sum, i| sum + i } duration_values = @overview.values.map { |e| e[:duration] } duration_keys = duration_values.size.times.to_a if duration_values.size < 2 duration_values.unshift(duration_values.first) duration_keys = duration_keys << 1 end @durations = duration_keys.zip(duration_values.map{|d| d.to_f.round(5)}) @summary_duration = duration_values.map{|d| d.to_f.round(5)}.inject(0) { |sum, i| sum + i }.to_s(:rounded, precision: 5) @total_examples = @passed + @failed + @pending template_file = File.read(File.dirname(__FILE__) + '/../templates/overview.erb') f.puts ERB.new(template_file).result(binding) end end |
#example_failed(notification) ⇒ Object
203 204 205 206 |
# File 'lib/rspec_html_reporter.rb', line 203 def example_failed(notification) @group_example_failure_count += 1 @examples << Example.new(notification.example) end |
#example_group_finished(notification) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/rspec_html_reporter.rb', line 213 def example_group_finished(notification) @group_level -= 1 if @group_level == 0 File.open("#{REPORT_PATH}/#{notification.group.description.parameterize}.html", 'w') do |f| @passed = @group_example_success_count @failed = @group_example_failure_count @pending = @group_example_pending_count duration_values = @examples.map { |e| e.run_time } duration_keys = duration_values.size.times.to_a if duration_values.size < 2 and duration_values.size > 0 duration_values.unshift(duration_values.first) duration_keys = duration_keys << 1 end @title = notification.group.description @durations = duration_keys.zip(duration_values) @summary_duration = duration_values.inject(0) { |sum, i| sum + i }.to_s(:rounded, precision: 5) Example.load_spec_comments!(@examples) class_map = {passed: 'success', failed: 'danger', pending: 'warning'} statuses = @examples.map { |e| e.status } status = statuses.include?('failed') ? 'failed' : (statuses.include?('passed') ? 'passed' : 'pending') @all_groups[notification.group.description.parameterize] = { group: notification.group.description, examples: @examples.size, status: status, klass: class_map[status.to_sym], passed: statuses.select { |s| s == 'passed' }, failed: statuses.select { |s| s == 'failed' }, pending: statuses.select { |s| s == 'pending' }, duration: @summary_duration } template_file = File.read(File.dirname(__FILE__) + '/../templates/report.erb') f.puts ERB.new(template_file).result(binding) end end end |
#example_group_started(notification) ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/rspec_html_reporter.rb', line 181 def example_group_started(notification) if @group_level == 0 @example_group = {} @examples = [] @group_example_count = 0 @group_example_success_count = 0 @group_example_failure_count = 0 @group_example_pending_count = 0 end @group_level += 1 end |
#example_passed(notification) ⇒ Object
198 199 200 201 |
# File 'lib/rspec_html_reporter.rb', line 198 def example_passed(notification) @group_example_success_count += 1 @examples << Example.new(notification.example) end |
#example_pending(notification) ⇒ Object
208 209 210 211 |
# File 'lib/rspec_html_reporter.rb', line 208 def example_pending(notification) @group_example_pending_count += 1 @examples << Example.new(notification.example) end |
#example_started(notification) ⇒ Object
194 195 196 |
# File 'lib/rspec_html_reporter.rb', line 194 def example_started(notification) @group_example_count += 1 end |