Class: Chartspec::Formatter
- Inherits:
-
RSpec::Core::Formatters::ProgressFormatter
- Object
- RSpec::Core::Formatters::ProgressFormatter
- Chartspec::Formatter
- Defined in:
- lib/chartspec/formatter.rb
Instance Method Summary collapse
- #dump_summary(summary) ⇒ Object
- #example_failed(failure) ⇒ Object
- #example_group_started(notification) ⇒ Object
- #example_passed(passed) ⇒ Object
- #example_pending(pending) ⇒ Object
- #example_started(notification) ⇒ Object
-
#initialize(output) ⇒ Formatter
constructor
A new instance of Formatter.
- #start(notification) ⇒ Object
- #start_dump(notification) ⇒ Object
- #stop(notification) ⇒ Object
Constructor Details
#initialize(output) ⇒ Formatter
Returns a new instance of Formatter.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/chartspec/formatter.rb', line 11 def initialize(output) super output @failed_examples = [] @current_file = {} @example_group_number = 0 @example_number = 0 @header_red = false @db = Db.new ENV["CHARTSPEC_DB"] #@printer = Printer.new output end |
Instance Method Details
#dump_summary(summary) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/chartspec/formatter.rb', line 46 def dump_summary(summary) output.puts summary.fully_formatted @output_hash[:summary] = { :duration => summary.duration, :example_count => summary.example_count, :failure_count => summary.failure_count, :pending_count => summary.pending_count } @output_hash[:summary_line] = summary.totals_line specs_history = [].tap do |cd| @db.all.each do |row| cd << { file: row[0], name: row[1], duration: row[2], measured_at: row[3] } end end @chart_data = {}.tap do |spec_summary| specs_history.group_by{ |x| x[:name] }.each do |name, specs| measures = [] specs.each do |spec| measures << [Time.at(spec[:measured_at]), spec[:duration], spec[:name]] end spec_summary[name] = measures end end @chartspec_root = File.("../../../", __FILE__) template = ERB.new File.new(File.("../../../templates/chartspec.html.erb", __FILE__)).read, nil, "%" template.result(binding) @chart_file = ENV["CHARTSPEC_HTML"] || "tmp/chartspec.html" chart_dirname = File.dirname(@chart_file) unless File.directory?(chart_dirname) FileUtils.mkdir_p(chart_dirname) end File.open(@chart_file, "w") do |file| file.puts template.result(binding) end puts "* Chartspec output: #{@chart_file}\n" puts "* Chartspec tmp_db: #{@db.file_name}\n" end |
#example_failed(failure) ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/chartspec/formatter.rb', line 111 def example_failed(failure) super @failed_examples << failure.example unless @header_red @header_red = true end end |
#example_group_started(notification) ⇒ Object
93 94 95 96 97 |
# File 'lib/chartspec/formatter.rb', line 93 def example_group_started(notification) super @example_group_red = false @example_group_number += 1 end |
#example_passed(passed) ⇒ Object
107 108 109 |
# File 'lib/chartspec/formatter.rb', line 107 def example_passed(passed) super end |
#example_pending(pending) ⇒ Object
119 120 121 |
# File 'lib/chartspec/formatter.rb', line 119 def example_pending(pending) super end |
#example_started(notification) ⇒ Object
103 104 105 |
# File 'lib/chartspec/formatter.rb', line 103 def example_started(notification) @example_number += 1 end |
#start(notification) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/chartspec/formatter.rb', line 22 def start(notification) super @output_hash = {} #@printer.print_html_start #@printer.flush end |
#start_dump(notification) ⇒ Object
99 100 101 |
# File 'lib/chartspec/formatter.rb', line 99 def start_dump(notification) end |
#stop(notification) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/chartspec/formatter.rb', line 29 def stop(notification) @output_hash[:examples] = notification.examples.map do |example| format_example(example).tap do |hash| e = example.exception if e hash[:exception] = { :class => e.class.name, :message => e., :backtrace => e.backtrace, } else @db.add example.[:file_path], example.full_description, example.execution_result.run_time end end end end |