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

Commit 0266427

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

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/rspec/core/formatters/documentation_formatter.rb

Lines changed: 15 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)
@@ -27,23 +28,34 @@ def example_group_finished(_notification)
2728

2829
def example_passed(passed)
2930
output.puts passed_output(passed.example)
31+
flush_messages
3032
end
3133

3234
def example_pending(pending)
3335
output.puts pending_output(pending.example,
3436
pending.example.execution_result.pending_message)
37+
flush_messages
3538
end
3639

3740
def example_failed(failure)
3841
output.puts failure_output(failure.example)
42+
flush_messages
3943
end
4044

4145
def message(notification)
42-
output.puts "#{current_indentation}#{notification.message}"
46+
@messages << notification.message
4347
end
4448

4549
private
4650

51+
def flush_messages
52+
@messages.each do |message|
53+
output.puts "#{current_indentation(1)}#{message}"
54+
end
55+
56+
@messages.clear
57+
end
58+
4759
def passed_output(example)
4860
ConsoleCodes.wrap("#{current_indentation}#{example.description.strip}", :success)
4961
end
@@ -65,8 +77,8 @@ def next_failure_index
6577
@next_failure_index += 1
6678
end
6779

68-
def current_indentation
69-
' ' * @group_level
80+
def current_indentation(offset = 0)
81+
' ' * (@group_level + offset)
7082
end
7183
end
7284
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)