Class: Validator::FormatterBase

Inherits:
Object
  • Object
show all
Defined in:
spec/support/formatters/formatter_base.rb

Direct Known Subclasses

Brief, Details, List

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ FormatterBase

Returns a new instance of FormatterBase.



6
7
8
9
# File 'spec/support/formatters/formatter_base.rb', line 6

def initialize output
  @output = output
  @groups = []
end

Instance Method Details

#close(notification) ⇒ Object



66
67
68
# File 'spec/support/formatters/formatter_base.rb', line 66

def close notification
  @output << "\n"
end

#colorize(str, color) ⇒ Object



11
12
13
# File 'spec/support/formatters/formatter_base.rb', line 11

def colorize str, color
  RSpec::Core::Formatters::ConsoleCodes.wrap str, color
end

#dump_failures(notification) ⇒ Object



44
45
46
47
48
# File 'spec/support/formatters/formatter_base.rb', line 44

def dump_failures notification
  if notification.failed_examples.any?
    @output << notification.fully_formatted_failed_examples
  end
end

#dump_pending(notification) ⇒ Object



27
28
29
30
31
# File 'spec/support/formatters/formatter_base.rb', line 27

def dump_pending notification
  if notification.pending_examples.any?
    @output << notification.fully_formatted_pending_examples
  end
end

#dump_sentinel_summaryObject



55
56
57
58
59
60
61
62
63
64
# File 'spec/support/formatters/formatter_base.rb', line 55

def dump_sentinel_summary
  return unless Validator::Testee.sentinel_errors.any?
  num = Validator::Testee.sentinel_errors.size
  str = "#{num} sentinel warnings:"
  str = colorize(str,:yellow) if num > 0
  @output << "\n#{str}\n\n"
  histogram = Validator::Testee.sentinel_errors.dup.inject(Hash.new(0)) { |h, x| h[x.class] += 1; h }.each_pair do |err,num|
    @output << colorize("  #{num} #{err}\n",:yellow)
  end
end

#dump_sentinel_warningsObject



33
34
35
36
37
38
39
40
41
42
# File 'spec/support/formatters/formatter_base.rb', line 33

def dump_sentinel_warnings
  warnings = Validator::Testee.sentinel_errors
  if warnings.any?
    @output << "\n\nSentinel warnings:\n\n"
    warnings.each.with_index(1) do |warning,i|
      @output << colorize("#{i.to_s.rjust(4)}) #{warning.class}\n",:yellow)
      @output << "      #{warning.message.capitalize}\n\n"
    end
  end
end

#dump_summary(notification) ⇒ Object



50
51
52
53
# File 'spec/support/formatters/formatter_base.rb', line 50

def dump_summary notification
  @output << notification.fully_formatted
  dump_sentinel_summary
end

#example_group_finished(notification) ⇒ Object



19
20
21
# File 'spec/support/formatters/formatter_base.rb', line 19

def example_group_finished notification
  @groups.pop
end

#example_group_started(notification) ⇒ Object



15
16
17
# File 'spec/support/formatters/formatter_base.rb', line 15

def example_group_started notification
  @groups.push notification.group.description
end

#start(notification) ⇒ Object



23
24
25
# File 'spec/support/formatters/formatter_base.rb', line 23

def start notification
  @output << "\n"
end