Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 93767e9

Browse files
committed
Buffer and flush messages, nested within example.
1 parent a62d1c9 commit 93767e9

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

lib/rspec/core/formatters/documentation_formatter.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class DocumentationFormatter < BaseTextFormatter
1212
def initialize(output)
1313
super
1414
@group_level = 0
15+
@messages = []
1516
end
1617

1718
def example_group_started(notification)
@@ -23,27 +24,39 @@ def example_group_started(notification)
2324

2425
def example_group_finished(_notification)
2526
@group_level -= 1 if @group_level > 0
27+
flush_messages
2628
end
2729

2830
def example_passed(passed)
2931
output.puts passed_output(passed.example)
32+
flush_messages
3033
end
3134

3235
def example_pending(pending)
3336
output.puts pending_output(pending.example,
3437
pending.example.execution_result.pending_message)
38+
flush_messages
3539
end
3640

3741
def example_failed(failure)
3842
output.puts failure_output(failure.example)
43+
flush_messages
3944
end
4045

4146
def message(notification)
42-
output.puts "#{current_indentation}#{notification.message}"
47+
@messages << notification.message
4348
end
4449

4550
private
4651

52+
def flush_messages
53+
@messages.each do |message|
54+
output.puts "#{current_indentation(1)}#{message}"
55+
end
56+
57+
@messages.clear
58+
end
59+
4760
def passed_output(example)
4861
ConsoleCodes.wrap("#{current_indentation}#{example.description.strip}", :success)
4962
end
@@ -65,8 +78,8 @@ def next_failure_index
6578
@next_failure_index += 1
6679
end
6780

68-
def current_indentation
69-
' ' * @group_level
81+
def current_indentation(offset = 0)
82+
' ' * (@group_level + offset)
7083
end
7184
end
7285
end

spec/rspec/core/formatters/documentation_formatter_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ def execution_result(values)
8989

9090
expect(formatter_output.string).to eql("
9191
root
92-
message
9392
example
93+
message
9494
")
9595
end
9696

0 commit comments

Comments
 (0)