public
Description: Behaviour Driven Development framework for Ruby
Homepage: http://rspec.info
Clone URL: git://github.com/dchelimsky/rspec.git
Search Repo:
Click here to lend your support to: rspec and make a donation at www.pledgie.com !
commit  e1bce2b4517a206dd08313652cf2f0b0cf740d4f
tree    191fe7aef3e39acdd8e968b68e34a15312c297ce
parent  294acb030f811fd546735aa819cdcf89d142b635
rspec / lib / spec / runner / formatter / indented_text_formatter.rb
100644 49 lines (42 sloc) 1.729 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'spec/runner/formatter/base_text_formatter'
 
module Spec
  module Runner
    module Formatter
      class IndentedTextFormatter < BaseTextFormatter
        def add_example_group(example_group)
          super
          if example_group.description_args && !example_group.description_args.empty?
            output.puts "#{example_group_indentation(example_group)}#{example_group.description_args}"
            output.flush
          end
        end
 
        def example_failed(example, counter, failure)
          message = if failure.expectation_not_met?
            "#{example_group_indentation(example.class)} #{example.description} (FAILED - #{counter})"
          else
            "#{example_group_indentation(example.class)} #{example.description} (ERROR - #{counter})"
          end
 
          output.puts(failure.expectation_not_met? ? red(message) : magenta(message))
          output.flush
        end
 
        def example_passed(example)
          message = "#{example_group_indentation(example.class)} #{example.description}"
          output.puts green(message)
          output.flush
        end
 
        def example_pending(example, message)
          super
          output.puts yellow("#{example_group_indentation(example.class)} #{example.description} (PENDING: #{message})")
          output.flush
        end
 
        def example_group_indentation(example_group)
          example_group_chain = []
          example_group.send(:execute_in_class_hierarchy) do |parent_example_group|
            example_group_chain << parent_example_group if parent_example_group.description_args
          end
          ' ' * (example_group_chain - [example_group]).length
        end
      end
    end
  end
end