class RSpec::TestSpec::Formatter
rubocop:disable Metrics/ClassLength
Constants
- DEFAULT_REPORT_PATH
- REPORT_PATH
- SCREENRECORD_DIR
- SCREENSHOT_DIR
Public Class Methods
new(_output)
click to toggle source
Calls superclass method
# File lib/test_spec/rspec/formatter.rb, line 29 def initialize(_output) super create_report_directory create_screenshots_directory create_screenrecords_directory provide_resources @all_groups = {} # REPEATED FROM THE SUPER # @group_level = 0 end
Public Instance Methods
close(notification)
click to toggle source
This is from BaseTextFormatter. rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize
Calls superclass method
# File lib/test_spec/rspec/formatter.rb, line 193 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 super end
example_failed(notification)
click to toggle source
This comes from the DocumentationFormatter.
# File lib/test_spec/rspec/formatter.rb, line 63 def example_failed(notification) @group_example_failure_count += 1 @examples << Example.new(notification.example) end
example_group_finished(notification)
click to toggle source
rubocop:disable Metrics/LineLength rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize
Calls superclass method
# File lib/test_spec/rspec/formatter.rb, line 123 def example_group_finished(notification) super return unless @group_level.zero? # rubocop:disable Metrics/BlockLength 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(&:run_time) duration_keys = duration_values.size.times.to_a if duration_values.size < 2 && !duration_values.empty? 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(&:status) status = if statuses.include?('failed') 'failed' elsif statuses.include?('passed') 'passed' else 'pending' end @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 # rubocop:enable Metrics/BlockLength # THIS ONE IS FROM THE SUPER # @group_level -= 1 if @group_level > 0 end
example_group_started(_notification)
click to toggle source
ADDED FOR REPORTING
Calls superclass method
# File lib/test_spec/rspec/formatter.rb, line 105 def example_group_started(_notification) if @group_level.zero? @examples = [] @group_example_count = 0 @group_example_success_count = 0 @group_example_failure_count = 0 @group_example_pending_count = 0 end super # REPEATED FROM THE SUPER # @group_level += 1 end
example_passed(notification)
click to toggle source
This comes from the DocumentationFormatter.
Calls superclass method
# File lib/test_spec/rspec/formatter.rb, line 54 def example_passed(notification) super unless notification.example.metadata[:with_steps] # For reporter @group_example_success_count += 1 @examples << Example.new(notification.example) end
example_pending(notification)
click to toggle source
This comes from the DocumentationFormatter. Needed for Reporter
.
# File lib/test_spec/rspec/formatter.rb, line 70 def example_pending(notification) @group_example_pending_count += 1 @examples << Example.new(notification.example) end
example_started(notification)
click to toggle source
rubocop:disable Metrics/LineLength
# File lib/test_spec/rspec/formatter.rb, line 43 def example_started(notification) return unless notification.example.metadata[:with_steps] full_message = "#{current_indentation}#{notification.example.description}" output.puts Core::Formatters::ConsoleCodes.wrap(full_message, :default) # For reporter @group_example_count += 1 end
example_step_failed(notification)
click to toggle source
rubocop:enable Metrics/AbcSize rubocop:enable Style/ConditionalAssignment
# File lib/test_spec/rspec/formatter.rb, line 97 def example_step_failed(notification) full_message = "#{current_indentation} #{notification.type.to_s.capitalize} #{notification.message} (FAILED)" output.puts Core::Formatters::ConsoleCodes.wrap(full_message, :failure) end
example_step_passed(notification)
click to toggle source
# File lib/test_spec/rspec/formatter.rb, line 75 def example_step_passed(notification) full_message = "#{current_indentation} #{notification.type.to_s.capitalize} #{notification.message}" output.puts Core::Formatters::ConsoleCodes.wrap(full_message, :success) end
example_step_pending(notification)
click to toggle source
rubocop:disable Metrics/AbcSize rubocop:disable Style/ConditionalAssignment
# File lib/test_spec/rspec/formatter.rb, line 82 def example_step_pending(notification) full_message = "#{current_indentation} #{notification.type.to_s.capitalize} #{notification.message}" if notification.options[:pending] && notification.options[:pending] != true full_message << " (PENDING: #{notification.options[:pending]})" else full_message << " (PENDING)" end output.puts Core::Formatters::ConsoleCodes.wrap(full_message, :pending) end
Private Instance Methods
create_report_directory()
click to toggle source
rubocop:enable Metrics/AbcSize rubocop:enable Metrics/MethodLength rubocop:enable Metrics/LineLength
# File lib/test_spec/rspec/formatter.rb, line 228 def create_report_directory FileUtils.rm_rf(REPORT_PATH) if File.exist?(REPORT_PATH) FileUtils.mkpath(REPORT_PATH) end
create_screenrecords_directory()
click to toggle source
# File lib/test_spec/rspec/formatter.rb, line 237 def create_screenrecords_directory FileUtils.mkdir_p SCREENRECORD_DIR unless File.exist?(SCREENRECORD_DIR) end
create_screenshots_directory()
click to toggle source
# File lib/test_spec/rspec/formatter.rb, line 233 def create_screenshots_directory FileUtils.mkdir_p SCREENSHOT_DIR unless File.exist?(SCREENSHOT_DIR) end
provide_resources()
click to toggle source
# File lib/test_spec/rspec/formatter.rb, line 241 def provide_resources FileUtils.cp_r( File.dirname(__FILE__) + "/../../../resources", REPORT_PATH ) end