Class: RspecHtmlFormatter
- Inherits:
-
RSpec::Core::Formatters::BaseFormatter
- Object
- RSpec::Core::Formatters::BaseFormatter
- RspecHtmlFormatter
- Defined in:
- lib/rspec_html_formatter.rb
Constant Summary collapse
- REPORT_PATH =
'./rspec_html_reports'
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) ⇒ RspecHtmlFormatter
constructor
A new instance of RspecHtmlFormatter.
Constructor Details
#initialize(io_standard_out) ⇒ RspecHtmlFormatter
Returns a new instance of RspecHtmlFormatter.
143 144 145 146 147 148 |
# File 'lib/rspec_html_formatter.rb', line 143 def initialize(io_standard_out) create_reports_dir create_resources_dir copy_resources @all_groups = {} end |
Instance Method Details
#close(notification) ⇒ Object
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/rspec_html_formatter.rb', line 221 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
168 169 170 171 |
# File 'lib/rspec_html_formatter.rb', line 168 def example_failed(notification) @group_example_failure_count += 1 @group_examples << Example.new(notification.example) end |
#example_group_finished(notification) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/rspec_html_formatter.rb', line 178 def example_group_finished(notification) 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 = @group_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) @examples = Specify.new(@group_examples).process 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 |
#example_group_started(notification) ⇒ Object
150 151 152 153 154 155 156 157 |
# File 'lib/rspec_html_formatter.rb', line 150 def example_group_started(notification) @example_group = {} @group_examples = [] @group_example_count = 0 @group_example_success_count = 0 @group_example_failure_count = 0 @group_example_pending_count = 0 end |
#example_passed(notification) ⇒ Object
163 164 165 166 |
# File 'lib/rspec_html_formatter.rb', line 163 def example_passed(notification) @group_example_success_count += 1 @group_examples << Example.new(notification.example) end |
#example_pending(notification) ⇒ Object
173 174 175 176 |
# File 'lib/rspec_html_formatter.rb', line 173 def example_pending(notification) @group_example_pending_count += 1 @group_examples << Example.new(notification.example) end |
#example_started(notification) ⇒ Object
159 160 161 |
# File 'lib/rspec_html_formatter.rb', line 159 def example_started(notification) @group_example_count += 1 end |