Class: Chartspec::Formatter

Inherits:
RSpec::Core::Formatters::BaseTextFormatter
  • Object
show all
Defined in:
lib/chartspec/formatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ Formatter

Returns a new instance of Formatter.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/chartspec/formatter.rb', line 12

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
  @charts = {}
end

Instance Method Details

#dump_failures(notification) ⇒ Object



85
86
87
88
# File 'lib/chartspec/formatter.rb', line 85

def dump_failures(notification)
  return if notification.failure_notifications.empty?
  puts notification.fully_formatted_failed_examples
end

#dump_pending(notification) ⇒ Object



90
91
92
93
# File 'lib/chartspec/formatter.rb', line 90

def dump_pending(notification)
  return if notification.pending_examples.empty?
  puts notification.fully_formatted_pending_examples
end

#dump_summary(summary) ⇒ Object



29
30
31
32
33
# File 'lib/chartspec/formatter.rb', line 29

def dump_summary(summary)
  puts summary.totals_line
  @printer.print_html_end
  @printer.flush
end

#example_failed(failure) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'lib/chartspec/formatter.rb', line 70

def example_failed(failure)
  putc RSpec::Core::Formatters::ConsoleCodes.wrap('F', :failure)
  @failed_examples << failure.example
  unless @header_red
    @header_red = true
  end
  @printer.print_example_failed(@example_number, failure.example.[:file_path], failure.example.description, failure.example.execution_result.run_time,
    failure.example.exception.message, failure.example.exception.backtrace, failure.example.[:chartspec_turnip])
end

#example_group_started(notification) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/chartspec/formatter.rb', line 35

def example_group_started(notification)
  @example_group_red = false
  @example_group_number += 1
  
  unless example_group_number == 1
    @printer.print_group_end
    generate_chart @current_file, @current_group
  end
  @printer.print_group_start example_group_number, notification.group.to_s, notification.group.description, notification.group.parent_groups.size
  @charts[@example_group_number] = []
end

#example_passed(passed) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/chartspec/formatter.rb', line 59

def example_passed(passed)
  putc RSpec::Core::Formatters::ConsoleCodes.wrap('.', :success)
  @printer.print_example_passed(passed.example.description, passed.example.execution_result.run_time, passed.example.[:chartspec_turnip])
  @db.add(
    passed.example.[:file_path], 
    passed.example.example_group, 
    passed.example.description, 
    passed.example.execution_result.run_time
   ) if passed.example.[:chart]
end

#example_pending(pending) ⇒ Object



80
81
82
83
# File 'lib/chartspec/formatter.rb', line 80

def example_pending(pending)
  putc RSpec::Core::Formatters::ConsoleCodes.wrap('*', :pending)
  @printer.print_example_pending(pending.example.description, pending.example.execution_result.pending_message, pending.example.[:chartspec_turnip])
end

#example_started(notification) ⇒ Object



53
54
55
56
57
# File 'lib/chartspec/formatter.rb', line 53

def example_started(notification)
  @example_number += 1
  @current_group = notification.example.example_group
  @current_file = notification.example.[:file_path]
end

#start(notification) ⇒ Object



24
25
26
27
# File 'lib/chartspec/formatter.rb', line 24

def start(notification)
  @printer.print_html_start
  @printer.flush
end

#start_dump(notification) ⇒ Object



47
48
49
50
51
# File 'lib/chartspec/formatter.rb', line 47

def start_dump(notification)
  @printer.print_group_end
  generate_chart @current_file, @current_group
  puts
end