Exception: Flores::RSpec::Analyze::Analysis
- Inherits:
-
StandardError
- Object
- StandardError
- Flores::RSpec::Analyze::Analysis
- Defined in:
- lib/flores/rspec/analyze.rb
Overview
A formatter to show analysis of an ‘analyze_it` example.
Instance Method Summary collapse
-
#error_report(error, instances) ⇒ Object
def failure_summary.
-
#error_sample_states(error, instances) ⇒ Object
def error_summary.
-
#error_summary(error, instances) ⇒ Object
def error_report.
-
#failure_summary ⇒ Object
TODO(sissel): All these report/summary/to_s things are an indication that the report formatting belongs in a separate class.
-
#initialize(results) ⇒ Analysis
constructor
A new instance of Analysis.
-
#percent(count) ⇒ Object
def success_count.
-
#percent_s(count) ⇒ Object
def percent.
-
#success_count ⇒ Object
def total.
-
#to_s ⇒ Object
def percent_s.
-
#total ⇒ Object
def initialize.
Constructor Details
#initialize(results) ⇒ Analysis
Returns a new instance of Analysis.
79 80 81 |
# File 'lib/flores/rspec/analyze.rb', line 79 def initialize(results) @results = results end |
Instance Method Details
#error_report(error, instances) ⇒ Object
def failure_summary
121 122 123 124 125 |
# File 'lib/flores/rspec/analyze.rb', line 121 def error_report(error, instances) report = error_summary(error, instances) report += error_sample_states(error, instances) if instances.size > 1 report end |
#error_sample_states(error, instances) ⇒ Object
def error_summary
136 137 138 139 140 141 |
# File 'lib/flores/rspec/analyze.rb', line 136 def error_sample_states(error, instances) [ " Samples causing #{error}:", *instances.sample(5).collect { |state, _exception| " #{state}" } ] end |
#error_summary(error, instances) ⇒ Object
def error_report
127 128 129 130 131 132 133 134 |
# File 'lib/flores/rspec/analyze.rb', line 127 def error_summary(error, instances) sample = instances.sample(1) [ " #{percent_s(instances.length)} -> [#{instances.length}] #{error}", " Sample exception for #{sample.first[0]}", sample.first[1].to_s.gsub(/^/, " ") ] end |
#failure_summary ⇒ Object
TODO(sissel): All these report/summary/to_s things are an indication that the report formatting belongs in a separate class.
112 113 114 115 116 117 118 119 |
# File 'lib/flores/rspec/analyze.rb', line 112 def failure_summary report = ["Failure analysis:"] report += @results.sort_by { |_, v| -v.length }.collect do |group, instances| next if group == :success error_report(group, instances) end.reject(&:nil?).flatten report end |
#percent(count) ⇒ Object
def success_count
95 96 97 |
# File 'lib/flores/rspec/analyze.rb', line 95 def percent(count) return (count + 0.0) / total end |
#percent_s(count) ⇒ Object
def percent
99 100 101 |
# File 'lib/flores/rspec/analyze.rb', line 99 def percent_s(count) return format("%.2f%%", percent(count) * 100) end |
#success_count ⇒ Object
def total
87 88 89 90 91 92 93 |
# File 'lib/flores/rspec/analyze.rb', line 87 def success_count if @results.include?(:success) @results[:success].length else 0 end end |
#to_s ⇒ Object
def percent_s
103 104 105 106 107 108 |
# File 'lib/flores/rspec/analyze.rb', line 103 def to_s # This method is crazy complex for a formatter. Should refactor this significantly. report = ["#{percent_s(success_count)} tests successful of #{total} tests"] report += failure_summary if success_count < total report.join("\n") end |
#total ⇒ Object
def initialize
83 84 85 |
# File 'lib/flores/rspec/analyze.rb', line 83 def total @results.reduce(0) { |m, (_, v)| m + v.length } end |