Class: RSpec::CapturingFormatter
- Inherits:
-
Object
- Object
- RSpec::CapturingFormatter
show all
- Defined in:
- lib/rspec/capturing_formatter.rb,
lib/rspec/capturing_formatter/version.rb,
lib/rspec/capturing_formatter/renderer.rb,
lib/rspec/capturing_formatter/sanitizer.rb,
lib/rspec/capturing_formatter/stream_proxy.rb,
lib/rspec/capturing_formatter/configuration.rb,
lib/rspec/capturing_formatter/windows_terminal.rb,
lib/rspec/capturing_formatter/windows_command_line.rb
Overview
Interprets RSpec notifications and attributes captured writes; Renderer owns presentation.
Defined Under Namespace
Modules: WindowsCommandLine, WindowsTerminal
Classes: CaptureManager, Configuration, Renderer, Sanitizer, StreamProxy
Constant Summary
collapse
- VERSION =
After updating this value, run bundle exec rake bundle:install -m
to sync all Bundler lockfiles.
"1.0.1"
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(output, capture_manager: CapturingFormatter::CaptureManager.instance) ⇒ CapturingFormatter
Returns a new instance of CapturingFormatter.
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/rspec/capturing_formatter.rb', line 29
def initialize(output, capture_manager: CapturingFormatter::CaptureManager.instance)
@output = output
@manager = capture_manager
manager_was_active = @manager.active?
manager_generation = @manager.generation
@renderer = CapturingFormatter::Renderer.new(
output,
self.class.configuration,
capture_manager: @manager
)
@groups = []
@seen_groups = {}
@current_example = nil
@started = false
@suite_heading_emitted = false
@report_visible = false
@failed_reruns = []
@seed_notification = nil
@lease = @manager.activate(output, self)
rescue Exception
if defined?(@lease) && @lease
@manager.deactivate(@lease)
elsif @manager && !manager_was_active
@manager.rollback_if_unchanged(manager_generation)
end
raise
end
|
Instance Attribute Details
#output ⇒ Object
Returns the value of attribute output.
27
28
29
|
# File 'lib/rspec/capturing_formatter.rb', line 27
def output
@output
end
|
Class Method Details
22
23
24
|
# File 'lib/rspec/capturing_formatter.rb', line 22
def configure
yield(configuration)
end
|
Instance Method Details
#capture(source, value, encoding, nonblocking: false) ⇒ Object
166
167
168
169
170
171
172
173
174
175
176
|
# File 'lib/rspec/capturing_formatter.rb', line 166
def capture(source, value, encoding, nonblocking: false)
with_capture_lock do
if @current_example
@renderer.capture(source.to_s, value, encoding, nonblocking: nonblocking)
else
ensure_suite_or_context
label = (source == :stdout) ? "suite stdout" : "suite stderr"
@renderer.capture(label, value, encoding, nonblocking: nonblocking)
end
end
end
|
#close(_notification = nil) ⇒ Object
162
163
164
|
# File 'lib/rspec/capturing_formatter.rb', line 162
def close(_notification = nil)
with_capture_lock { @manager.deactivate(@lease) }
end
|
#dump_profile(notification) ⇒ Object
133
134
135
|
# File 'lib/rspec/capturing_formatter.rb', line 133
def dump_profile(notification)
with_capture_lock { @renderer.profile(notification) }
end
|
#dump_summary(notification) ⇒ Object
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# File 'lib/rspec/capturing_formatter.rb', line 137
def dump_summary(notification)
with_capture_lock do
total = notification.respond_to?(:example_count) ? notification.example_count : notification.examples.to_i
failed = notification.respond_to?(:failure_count) ? notification.failure_count : notification.failed_examples.to_i
pending = notification.respond_to?(:pending_count) ? notification.pending_count : notification.pending_examples.to_i
@renderer.summary(
total: total,
succeeded: total - failed - pending,
failed: failed,
pending: pending,
duration: notification.duration,
load_time: notification.load_time,
errors: notification.errors_outside_of_examples_count
)
@renderer.reruns(@failed_reruns.uniq)
if @seed_notification&.respond_to?(:seed_used?) && @seed_notification.seed_used?
@renderer.seed(@seed_notification.seed)
end
end
end
|
#example_failed(notification) ⇒ Object
90
91
92
93
94
95
|
# File 'lib/rspec/capturing_formatter.rb', line 90
def example_failed(notification)
with_capture_lock do
example = notification.example
finish_example(example, :failed, notification)
end
end
|
#example_group_finished(_notification) ⇒ Object
72
73
74
|
# File 'lib/rspec/capturing_formatter.rb', line 72
def example_group_finished(_notification)
with_capture_lock { @groups.pop }
end
|
#example_group_started(notification) ⇒ Object
68
69
70
|
# File 'lib/rspec/capturing_formatter.rb', line 68
def example_group_started(notification)
with_capture_lock { @groups << notification.group }
end
|
#example_passed(notification) ⇒ Object
86
87
88
|
# File 'lib/rspec/capturing_formatter.rb', line 86
def example_passed(notification)
with_capture_lock { finish_example(notification.example, :passed) }
end
|
#example_pending(notification) ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/rspec/capturing_formatter.rb', line 97
def example_pending(notification)
with_capture_lock do
example = notification.example
reason = example.execution_result.pending_message.to_s
skipped = example.execution_result.pending_exception.nil?
@renderer.pending(
reason,
rerun_command(example),
skipped: skipped,
run_time: example.execution_result.run_time
)
unless skipped || pending_failure_output == :skip
lines = failure_lines(notification, example)
if pending_failure_output == :no_backtrace
lines = lines.reject { |line| strip_ansi(line.to_s).lstrip.start_with?("# ") }
end
@renderer.failure(lines)
end
@current_example = nil
end
end
|
#example_started(notification) ⇒ Object
76
77
78
79
80
81
82
83
84
|
# File 'lib/rspec/capturing_formatter.rb', line 76
def example_started(notification)
with_capture_lock do
example = notification.example
@groups.each { |group| @seen_groups[group.object_id] = true }
@current_example = example
@report_visible = true
@renderer.example_started(path_for(example))
end
end
|
#finish_capture ⇒ Object
178
179
180
|
# File 'lib/rspec/capturing_formatter.rb', line 178
def finish_capture
with_capture_lock { @renderer.finish_capture }
end
|
#flush_pending ⇒ Object
182
183
184
|
# File 'lib/rspec/capturing_formatter.rb', line 182
def flush_pending
with_capture_lock { @renderer.flush_pending }
end
|
#message(notification) ⇒ Object
121
122
123
124
125
126
127
|
# File 'lib/rspec/capturing_formatter.rb', line 121
def message(notification)
with_capture_lock do
inside = !@current_example.nil?
@renderer.message(notification.message, inside_example: inside)
@report_visible = true
end
end
|
#seed(notification) ⇒ Object
158
159
160
|
# File 'lib/rspec/capturing_formatter.rb', line 158
def seed(notification)
with_capture_lock { @seed_notification = notification }
end
|
#start(notification) ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/rspec/capturing_formatter.rb', line 60
def start(notification)
with_capture_lock do
@started = true
@count = notification.count if notification.respond_to?(:count)
@load_time = notification.load_time if notification.respond_to?(:load_time)
end
end
|
#stop(_notification) ⇒ Object
129
130
131
|
# File 'lib/rspec/capturing_formatter.rb', line 129
def stop(_notification)
with_capture_lock { @manager.deactivate(@lease) }
end
|