Updated to latest rspec
[gitorious:georgyos-clone.git] / vendor / plugins / rspec / lib / spec / runner / formatter / nested_text_formatter.rb
1 require 'spec/runner/formatter/base_text_formatter'
2
3 module Spec
4   module Runner
5     module Formatter
6       class NestedTextFormatter < BaseTextFormatter
7         attr_reader :previous_nested_example_groups
8         def initialize(options, where)
9           super
10           @previous_nested_example_groups = []
11         end
12
13         def add_example_group(example_group)
14           super
15
16           current_nested_example_groups = described_example_group_chain
17           current_nested_example_groups.each_with_index do |nested_example_group, i|
18             unless nested_example_group == previous_nested_example_groups[i]
19               output.puts "#{'  ' * i}#{nested_example_group.description_args}"
20             end
21           end
22
23           @previous_nested_example_groups = described_example_group_chain
24         end
25
26         def example_failed(example, counter, failure)
27           message = if failure.expectation_not_met?
28             "#{current_indentation}#{example.description} (FAILED - #{counter})"
29           else
30             "#{current_indentation}#{example.description} (ERROR - #{counter})"
31           end
32
33           output.puts(failure.expectation_not_met? ? red(message) : magenta(message))
34           output.flush
35         end
36
37         def example_passed(example)
38           message = "#{current_indentation}#{example.description}"
39           output.puts green(message)
40           output.flush
41         end
42
43         def example_pending(example, message)
44           super
45           output.puts yellow("#{current_indentation}#{example.description} (PENDING: #{message})")
46           output.flush
47         end
48
49         def current_indentation
50           '  ' * previous_nested_example_groups.length
51         end
52
53         def described_example_group_chain
54           example_group_chain = []
55           example_group.send(:execute_in_class_hierarchy) do |parent_example_group|
56             if parent_example_group.description_args && !parent_example_group.description_args.empty?
57               example_group_chain << parent_example_group
58             end
59           end
60           example_group_chain
61         end
62       end
63     end
64   end
65 end