rspec-ontap 0.3.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6ef09b51496338e3c6b5091d3ce38aecd3020da0
4
- data.tar.gz: d59e58f5b115d74d1ef25fe37491bc0cbd33ae9f
2
+ SHA256:
3
+ metadata.gz: 10b976885cf4cd36799a63b7a795c65282dd6c1253894a56cf845261e9a27245
4
+ data.tar.gz: cebd7367d9c0f08d0f5eb3239ca996cb3dc0e58932ca78e758c919e845eba9cb
5
5
  SHA512:
6
- metadata.gz: 2cc6d1be7dd968bbe18991b72bcc81672a65554101ceb18f61a89023cecc86d0463ceb4ef27f3b3daa8d8cf092a92bf8e705bcaf5ea5a8ab8069c18f5903e36c
7
- data.tar.gz: b1933d4b045be9f482e77f0e8b0e1bfcce2f4bb47e812c939743008dd9ca31e1ce0991dec44709c74f85d37394cb9ed6cc9fe468992cc1ad7f3bbe36a9abc681
6
+ metadata.gz: 645978f6c2cee83351a7c4967b1551a8201e59f74dd0cf01f980a968b842ec75873244a1e2fdb74b8752e7fd774b8f5f2f3f3b0285ca968f0ace5a6859fdacaa
7
+ data.tar.gz: d5fc486c10a307aca61e1ef3ddde26303a8d9b2a57972d669324505f3a12450988a7a124921c0a7bd6b3de3f74de975a96899f6c31915536d3ace47226ab4ed5
data/.yardopts CHANGED
@@ -1,9 +1,8 @@
1
- --title VCLog
1
+ --title "RSpec On Tap"
2
+ --readme README.md
2
3
  --protected
3
4
  --private
4
5
  lib/
5
6
  -
6
7
  *.md
7
8
  *.txt
8
- *.yml
9
-
data/HISTORY.md CHANGED
@@ -1,5 +1,40 @@
1
1
  # Release History
2
2
 
