summaryrefslogtreecommitdiff
path: root/spec/mspec/lib/mspec/runner/formatters/describe.rb
blob: 176bd792793aec6a4c8348b5cda460374b0db208 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
require 'mspec/runner/formatters/dotted'
require 'mspec/runner/actions/tally'

class DescribeFormatter < DottedFormatter
  # Callback for the MSpec :finish event. Prints a summary of
  # the number of errors and failures for each +describe+ block.
  def finish
    describes = Hash.new { |h,k| h[k] = Tally.new }

    @exceptions.each do |exc|
      desc = describes[exc.describe]
      exc.failure? ? desc.failures! : desc.errors!
    end

    print "\n"
    describes.each do |d, t|
      text = d.size > 40 ? "#{d[0,37]}..." : d.ljust(40)
      print "\n#{text} #{t.failure}, #{t.error}"
    end
    print "\n" unless describes.empty?

    print "\n#{@timer.format}\n\n#{@tally.format}\n"
  end
end