rspec-osc7501 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d5789a92d347d7a152a9b2ce9a2edd188a21d6209beb9f41247f1a0713598233
4
+ data.tar.gz: 7ed3f5e657885323cb1381ecdb6202f299dd1f7db5f7239120329b9cecdb9c29
5
+ SHA512:
6
+ metadata.gz: 1934634e2afade69128ade89e9d1aa8a27eafa1449142c5b3807411e9af5eec7b8e6b538c13fd3e2fb70a63b773719a76cc85521688761919aece4dac57699b8
7
+ data.tar.gz: 1b0a02f82acf691eb1e36dc9f6c44f7078daeef4faff113da8c1bc18d210493cc745f1131359dc2c4018929364a82d2a997ee89be43333d5b77f98f485c7d84f
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+
5
+ - Add an opt-in OSC 7501 formatter for RSpec suite progress and outcomes.
6
+ - Support TTY detection, explicit output capture, and a configurable suite title.
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,25 @@
1
+ # Contributing
2
+
3
+ Use MRI Ruby 3.3 or newer. Install dependencies and run specs:
4
+
5
+ ```sh
6
+ bundle install
7
+ bundle exec rake spec
8
+ ```
9
+
10
+ Keep runtime dependencies limited to `rspec-core`. Cover formatter behavior with
11
+ specs and lifecycle changes with real RSpec subprocesses. Check RSpec 3.12 and
12
+ 3.13 when changing early-stop detection.
13
+
14
+ Build the gem and documentation:
15
+
16
+ ```sh
17
+ bundle exec rake package
18
+ bundle exec rake rdoc
19
+ ```
20
+
21
+ The package is `pkg/rspec-osc7501-0.1.0.gem`. Open `tmp/rdoc/index.html` to check
22
+ rendered documentation. Keep generated files out of commits.
23
+
24
+ Update usage or behavior documentation for user-visible changes and add a brief
25
+ entry under `Unreleased` in `CHANGELOG.md`. Preserve the Apache-2.0 license text.
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # rspec-osc7501
2
+
3
+ Report RSpec suite activity, progress and results to terminals that support
4
+ [OSC 7501](https://www.superlogical.com/rex/docs/build/program-status).
5
+ Use the formatter alongside RSpec’s progress or documentation formatter.
6
+
7
+ Requires MRI Ruby 3.3 or newer and `rspec-core >= 3.12, < 4`.
8
+
9
+ ## Install
10
+
11
+ This gem is unreleased. Add the source branch to your Gemfile:
12
+
13
+ ```ruby
14
+ group :test do
15
+ gem "rspec"
16
+ gem "rspec-osc7501",
17
+ git: "https://github.com/cosgroveb/rspec-osc7501",
18
+ branch: "feature/osc7501-formatter"
19
+ end
20
+ ```
21
+
22
+ Run `bundle install`.
23
+
24
+ ## Run
25
+
26
+ Run your specs in a terminal that supports OSC 7501:
27
+
28
+ ```sh
29
+ bundle exec rspec --require rspec/osc7501 \
30
+ --format progress --format RSpec::OSC7501::Formatter
31
+ ```
32
+
33
+ Keep `--format progress` to retain RSpec’s dots, failures and summary. The OSC
34
+ formatter reports completed examples and the final suite result through terminal
35
+ status records. Requiring `rspec/osc7501` registers the formatter without selecting
36
+ it.
37
+
38
+ To check the emitted records without terminal support, force output through a
39
+ pipe:
40
+
41
+ ```sh
42
+ RSPEC_OSC7501=force bundle exec rspec --require rspec/osc7501 \
43
+ --format progress --format RSpec::OSC7501::Formatter | cat -v
44
+ ```
45
+
46
+ Look for `^[]7501;` records alongside RSpec output. A normal completed run ends
47
+ with a `state=done` or `state=error` record.
48
+
49
+ ## Configure
50
+
51
+ | Environment variable | Values | Default |
52
+ | --- | --- | --- |
53
+ | `RSPEC_OSC7501` | `auto` emits to a TTY, `off` disables output, `force` permits redirected output | `auto` |
54
+ | `RSPEC_OSC7501_TITLE` | Title for the suite’s status records | `RSpec` |
55
+
56
+ The formatter uses the output stream RSpec assigns, including `--out`. Default
57
+ mode emits nothing to redirected streams. Use one reporting RSpec process per
58
+ terminal. Concurrent processes overwrite the same status record.
59
+
60
+ Early stops report `idle` unless failure conditions take precedence. Termination
61
+ that bypasses formatter callbacks can leave the last status in place. See
62
+ [behavior and limits](doc/behavior.rdoc) for classification details.
63
+
64
+ ## Documentation
65
+
66
+ - [Usage recipes](doc/usage.rdoc): persistent configuration and output routing.
67
+ - [Behavior and reference](doc/behavior.rdoc): progress, terminal states and limits.
68
+ - [Contributing](CONTRIBUTING.md): development and verification commands.
69
+ - [Changelog](CHANGELOG.md).
70
+
71
+ Licensed under [Apache License 2.0](LICENSE).
data/doc/behavior.rdoc ADDED
@@ -0,0 +1,83 @@
1
+ = Behavior
2
+
3
+ RSpec::OSC7501::Formatter reports one RSpec suite through OSC 7501. Requiring
4
+ <tt>rspec/osc7501</tt> registers the formatter without selecting it. Select an
5
+ ordinary formatter too if you want RSpec's progress or documentation output.
6
+
7
+ == Output and settings
8
+
9
+ The formatter uses the stream RSpec supplies, including <tt>--out</tt>. It leaves
10
+ that stream open. Settings apply when RSpec constructs the formatter.
11
+
12
+ [<tt>RSPEC_OSC7501=auto</tt>]
13
+ Emit to a TTY. This is the default, including an unset variable.
14
+ [<tt>RSPEC_OSC7501=off</tt>]
15
+ Emit no frames.
16
+ [<tt>RSPEC_OSC7501=force</tt>]
17
+ Emit to the selected stream even if it is not a TTY.
18
+ [<tt>RSPEC_OSC7501_TITLE</tt>]
19
+ Set a stable suite title. Default: <tt>RSpec</tt>.
20
+
21
+ Other mode values raise ArgumentError. A supporting terminal determines how to
22
+ display status. The formatter sends no capability query and reads no stdin.
23
+ Use one reporting RSpec process per terminal. Concurrent processes replace the
24
+ same root status record, without worker aggregation.
25
+
26
+ == Progress and outcomes
27
+
28
+ The first frame reports <tt>working</tt>. Example events update the current
29
+ description and completed, failed, and pending counts. Progress divides completed
30
+ results by the initial example count and stays within 0 to 100. Pending examples
31
+ count as completed. Zero-example runs omit progress.
32
+
33
+ Intermediate updates occur at most once per 100 ms. Initial and final updates
34
+ bypass throttling. A dry run identifies itself in its messages.
35
+
36
+ The final frame includes RSpec's summary counts and duration, with no progress:
37
+
38
+ [<tt>done</tt>]
39
+ The suite completed without a failure condition.
40
+ [<tt>error</tt>]
41
+ Failures, outside-example errors, a nonzero SystemExit, or another active
42
+ exception ended the run. An empty suite with <tt>fail_if_no_examples</tt> also
43
+ reports error.
44
+ [<tt>idle</tt>]
45
+ Interrupt, a successful early SystemExit, or an otherwise unexplained early-stop
46
+ request ended the run.
47
+
48
+ The formatter reads RSpec's private early-stop flag at summary time. A reached
49
+ fail-fast threshold or outside-example error takes precedence over that flag.
50
+ A coincident SIGINT can therefore report error. An early stop after a failure
51
+ can report idle and retain the failure count. The formatter preserves RSpec's
52
+ exit status.
53
+
54
+ Close emits no additional frame after a summary. A started run that closes
55
+ without a summary reports an incomplete error once.
56
+
57
+ == Reporting limits
58
+
59
+ RSpec must invoke formatter callbacks for a final result. Exits before formatter
60
+ installation, load-time SystemExit, forced termination, and a second SIGINT can
61
+ bypass those callbacks. A later <tt>at_exit</tt> failure can occur after the
62
+ formatter's result. The formatter installs no signal handler or process-wide
63
+ exit hook.
64
+
65
+ == Wire format
66
+
67
+ Each frame addresses the root record, repeats <tt>app=rspec</tt>, title, and
68
+ message, and ends with ST (ESC followed by a backslash). The formatter writes each
69
+ frame in one call and sends no clear-on-close record.
70
+
71
+ Title and message contain valid UTF-8 encoded as standard Base64. The formatter
72
+ removes control characters in U+0000 through U+001F and U+007F through U+009F,
73
+ replaces invalid encoding, and truncates on character boundaries. Decoded titles
74
+ are at most 192 bytes, decoded messages at most 2048 bytes, and frames at most
75
+ 4096 bytes.
76
+
77
+ IOError or SystemCallError disables further status output for that formatter
78
+ instance. Other exceptions propagate.
79
+
80
+ == Compatibility
81
+
82
+ The gem requires Ruby >= 3.3 and <tt>rspec-core</tt> >= 3.12, < 4. MRI is the
83
+ supported Ruby engine. Other engines and RSpec 4 are unverified.
data/doc/usage.rdoc ADDED
@@ -0,0 +1,54 @@
1
+ = Usage
2
+
3
+ Add OSC 7501 status alongside an ordinary RSpec formatter.
4
+ See the {README}[rdoc-ref:README.md] for source installation.
5
+
6
+ == Configure a project
7
+
8
+ Add these options to your project's <tt>.rspec</tt>:
9
+
10
+ --require rspec/osc7501
11
+ --format progress
12
+ --format RSpec::OSC7501::Formatter
13
+
14
+ Run <tt>bundle exec rspec</tt>. RSpec prints ordinary progress and sends status
15
+ frames to the formatter's TTY output. A terminal with OSC 7501 support can show
16
+ the suite status.
17
+
18
+ == Keep JSON separate
19
+
20
+ Give each formatter its own destination. RSpec applies <tt>--out</tt> to the
21
+ preceding formatter:
22
+
23
+ bundle exec rspec --require rspec/osc7501 \
24
+ --format json --out results.json \
25
+ --format progress --out /dev/stdout \
26
+ --format RSpec::OSC7501::Formatter --out /dev/stderr
27
+
28
+ This Unix example writes JSON to <tt>results.json</tt>, progress to stdout, and
29
+ status to stderr. The OSC formatter stays silent if stderr is not a TTY.
30
+
31
+ == Capture frames (optional)
32
+
33
+ Set <tt>RSPEC_OSC7501=force</tt> to permit redirected status output:
34
+
35
+ RSPEC_OSC7501=force bundle exec rspec --require rspec/osc7501 \
36
+ --format progress --out /dev/stdout \
37
+ --format RSpec::OSC7501::Formatter --out status.osc
38
+
39
+ <tt>status.osc</tt> contains terminal control sequences. Keep it separate from
40
+ JSON and other machine-readable reports.
41
+
42
+ == Set a title (optional)
43
+
44
+ Set the title for one run:
45
+
46
+ RSPEC_OSC7501_TITLE='Payments specs' bundle exec rspec
47
+
48
+ This command assumes the <tt>.rspec</tt> configuration above. The default title
49
+ is <tt>RSpec</tt>.
50
+
51
+ == Disable status
52
+
53
+ Set <tt>RSPEC_OSC7501=off</tt> to disable frames while retaining the formatter
54
+ configuration. See {Behavior}[rdoc-ref:doc/behavior.rdoc] for settings and limits.
@@ -0,0 +1,131 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpec
4
+ # Reports RSpec suite status through OSC 7501 terminal records.
5
+ module OSC7501
6
+ # RSpec formatter for suite activity, progress, and final results.
7
+ # Select alongside an ordinary formatter to retain RSpec's text output.
8
+ class Formatter
9
+ RSpec::Core::Formatters.register self, :start, :example_started, :example_passed,
10
+ :example_failed, :example_pending, :dump_summary, :close
11
+
12
+ # Writes status to RSpec's +output+ stream without closing it.
13
+ # Reads RSPEC_OSC7501 and RSPEC_OSC7501_TITLE at construction.
14
+ # The optional +clock+ callable returns monotonic seconds for throttling.
15
+ def initialize(output, clock: -> { Process.clock_gettime(Process::CLOCK_MONOTONIC) })
16
+ @writer = Writer.new(output, mode: ENV.fetch("RSPEC_OSC7501", "auto"),
17
+ title: ENV.fetch("RSPEC_OSC7501_TITLE", "RSpec"))
18
+ @clock = clock
19
+ @started = false
20
+ @summarized = false
21
+ end
22
+
23
+ # Starts suite progress from the example count in +notification+.
24
+ def start(notification)
25
+ @started = true
26
+ @total = notification.count
27
+ @completed = @failed = @pending = 0
28
+ @current = nil
29
+ @last_update = @clock.call
30
+ message = "Running #{@total} examples"
31
+ message += " (dry run)" if RSpec.configuration.dry_run
32
+ @writer.emit(state: "working", msg: message, progress: progress)
33
+ end
34
+
35
+ # Sets the current example description and attempts a throttled update.
36
+ def example_started(notification)
37
+ @current = notification.example.full_description
38
+ update
39
+ end
40
+
41
+ # Counts a passed example as completed and attempts a throttled update.
42
+ def example_passed(_notification)
43
+ @completed += 1
44
+ update
45
+ end
46
+
47
+ # Counts a failed example as completed and attempts a throttled update.
48
+ def example_failed(_notification)
49
+ @completed += 1
50
+ @failed += 1
51
+ update
52
+ end
53
+
54
+ # Counts a pending example as completed and attempts a throttled update.
55
+ def example_pending(_notification)
56
+ @completed += 1
57
+ @pending += 1
58
+ update
59
+ end
60
+
61
+ # Emits the final state, counts, and duration from RSpec's summary.
62
+ # Final output bypasses throttling and omits progress.
63
+ def dump_summary(notification)
64
+ active_exception = $!
65
+ @summarized = true
66
+ state = final_state(notification, active_exception)
67
+ outcome = { "done" => "Completed", "error" => "Failed", "idle" => "Stopped" }.fetch(state)
68
+ message = "#{outcome}: #{notification.totals_line} in #{notification.formatted_duration}"
69
+ message += " (dry run)" if RSpec.configuration.dry_run
70
+ @writer.emit(state: state, msg: message)
71
+ end
72
+
73
+ # Reports an incomplete run if it started without reaching a summary.
74
+ def close(_notification)
75
+ return if @summarized || !@started || @closed
76
+
77
+ @closed = true
78
+ @writer.emit(state: "error", msg: "Incomplete: #{@completed}/#{@total} examples")
79
+ end
80
+
81
+ private
82
+
83
+ def update
84
+ now = @clock.call
85
+ return if now - @last_update < 0.1
86
+
87
+ message = "#{@completed}/#{@total} examples"
88
+ message += ", #{@failed} failures" if @failed.positive?
89
+ message += ", #{@pending} pending" if @pending.positive?
90
+ message += ": #{@current}" if @current
91
+ @writer.emit(state: "working", msg: message, progress: progress)
92
+ @last_update = now
93
+ end
94
+
95
+ def progress
96
+ return if @total.zero?
97
+
98
+ ((@completed * 100) / @total).clamp(0, 100)
99
+ end
100
+
101
+ def final_state(summary, active_exception)
102
+ return "idle" if active_exception.is_a?(Interrupt)
103
+ if active_exception.is_a?(SystemExit)
104
+ return "error" if active_exception.status != 0 || summary.failure_count.positive? || summary.errors_outside_of_examples_count.positive?
105
+
106
+ return "idle"
107
+ end
108
+ return "error" if active_exception || summary.errors_outside_of_examples_count.positive?
109
+ if early_stop?
110
+ return "error" if fail_fast_reached?(summary.failure_count)
111
+
112
+ return "idle"
113
+ end
114
+ return "error" if summary.failure_count.positive? || (summary.example_count.zero? && RSpec.configuration.fail_if_no_examples)
115
+
116
+ "done"
117
+ end
118
+
119
+ # RSpec has no public early-stop event in 3.12 or 3.13.
120
+ def early_stop?
121
+ RSpec.world.wants_to_quit
122
+ end
123
+
124
+ def fail_fast_reached?(failure_count)
125
+ threshold = RSpec.configuration.fail_fast
126
+ threshold = 1 if threshold == true
127
+ threshold.is_a?(Integer) && threshold.positive? && failure_count >= threshold
128
+ end
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpec
4
+ module OSC7501
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpec
4
+ module OSC7501
5
+ class Writer # :nodoc: all
6
+ def initialize(output, mode:, title:)
7
+ raise ArgumentError, "RSPEC_OSC7501 must be auto, off, or force" unless %w[auto off force].include?(mode)
8
+
9
+ @output = output
10
+ @enabled = mode == "force" || (mode == "auto" && output.tty?)
11
+ @title = encode(title, 192) if @enabled
12
+ rescue IOError, SystemCallError
13
+ @enabled = false
14
+ end
15
+
16
+ def emit(state:, msg:, progress: nil)
17
+ return unless @enabled
18
+
19
+ fields = ["app=rspec", "title=#{@title}", "state=#{state}", "msg=#{encode(msg, 2048)}"]
20
+ fields << "progress=#{progress.to_i.clamp(0, 100)}" if state == "working" && !progress.nil?
21
+ @output.write("\e]7501;#{fields.join(':')}\e\\")
22
+ rescue IOError, SystemCallError
23
+ @enabled = false
24
+ end
25
+
26
+ private
27
+
28
+ def encode(text, byte_limit)
29
+ clean = text.to_s.encode("UTF-8", invalid: :replace, undef: :replace).gsub(/[\u0000-\u001F\u007F-\u009F]/, "")
30
+ bytes = 0
31
+ bounded = clean.each_char.take_while do |char|
32
+ bytes += char.bytesize
33
+ bytes <= byte_limit
34
+ end.join
35
+ [bounded].pack("m0")
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rspec/core"
4
+ require_relative "osc7501/version"
5
+ require_relative "osc7501/writer"
6
+ require_relative "osc7501/formatter"
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-osc7501
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brian Cosgrove
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rspec-core
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '3.12'
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '4'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '3.12'
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '4'
32
+ description: Reports RSpec suite progress and outcomes through OSC 7501.
33
+ email:
34
+ - cosgroveb@users.noreply.github.com
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - CHANGELOG.md
40
+ - CONTRIBUTING.md
41
+ - LICENSE
42
+ - README.md
43
+ - doc/behavior.rdoc
44
+ - doc/usage.rdoc
45
+ - lib/rspec/osc7501.rb
46
+ - lib/rspec/osc7501/formatter.rb
47
+ - lib/rspec/osc7501/version.rb
48
+ - lib/rspec/osc7501/writer.rb
49
+ homepage: https://github.com/cosgroveb/rspec-osc7501
50
+ licenses:
51
+ - Apache-2.0
52
+ metadata:
53
+ source_code_uri: https://github.com/cosgroveb/rspec-osc7501
54
+ bug_tracker_uri: https://github.com/cosgroveb/rspec-osc7501/issues
55
+ changelog_uri: https://github.com/cosgroveb/rspec-osc7501/blob/main/CHANGELOG.md
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '3.3'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.6.9
71
+ specification_version: 4
72
+ summary: RSpec formatter for OSC 7501 terminal program status
73
+ test_files: []