3
+ ## 0.4.0 / 2026-11-22
4
+
5
+ RSpec On Tap runs on current Ruby and RSpec, and tells skipped examples
6
+ from pending ones. It needs Ruby 2.7 or newer and RSpec 3.
7
+
8
+ Changes:
9
+
10
+ * Report an example that was skipped (`skip`, `xit`) with the status
11
+ `omit`. One that is pending, or has no body yet, is still a `todo`.
12
+ All four were `todo` before.
13
+ * Give the reason an example was skipped or is pending, as the message
14
+ of the record's exception section.
15
+ * Report a pending example that passes as a failure, as RSpec does. It
16
+ was reported as an error.
17
+ * Report a failed mock expectation as a failure, too.
18
+ * Pass on what RSpec says outside of an example, such as an error while
19
+ loading a spec file, as a note. It was dropped.
20
+ * Leave out the seed when the examples don't run in random order.
21
+ * No longer raise when a failure's backtrace is empty or names a file
22
+ that can't be read.
23
+ * Require Tapout 0.5 or newer.
24
+ * `RSpec::OnTap::VERSION` gives the version.
25
+ * Replace the old packaging (`.index`, `.gemspec`, `Assembly`,
26
+ `MANIFEST`) with a plain `rspec-ontap.gemspec`, and Travis with GitHub
27
+ Actions, testing Ruby 2.7 to 4.0.
28
+
29
+
30
+ ## 0.3.1 / 2015-07-17
31
+
32
+ Changes:
33
+
34
+ * Fix calls to `relative_path`, which raised NoMethodError for every
35
+ passing and pending example (#2).
36
+
37
+
3
38
  ## 0.3.0 / 2014-01-17
4
39
 
5
40
  This is a major overhaul of the formatter to work with RSpec 3+.
data/README.md CHANGED
@@ -1,66 +1,79 @@
1
1
  # RSpec On Tap
2
2
 
3
- [Homepage](http://rubyworks.github.com/rspec-ontap) |
4
- [Source Code](http://github.com/rubyworks/rspec-ontap) |
5
- [Report Issue](http://github.com/rubyworks/rspec-ontap/issues)
3
+ [Documentation](https://rubydoc.info/gems/rspec-ontap) |
4
+ [Report Issue](https://github.com/rubyworks/rspec-ontap/issues) |
5
+ [Source Code](https://github.com/rubyworks/rspec-ontap)
6
6
 
7
+ [![CI](https://github.com/rubyworks/rspec-ontap/actions/workflows/ci.yml/badge.svg)](https://github.com/rubyworks/rspec-ontap/actions/workflows/ci.yml)
8
+ [![Gem Version](https://badge.fury.io/rb/rspec-ontap.svg)](https://badge.fury.io/rb/rspec-ontap)
7
9
 
8
- ## Description
9
-
10
- **RSpec On Tap** is a TAP-Y/J formatter for RSpec.
11
10
 
12
- The latest version works with **RSpec 3+ only**.
11
+ ## Description
13
12
 
14
- You can learn more about TAP-Y/J [here](https://github.com/rubyworks/tapout).
13
+ **RSpec On Tap** is a pair of formatters for [RSpec](https://rspec.info)
14
+ that report in TAP-Y or TAP-J. Those are the formats that
15
+ [Tapout](https://github.com/rubyworks/tapout) reads, so with RSpec On Tap
16
+ a suite of specs can be shown in any of Tapout's report formats.
15
17
 
18
+ $ rspec -f RSpec::TapY | tapout progress
16
19
 
17
- ## Usage
20
+ It works with RSpec 3, on Ruby 2.7 and newer.
18
21
 
19
- Usage is simply a matter of requiring the plugin and passing the name of the
20
- format class to the `rspec` command via the `-f` option.
21
22
 
22
- $ rspec -r rspec/ontap -f RSpec::TapY spec/*.rb
23
+ ## Installation
23
24
 
24
- This can be shortened to just:
25
+ $ gem install rspec-ontap
25
26
 
26
- $ rspec -f RSpec::TapY spec/*.rb
27
+ Or in a Gemfile:
27
28
 
28
- This works because RSpec will automatically require a related path -- in this
29
- case `rspec/tap_y` -- if the class if initially undefined. The library file
30
- `rspec/tap_y` itself simply requires `rspec/ontap` (the same is true for
31
- `rspec/tap_j`).
29
+ group :test do
30
+ gem "rspec-ontap", :require => false
31
+ end
32
32
 
33
- With TAP-Y output in hand, the `tapout` tool can then be used to produce a
34
- variety of other output formats. First, make sure Tapout is installed:
33
+ Tapout is installed along with it.
35
34
 
36
- $ gem install tapout
37
35
 
38
- Then, for example:
36
+ ## Usage
39
37
 
40
- $ rspec -f RSpec::TapY spec/*.rb | tapout progress
38
+ Give the `rspec` command the name of the formatter with its `-f` option:
39
+ `RSpec::TapY` for TAP-Y, or `RSpec::TapJ` for TAP-J.
41
40
 
42
- See the [TapOut project](http://rubyworks.github.com/tapout) for more information.
41
+ $ rspec -f RSpec::TapY
43
42
 
43
+ Nothing has to be required. When RSpec doesn't know a formatter, it
44
+ requires a file named after it, here `rspec/tap_y`, and that loads the
45
+ formatters. If you'd rather be explicit:
44
46
 
47
+ $ rspec -r rspec/ontap -f RSpec::TapY
45
48
 
46
- ## Installation
49
+ The output is a TAP-Y stream, which isn't meant to be read as it is.
50
+ Pipe it to `tapout`, with the name of the report you want:
47
51
 
48
- Installation follows the usual pattern:
52
+ $ rspec -f RSpec::TapY | tapout progress
49
53
 
50
- $ gem install rspec-ontap
54
+ `tapout --help` lists the reports.
51
55
 
52
- Or using your Gemfile, add something like:
56
+ ### What is reported
53
57
 
54
- group :test do
55
- gem "rspec-ontap", :require => false
56
- end
58
+ * Each example group is a case, nested as the groups are, and each
59
+ example a test.
60
+ * A failure or error comes with its message, the file and line, the
61
+ lines of source around it, and RSpec's backtrace. An expectation that
62
+ wasn't met is a failure; anything else raised is an error.
63
+ * An example that was skipped, with `skip` or `xit`, is reported as
64
+ omitted. One that is pending, or has no body yet, is reported as still
65
+ to be done. Both give the reason.
66
+ * What an example prints to `$stdout` and `$stderr` is captured and
67
+ reported with the example, since it would otherwise break the stream.
68
+ * Anything RSpec says outside of an example, such as an error while
69
+ loading a spec file, is passed on as a note.
57
70
 
58
71
 
59
72
  ## Copyrights
60
73
 
61
74
  Copyright (c) 2011 Rubyworks. All Rights Reserved.
62
75
 
63
- RSpecOnTap is distributable in accordance with the *FreeBSD* license.
76
+ RSpec On Tap is distributable in accordance with the *BSD-2-Clause*
77
+ license.
64
78
 
65
79
  See LICENSE.txt for details.
66
-
data/demo/01_tapy.md ADDED
@@ -0,0 +1,104 @@
1
+ # TAP-Y
2
+
3
+ Given a spec file:
4
+
5
+ RSpec.describe "Example" do
6
+ it "passes" do
7
+ expect(1).to eq(1)
8
+ end
9
+
10
+ it "fails" do
11
+ expect(1).to eq(2)
12
+ end
13
+
14
+ it "errors" do
15
+ raise "oops"
16
+ end
17
+ end
18
+
19
+ Running it with the `RSpec::TapY` formatter gives a TAP-Y stream. RSpec
20
+ finds the formatter by its name, so nothing has to be required.
21
+
22
+ stream = run_tapy
23
+
24
+ There are six documents in it.
25
+
26
+ stream.size #=> 6
27
+
28
+ The first is the `suite`, with the number of examples.
29
+
30
+ stream.first['type'] #=> 'suite'
31
+ stream.first['count'] #=> 3
32
+ stream.first['rev'] #=> 4
33
+
34
+ The second is a `case`, for the example group.
35
+
36
+ stream[1]['type'] #=> 'case'
37
+ stream[1]['subtype'] #=> 'describe'
38
+ stream[1]['label'] #=> 'Example'
39
+ stream[1]['level'] #=> 0
40
+
41
+ The next three are the examples.
42
+
43
+ tests = tests(stream)
44
+
45
+ tests.keys #=> ['passes', 'fails', 'errors']
46
+
47
+ Each says where it is in the spec file.
48
+
49
+ passing = tests['passes']
50
+
51
+ passing['status'] #=> 'pass'
52
+ passing['subtype'] #=> 'it'
53
+ passing['file'] #=> './spec/example_spec.rb'
54
+ passing['line'] #=> 2
55
+ passing['source'] #=> 'it "passes" do'
56
+
57
+ passing.key?('exception') #=> false
58
+
59
+ An expectation that isn't met is a failure. It says what was expected
60
+ and what came back, and where.
61
+
62
+ failing = tests['fails']
63
+
64
+ failing['status'] #=> 'fail'
65
+ failing['expected'] #=> '2'
66
+ failing['returned'] #=> '1'
67
+
68
+ failing['exception']['class'] #=> 'RSpec::Expectations::ExpectationNotMetError'
69
+ failing['exception']['file'] #=> './spec/example_spec.rb'
70
+ failing['exception']['line'] #=> 7
71
+ failing['exception']['source'] #=> 'expect(1).to eq(2)'
72
+
73
+ failing['exception']['message'].assert.include?('expected: 2')
74
+
75
+ It comes with the lines around the failure.
76
+
77
+ failing['exception']['snippet'].map { |line| line.keys.first } #=> [5, 6, 7, 8, 9]
78
+ failing['exception']['snippet'][2][7] #=> ' expect(1).to eq(2)'
79
+
80
+ Anything else raised is an error.
81
+
82
+ erring = tests['errors']
83
+
84
+ erring['status'] #=> 'error'
85
+ erring['exception']['class'] #=> 'RuntimeError'
86
+ erring['exception']['message'] #=> 'oops'
87
+ erring['exception']['line'] #=> 11
88
+
89
+ erring['exception']['backtrace'].first.assert.start_with?('./spec/example_spec.rb:11')
90
+
91
+ The last document is the `final` one, with the counts.
92
+
93
+ stream.last['type'] #=> 'final'
94
+ stream.last['counts'] #=> {'total'=>3, 'pass'=>1, 'fail'=>1, 'error'=>1, 'omit'=>0, 'todo'=>0}
95
+
96
+ The stream ends with the YAML end-of-document marker.
97
+
98
+ @stdout.lines.last #=> "...\n"
99
+
100
+ Nothing else is written, and the exit status still tells of the
101
+ failures.
102
+
103
+ @stderr #=> ''
104
+ @status.success? #=> false
data/demo/02_tapj.md ADDED
@@ -0,0 +1,35 @@
1
+ # TAP-J
2
+
3
+ Given a spec file:
4
+
5
+ RSpec.describe "Example" do
6
+ it "passes" do
7
+ expect(1).to eq(1)
8
+ end
9
+
10
+ it "fails" do
11
+ expect(1).to eq(2)
12
+ end
13
+ end
14
+
15
+ The `RSpec::TapJ` formatter gives a TAP-J stream: the same records as
16
+ TAP-Y, as a JSON document on each line.
17
+
18
+ stream = run_tapj
19
+
20
+ stream.map { |d| d['type'] } #=> ['suite', 'case', 'test', 'test', 'final']
21
+
22
+ tests = tests(stream)
23
+
24
+ tests['passes']['status'] #=> 'pass'
25
+ tests['fails']['status'] #=> 'fail'
26
+ tests['fails']['exception']['file'] #=> './spec/example_spec.rb'
27
+ tests['fails']['exception']['line'] #=> 7
28
+
29
+ stream.last['counts'] #=> {'total'=>2, 'pass'=>1, 'fail'=>1, 'error'=>0, 'omit'=>0, 'todo'=>0}
30
+
31
+ The formatters can also be loaded by requiring `rspec/ontap`.
32
+
33
+ stream = run_specs('-r', 'rspec/ontap', '-f', 'RSpec::TapJ').lines
34
+
35
+ stream.size #=> 5
@@ -0,0 +1,57 @@
1
+ # Skipped and pending examples
2
+
3
+ Given a spec file:
4
+
5
+ RSpec.describe "Example" do
6
+ it "is skipped" do
7
+ skip "not on this machine"
8
+ end
9
+
10
+ xit "is crossed out" do
11
+ expect(1).to eq(2)
12
+ end
13
+
14
+ it "is pending" do
15
+ pending "waiting on a fix"
16
+ expect(1).to eq(2)
17
+ end
18
+
19
+ it "is yet to be written"
20
+
21
+ it "was pending" do
22
+ pending "waiting on a fix"
23
+ expect(1).to eq(1)
24
+ end
25
+ end
26
+
27
+ RSpec calls all of the first four pending. TAP-Y/J tells them apart.
28
+
29
+ stream = run_tapy
30
+ tests = tests(stream)
31
+
32
+ An example that was skipped is omitted, with the reason.
33
+
34
+ tests['is skipped']['status'] #=> 'omit'
35
+ tests['is skipped']['exception']['message'] #=> 'not on this machine'
36
+
37
+ tests['is crossed out']['status'] #=> 'omit'
38
+ tests['is crossed out']['exception']['message'] #=> 'Temporarily skipped with xit'
39
+
40
+ An example that is pending, or has no body yet, is still to be done.
41
+
42
+ tests['is pending']['status'] #=> 'todo'
43
+ tests['is pending']['exception']['message'] #=> 'waiting on a fix'
44
+
45
+ tests['is yet to be written']['status'] #=> 'todo'
46
+ tests['is yet to be written']['exception']['message'] #=> 'Not yet implemented'
47
+
48
+ A pending example that passes is a failure, as it is to RSpec, and not
49
+ an error.
50
+
51
+ tests['was pending']['status'] #=> 'fail'
52
+
53
+ tests['was pending']['exception']['message'].assert.include?('it passed')
54
+
55
+ The counts agree.
56
+
57
+ stream.last['counts'] #=> {'total'=>5, 'pass'=>0, 'fail'=>1, 'error'=>0, 'omit'=>2, 'todo'=>2}
@@ -0,0 +1,115 @@
1
+ # Details
2
+
3
+ ## Nested groups
4
+
5
+ Given a spec file:
6
+
7
+ RSpec.describe "Outer" do
8
+ it "one" do
9
+ expect(1).to eq(1)
10
+ end
11
+
12
+ context "inner" do
13
+ it "two" do
14
+ expect(2).to eq(2)
15
+ end
16
+
17
+ describe "innermost" do
18
+ it "three" do
19
+ expect(3).to eq(3)
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ RSpec.describe "Another" do
26
+ it "four" do
27
+ expect(4).to eq(4)
28
+ end
29
+ end
30
+
31
+ Each group is a case, and its level says how deep it is.
32
+
33
+ stream = run_tapy
34
+
35
+ cases = stream.select { |d| d['type'] == 'case' }
36
+
37
+ cases.map { |d| [d['label'], d['level']] } #=> [['Outer', 0], ['inner', 1], ['innermost', 2], ['Another', 0]]
38
+
39
+ stream.map { |d| d['type'] } #=> ['suite', 'case', 'test', 'case', 'test', 'case', 'test', 'case', 'test', 'final']
40
+
41
+ ## Output from examples
42
+
43
+ Given a spec file:
44
+
45
+ RSpec.describe "Example" do
46
+ it "is noisy" do
47
+ puts "to stdout"
48
+ warn "to stderr"
49
+ end
50
+
51
+ it "is quiet" do
52
+ end
53
+
54
+ it "is noisy and fails" do
55
+ puts "before failing"
56
+ expect(1).to eq(2)
57
+ end
58
+ end
59
+
60
+ What an example prints would break the stream. It is captured and
61
+ becomes part of the example's record.
62
+
63
+ stream = run_tapy
64
+ tests = tests(stream)
65
+
66
+ tests['is noisy']['stdout'] #=> 'to stdout'
67
+ tests['is noisy']['stderr'] #=> 'to stderr'
68
+
69
+ tests['is quiet'].key?('stdout') #=> false
70
+ tests['is quiet'].key?('stderr') #=> false
71
+
72
+ tests['is noisy and fails']['stdout'] #=> 'before failing'
73
+
74
+ @stderr #=> ''
75
+
76
+ ## The seed
77
+
78
+ When the examples run in random order, the seed is in the `suite`
79
+ document.
80
+
81
+ stream = run_tapy('--seed', '42')
82
+
83
+ stream.first['seed'] #=> 42
84
+
85
+ Otherwise there is none.
86
+
87
+ stream = run_tapy
88
+
89
+ stream.first['seed'] #=> nil
90
+
91
+ ## A spec file that can't be loaded
92
+
93
+ Given a spec file:
94
+
95
+ RSpec.describe "Example" do
96
+ it "passes" do
97
+ expect(1).to eq(1)
98
+ end
99
+ end
100
+
101
+ raise "can't go on"
102
+
103
+ What RSpec has to say about it becomes a note, after the `suite`
104
+ document that has to begin the stream. (RSpec reports such an error
105
+ from version 3.6. Before that it let the error end the run.)
106
+
107
+ if Gem.loaded_specs['rspec-core'].version >= Gem::Version.new('3.6')
108
+ stream = run_tapy
109
+
110
+ stream.map { |d| d['type'] }.assert == ['suite', 'note', 'final']
111
+
112
+ stream[1]['text'].assert.include?("can't go on")
113
+
114
+ @status.refute.success?
115
+ end
data/demo/05_tapout.md ADDED
@@ -0,0 +1,45 @@
1
+ # Tapout
2
+
3
+ The stream is for Tapout, which renders it in a format of your choice.
4
+
5
+ Given a spec file:
6
+
7
+ RSpec.describe "Example" do
8
+ it "passes" do
9
+ expect(1).to eq(1)
10
+ end
11
+
12
+ it "fails" do
13
+ expect(1).to eq(2)
14
+ end
15
+
16
+ it "errors" do
17
+ raise NameError, "oops"
18
+ end
19
+
20
+ it "is skipped" do
21
+ skip "not today"
22
+ end
23
+
24
+ it "is yet to be written"
25
+ end
26
+
27
+ Tapout reads the TAP-Y stream.
28
+
29
+ out = tapout(run_specs('-f', 'RSpec::TapY'), 'tap')
30
+
31
+ out.assert.include?('1..5')
32
+
33
+ out.assert =~ /^ok 1 - passes$/
34
+ out.assert =~ /^not ok 2 - fails$/
35
+ out.assert =~ /^not ok 3 - errors$/
36
+ out.assert =~ /^ok 4 - is skipped # SKIP not today$/
37
+ out.assert =~ /^not ok 5 - is yet to be written # TODO Not yet implemented$/
38
+
39
+ And the TAP-J stream.
40
+
41
+ out = tapout(run_specs('-f', 'RSpec::TapJ'), 'tap')
42
+
43
+ out.assert =~ /^ok 1 - passes$/
44
+ out.assert =~ /^not ok 2 - fails$/
45
+ out.assert =~ /^ok 4 - is skipped # SKIP not today$/
@@ -0,0 +1 @@
1
+ require 'ae'
@@ -0,0 +1,49 @@
1
+ require 'tmpdir'
2
+ require 'open3'
3
+ require 'rbconfig'
4
+ require 'yaml'
5
+ require 'json'
6
+
7
+ # Each demo writes a spec file and runs it with the `rspec` command, in
8
+ # a process of its own.
9
+
10
+ LIB = File.expand_path('../../lib', __dir__)
11
+
12
+ When 'iven a spec file' do |text|
13
+ @source = text
14
+ end
15
+
16
+ # Run the spec file with the given command line options. Returns what
17
+ # the run wrote to standard output.
18
+ def run_specs(*options)
19
+ rspec = Gem.bin_path('rspec-core', 'rspec')
20
+ Dir.mktmpdir('rspec-ontap') do |dir|
21
+ Dir.mkdir(File.join(dir, 'spec'))
22
+ File.write(File.join(dir, 'spec', 'example_spec.rb'), @source)
23
+ command = [RbConfig.ruby, rspec, "-I#{LIB}", '--no-color', *options]
24
+ @stdout, @stderr, @status = Open3.capture3(*command, :chdir => dir)
25
+ end
26
+ @stdout
27
+ end
28
+
29
+ # Run the spec file and read its output as a TAP-Y stream.
30
+ def run_tapy(*options)
31
+ YAML.load_stream(run_specs('-f', 'RSpec::TapY', *options))
32
+ end
33
+
34
+ # Run the spec file and read its output as a TAP-J stream.
35
+ def run_tapj(*options)
36
+ run_specs('-f', 'RSpec::TapJ', *options).lines.map { |line| JSON.parse(line) }
37
+ end
38
+
39
+ # The test records of a stream, by label.
40
+ def tests(stream)
41
+ stream.select { |d| d['type'] == 'test' }.to_h { |d| [d['label'], d] }
42
+ end
43
+
44
+ # Pipe a stream through Tapout. Returns what Tapout printed.
45
+ def tapout(stream, reporter)
46
+ bin = Gem.bin_path('tapout', 'tapout')
47
+ out, _ = Open3.capture2(RbConfig.ruby, bin, reporter, :stdin_data => stream)
48
+ out
49
+ end
@@ -0,0 +1,5 @@
1
+ module RSpec
2
+ module OnTap
3
+ VERSION = '0.4.0'
4
+ end
5
+ end