rubytest 0.10.0 → 0.11.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
2
  SHA256:
3
- metadata.gz: 87813efd760c9e9e813d32fe22a048da1c82e47bf580420892942931008039ba
4
- data.tar.gz: 4f8c2918e8885f5a29f144d1315135ce61a44016711b4289e0419f7b8dfff02e
3
+ metadata.gz: 97dcdf49dd86b82c62193f72bb232f37cfa8e8046b84d42e592c7299cf215678
4
+ data.tar.gz: 5b16f6f571348f0688fb8365433f20ba142b47373e93898fd1f1ad9e5749d3da
5
5
  SHA512:
6
- metadata.gz: 6d91841470661e6bfdc0131d970723154d6c6ff6eb18da980e4a4b205f43a1f5134192e73fef2430dbbe6f77b71d297d4b25db5c29ff5972a1179e0e3c155075
7
- data.tar.gz: cc2829ce1797a428386e37cf2ab98a11f575ea0848e215ca3f65f19665d5e36057f0d8fd5ac488746bf43a0df1b7b9a275375791138a8693a0b18ce0021cd8e1
6
+ metadata.gz: c505c432de946e79b37c461daf9ac3204758adf1f04fcd579d55d15d85522e480d21c933864ebbb4382e003f87f740ee651b57eb65340cb0cc7b82210d52a709
7
+ data.tar.gz: 1f9073050a320ee5faa7ae37f73714b8ff76bc9b51c47572b2dd6105a2bc6a491d90ac5980a9b9d11cafe43cd334c15fb9dbadd9d1694f04b35a408aa7dfa095
data/HISTORY.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # RELEASE HISTORY
2
2
 
3
+ ## 0.11.0 / 2026-11-17
4
+
5
+ The Rake task and the HTML reporter are back in Rubytest, so rubytest-rake
6
+ and rubytest-html are no longer needed. With this, everything that was spun
7
+ off into a separate gem is part of Rubytest again.
8
+
9
+ Changes:
10
+
11
+ * Bring the HTML reporter in from rubytest-html, rewritten for the recorder:
12
+ `rubytest -f html`. It escapes what it writes, reports skipped tests and
13
+ cases, and shows captured output with each test.
14
+ * Bring the Rake task in from rubytest-rake: `require 'rubytest/rake'` for
15
+ `Test::Rake::TestTask`. The task now fails when the run does (it always
16
+ exited 0), runs only the default globs that match a file, and lets `TEST`
17
+ replace the task's files for one invocation.
18
+
3
19
  ## 0.10.0 / 2026-11-17
4
20
 
5
21
  Results now go through a recorder to the reporters, and the reporters that
data/README.md CHANGED
@@ -58,8 +58,10 @@ test), `outline` (nested cases), `progress` (running count and timing), `tap`
58
58
  (TAP version 13), and `tapy` and `tapj` (TAP-Y and TAP-J, the structured
59
59
  streams that [tapout](https://github.com/rubyworks/tapout) reads). Select one
60
60
  with `rubytest -f FORMAT`; `-y` and `-j` are short for `-f tapy` and `-f tapj`.
61
- Formats load only when selected. The TAP formats capture test output: TAP
62
- emits it as diagnostics, and TAP-Y and TAP-J record it with each test.
61
+ `html` writes the whole run as one self-contained HTML document
62
+ (`rubytest -f html > report.html`). Formats load only when selected. The TAP
63
+ and HTML formats capture test output: TAP emits it as diagnostics, and TAP-Y,
64
+ TAP-J and HTML record it with each test.
63
65
 
64
66
 
65
67
  ## Installation
@@ -122,8 +124,31 @@ named profile, use the `-p/--profile` option:
122
124
  The configuration file can also be at `config/test.rb`, `Testfile`,
123
125
  or `.test` (with optional `.rb` extension).
124
126
 
125
- If you are using Rake, shelling out to `rubytest` keeps your test
126
- environment pristine:
127
+ ### Via Rake
128
+
129
+ Rubytest has a Rake task. In your Rakefile:
130
+
131
+ require 'rubytest/rake'
132
+
133
+ Test::Rake::TestTask.new do |run|
134
+ run.loadpath 'lib'
135
+ run.test_files << 'test/*_test.rb'
136
+ end
137
+
138
+ The block takes the same settings as `Test.configure`. With no files, the
139
+ task runs whichever of `test/**/test_*.rb`, `*_test.rb`, `case_*.rb` and
140
+ `*_case.rb` it finds, and with no load path it adds `lib`. The task is named
141
+ `test` unless you give it another name (`TestTask.new('spec')`).
142
+
143
+ To run only some tests for one invocation, set `TEST`:
144
+
145
+ $ rake test TEST=test/foo_test.rb
146
+
147
+ Where the platform can fork, the tests run in a child process, so what they
148
+ load stays out of Rake's. `rake test` fails if the run does.
149
+
150
+ A configuration file isn't read by the task. To use one, shell out to
151
+ `rubytest` instead:
127
152
 
128
153
  desc "run tests"
129
154
  task :test do
@@ -116,3 +116,27 @@ The command line has a shortcut for each.
116
116
  cli.options.parse!([flag])
117
117
  cli.format.assert == format
118
118
  end
119
+
120
+ The HTML format writes one self-contained document once the run has
121
+ finished. Names, messages and captured output are escaped.
122
+
123
+ markup = probe_type.new('markup <b>&</b>') { print '<script>'; true }
124
+ html_suite = [Class.new(Array) { def to_s; 'a <case>'; end }.new([markup, failing]),
125
+ pending, skipped, skipped_case, broken_case]
126
+ success, output, report = render.call('html', html_suite)
127
+ success.assert == false
128
+
129
+ output.lines.first.chomp.assert == '<!DOCTYPE html>'
130
+ output.lines.last.chomp.assert == '</html>'
131
+ output.scan('<div class="result ').size.assert == report.total
132
+ output.scan('<section class="case">').size.assert == output.scan('</section>').size
133
+ %w[pass fail error todo skip].each do |status|
134
+ output.include?(%[<div class="result #{status}">]).assert == true
135
+ end
136
+
137
+ output.include?('markup &lt;b&gt;&amp;&lt;/b&gt;').assert == true
138
+ output.include?('<h2>a &lt;case&gt;</h2>').assert == true
139
+ output.include?('<pre class="stdout">&lt;script&gt;</pre>').assert == true
140
+ output.include?('<script>').assert == false
141
+ output.include?('Assertion: ').assert == true
142
+ output.include?('6 tests: 1 passing, 1 failures, 1 errors, 1 pending, 2 skipped.').assert == true
@@ -0,0 +1,87 @@
1
+ ## Rake task
2
+
3
+ `rubytest/rake` provides a task for running tests from a Rakefile.
4
+
5
+ require 'rubytest/rake'
6
+ require 'tmpdir'
7
+
8
+ project = Dir.mktmpdir('rubytest-rake')
9
+ Dir.mkdir(File.join(project, 'test'))
10
+
11
+ probe = lambda do |label, body|
12
+ <<-RUBY
13
+ probe = Object.new
14
+ probe.define_singleton_method(:call) { #{body} }
15
+ probe.define_singleton_method(:to_s) { #{label.inspect} }
16
+ $TEST_SUITE << probe
17
+ RUBY
18
+ end
19
+
20
+ File.write(File.join(project, 'test', 'good_test.rb'), probe.call('good', 'true'))
21
+ File.write(File.join(project, 'bad.rb'), probe.call('bad', "raise Assertion, 'wrong value'"))
22
+
23
+ status_of = lambda do |task|
24
+ Dir.chdir(project) do
25
+ begin
26
+ task.run
27
+ 0
28
+ rescue SystemExit => exit
29
+ exit.status
30
+ end
31
+ end
32
+ end
33
+
34
+ The block configures the run, as with `Test.configure`. The task is an
35
+ ordinary Rake task.
36
+
37
+ passing = Test::Rake::TestTask.new('demo:pass') do |run|
38
+ run.files << 'test/good_test.rb'
39
+ run.format = 'test'
40
+ end
41
+
42
+ Rake::Task.task_defined?('demo:pass').assert == true
43
+ status_of.call(passing).assert == 0
44
+
45
+ A run that fails makes the task exit with status 1, so that `rake` fails too.
46
+
47
+ failing = Test::Rake::TestTask.new('demo:fail') do |run|
48
+ run.files << 'bad.rb'
49
+ run.format = 'test'
50
+ end
51
+
52
+ status_of.call(failing).assert == 1
53
+
54
+ Given no files, the task looks under `test/` for files named `test_*.rb`,
55
+ `*_test.rb`, `case_*.rb` or `*_case.rb`, and runs whichever of those it
56
+ finds. It also puts `lib` on the load path.
57
+
58
+ defaults = Test::Rake::TestTask.new('demo:defaults') { |run| run.format = 'test' }
59
+
60
+ status_of.call(defaults).assert == 0
61
+ defaults.config.files.assert == ['test/**/*_test.rb']
62
+ defaults.config.loadpath.assert == ['lib']
63
+
64
+ If it finds none, it says so.
65
+
66
+ empty = Dir.mktmpdir('rubytest-rake-empty')
67
+ nothing = Test::Rake::TestTask.new('demo:nothing') { |run| run.format = 'test' }
68
+ missing = begin
69
+ Dir.chdir(empty) { nothing.run }
70
+ nil
71
+ rescue ArgumentError => error
72
+ error
73
+ end
74
+
75
+ missing.message.assert.start_with?('no test files found')
76
+
77
+ The `TEST` environment variable selects the tests for one invocation, in
78
+ place of the task's own.
79
+
80
+ previous = ENV['TEST']
81
+ begin
82
+ ENV['TEST'] = 'bad.rb'
83
+ status_of.call(passing).assert == 1
84
+ passing.config.files.assert == ['bad.rb']
85
+ ensure
86
+ ENV['TEST'] = previous
87
+ end
@@ -0,0 +1,144 @@
1
+ # encoding: UTF-8
2
+
3
+ module Test::Reporters
4
+
5
+ # HTML Test Reporter
6
+ #
7
+ # Writes the run as one self-contained HTML document, once the run has
8
+ # finished: a tally, then every result under the heading of its case.
9
+ # Test output is captured and shown with the test that wrote it.
10
+ #
11
+ class Html < Abstract
12
+
13
+ LABELS = {
14
+ :pass => 'PASS',
15
+ :fail => 'FAIL',
16
+ :error => 'ERROR',
17
+ :todo => 'TODO',
18
+ :skip => 'SKIP'
19
+ }
20
+
21
+ ESCAPES = {
22
+ '&' => '&amp;', '<' => '&lt;', '>' => '&gt;', '"' => '&quot;', "'" => '&#39;'
23
+ }
24
+
25
+ STYLE = <<-CSS
26
+ :root { color-scheme: light dark; --pass: #1a7f37; --fail: #cf222e; --todo: #9a6700; --skip: #57606a; --line: #d0d7de; }
27
+ @media (prefers-color-scheme: dark) { :root { --pass: #3fb950; --fail: #f85149; --todo: #d29922; --skip: #8b949e; --line: #30363d; } }
28
+ body { font-family: system-ui, sans-serif; line-height: 1.5; max-width: 60rem; margin: 2rem auto; padding: 0 1rem; }
29
+ h1 { margin-bottom: 0.25rem; }
30
+ .tally { font-weight: bold; }
31
+ .tally.passed { color: var(--pass); }
32
+ .tally.failed { color: var(--fail); }
33
+ section { border-left: 2px solid var(--line); padding-left: 1rem; margin: 1rem 0; }
34
+ .result { margin: 0.25rem 0; }
35
+ .status { display: inline-block; min-width: 3.5rem; font: bold 0.85em ui-monospace, monospace; }
36
+ .pass .status { color: var(--pass); }
37
+ .fail .status, .error .status { color: var(--fail); }
38
+ .todo .status { color: var(--todo); }
39
+ .skip .status { color: var(--skip); }
40
+ .time, .reason, footer { color: var(--skip); font-size: 0.85em; }
41
+ pre { margin: 0.25rem 0 0.5rem 3.5rem; padding: 0.5rem; border: 1px solid var(--line); overflow-x: auto; font-size: 0.85em; }
42
+ CSS
43
+
44
+ #
45
+ def initialize(runner, output: $stdout)
46
+ super(runner)
47
+ @output = output
48
+ @body = []
49
+ @depth = 0
50
+ end
51
+
52
+ # Test output would otherwise land in the middle of the document.
53
+ def capture_output?
54
+ true
55
+ end
56
+
57
+ #
58
+ def begin_suite(suite)
59
+ @body = []
60
+ @depth = 0
61
+ end
62
+
63
+ #
64
+ def begin_case(test_case)
65
+ title, *rest = test_case.to_s.strip.split("\n")
66
+ level = [@depth + 2, 6].min
67
+ @body << %[<section class="case">]
68
+ @body << %[<h#{level}>#{h title}</h#{level}>]
69
+ @body << %[<p>#{rest.map{ |line| h(line.strip) }.join('<br>')}</p>] unless rest.empty?
70
+ @depth += 1
71
+ end
72
+
73
+ #
74
+ def end_case(test_case)
75
+ @depth -= 1
76
+ @body << %[</section>]
77
+ end
78
+
79
+ # Add a completed result to the document.
80
+ def record(result)
81
+ label = result.test.to_s.strip.split("\n").first.to_s
82
+ label = "#{label} (case)" if result.kind == :case
83
+
84
+ line = %[<span class="status">#{LABELS.fetch(result.status)}</span> #{h label}]
85
+ line << %[ <span class="reason">#{h result.reason}</span>] if result.status == :skip && result.reason
86
+ line << %[ <span class="reason">#{h result.exception.message}</span>] if result.status == :todo && result.exception
87
+ line << %[ <span class="time">#{'%.5fs' % result.elapsed}</span>]
88
+
89
+ @body << %[<div class="result #{result.status}">#{line}]
90
+ if [:fail, :error].include?(result.status)
91
+ result.exceptions.each{ |exception| @body << %[<pre>#{h detail(exception, result.status == :error)}</pre>] }
92
+ end
93
+ @body << %[<pre class="stdout">#{h result.stdout}</pre>] unless result.stdout.empty?
94
+ @body << %[<pre class="stderr">#{h result.stderr}</pre>] unless result.stderr.empty?
95
+ @body << %[</div>]
96
+ end
97
+
98
+ # Write the document.
99
+ def finish(summary)
100
+ outcome = summary.success? ? 'passed' : 'failed'
101
+ tally = if summary.total.zero?
102
+ 'No tests were run.'
103
+ else
104
+ counts = ::Test::Result::STATUSES.map{ |status| "#{summary.counts[status]} #{TITLES[status]}" }
105
+ "#{summary.total} tests: #{counts.join(', ')}."
106
+ end
107
+
108
+ @output.puts '<!DOCTYPE html>'
109
+ @output.puts '<html lang="en">'
110
+ @output.puts '<head>'
111
+ @output.puts '<meta charset="utf-8">'
112
+ @output.puts '<meta name="viewport" content="width=device-width, initial-scale=1">'
113
+ @output.puts '<title>Test Report</title>'
114
+ @output.puts "<style>\n#{STYLE.gsub(/^ /, '')}</style>"
115
+ @output.puts '</head>'
116
+ @output.puts '<body>'
117
+ @output.puts '<h1>Test Report</h1>'
118
+ @output.puts %[<p class="tally #{outcome}">#{h tally}</p>]
119
+ @output.puts @body.join("\n") unless @body.empty?
120
+ @output.puts %[<footer>Finished in #{'%.5fs' % summary.elapsed}. Generated by Rubytest #{h ::Test::VERSION} on #{h Time.now.strftime('%Y-%m-%d %H:%M:%S')}.</footer>]
121
+ @output.puts '</body>'
122
+ @output.puts '</html>'
123
+ end
124
+
125
+ private
126
+
127
+ # Escape text for use in HTML.
128
+ def h(text)
129
+ text.to_s.gsub(/[&<>"']/, ESCAPES)
130
+ end
131
+
132
+ # An exception's class, message and where it was raised, with the rest
133
+ # of its backtrace if asked.
134
+ def detail(exception, backtrace=false)
135
+ lines = ["#{exception.class}: #{exception.message}"]
136
+ trace = exception.backtrace ? clean_backtrace(exception) : []
137
+ trace = trace.first(1) unless backtrace
138
+ lines.concat(trace.map{ |line| " #{line}" })
139
+ lines.join("\n")
140
+ end
141
+
142
+ end
143
+
144
+ end
@@ -0,0 +1,128 @@
1
+ require 'rubytest'
2
+ require 'rake'
3
+ require 'rake/tasklib'
4
+
5
+ module Test
6
+
7
+ ##
8
+ # Rake subspace.
9
+ #
10
+ module Rake
11
+
12
+ ##
13
+ # Define a rake task that runs tests.
14
+ #
15
+ # require 'rubytest/rake'
16
+ #
17
+ # Test::Rake::TestTask.new do |run|
18
+ # run.loadpath 'lib'
19
+ # run.files << 'test/*_test.rb'
20
+ # end
21
+ #
22
+ # The block is given the task's Test::Config, the same object that
23
+ # `Test.configure` yields. Without any files, the task runs whichever
24
+ # of DEFAULT_TESTS match, and without a load path it adds `lib`.
25
+ #
26
+ # The `TEST` environment variable selects the tests to run for one
27
+ # invocation, in place of the task's own: `rake test TEST=test/foo_test.rb`.
28
+ # Separate several files or globs with `:` or `;`.
29
+ #
30
+ # Where the platform can fork, tests run in a child process, so that
31
+ # what they load doesn't stay in Rake's. If the run is unsuccessful the
32
+ # task exits with status 1.
33
+ #
34
+ class TestTask < ::Rake::TaskLib
35
+
36
+ # Globs used to find test files when the task is given none.
37
+ DEFAULT_TESTS = [
38
+ 'test/**/case_*.rb',
39
+ 'test/**/*_case.rb',
40
+ 'test/**/test_*.rb',
41
+ 'test/**/*_test.rb'
42
+ ]
43
+
44
+ # Name of the task.
45
+ #
46
+ # @return [String]
47
+ attr :name
48
+
49
+ # Test run configuration.
50
+ #
51
+ # @return [Config]
52
+ attr :config
53
+
54
+ # Initialize new Rake::TestTask instance.
55
+ #
56
+ def initialize(name='test', desc='run tests', &block)
57
+ @name = (name || 'test').to_s
58
+ @desc = desc
59
+
60
+ @config = Test::Config.new
61
+
62
+ block.call(@config) if block
63
+
64
+ define_task
65
+ end
66
+
67
+ # Define rake task for testing.
68
+ #
69
+ # @return nothing
70
+ def define_task
71
+ desc @desc
72
+ task @name do
73
+ run
74
+ end
75
+ end
76
+
77
+ # Run tests, in a child process if possible, otherwise in this one.
78
+ # Exits with status 1 if the run is unsuccessful.
79
+ #
80
+ # @return nothing
81
+ def run
82
+ prepare
83
+ success = Process.respond_to?(:fork) ? run_in_fork : run_here
84
+ exit 1 unless success
85
+ end
86
+
87
+ private
88
+
89
+ # Settle the files and load path the run will use.
90
+ def prepare
91
+ if ENV['TEST']
92
+ config.files = ENV['TEST'].split(/[:;]/)
93
+ elsif config.files.empty?
94
+ config.files = default_tests
95
+ end
96
+ config.loadpath << 'lib' if config.loadpath.empty?
97
+ end
98
+
99
+ # The default globs that match at least one file. The runner fails a
100
+ # glob that matches nothing, so the others are left out.
101
+ #
102
+ # @return [Array<String>]
103
+ def default_tests
104
+ base = config.chdir || Dir.pwd
105
+ globs = DEFAULT_TESTS.reject{ |glob| Dir.glob(glob, base: base).empty? }
106
+ if globs.empty?
107
+ raise ArgumentError, "no test files found; looked for #{DEFAULT_TESTS.join(', ')}"
108
+ end
109
+ globs
110
+ end
111
+
112
+ # @return [Boolean] Whether the run was successful.
113
+ def run_here
114
+ Test::Runner.new(config).run
115
+ end
116
+
117
+ # @return [Boolean] Whether the run was successful.
118
+ def run_in_fork
119
+ pid = fork { exit(run_here ? 0 : 1) }
120
+ Process.wait(pid)
121
+ $?.success?
122
+ end
123
+
124
+ end
125
+
126
+ end
127
+
128
+ end
@@ -433,7 +433,7 @@ module Test
433
433
  # TODO: Could use finder gem to look these up, but that's yet another dependency.
434
434
  #
435
435
  KNOWN_FORMATS = %w{
436
- dotprogress progress outline summary tap tapy tapj test
436
+ dotprogress progress outline summary tap tapy tapj html test
437
437
  }
438
438
 
439
439
  # Returns a list of available report types.
data/lib/rubytest.rb CHANGED
@@ -6,7 +6,7 @@ $RUBY_IGNORE_CALLERS = [] unless defined?($RUBY_IGNORE_CALLERS)
6
6
  require 'ansi/core'
7
7
 
8
8
  module Test
9
- VERSION = '0.10.0'
9
+ VERSION = '0.11.0'
10
10
  end
11
11
 
12
12
  require_relative 'rubytest/core_ext'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubytest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trans
@@ -83,6 +83,7 @@ files:
83
83
  - demo/03_runner_reliability.md
84
84
  - demo/04_result_pipeline.md
85
85
  - demo/05_builtin_reporters.md
86
+ - demo/06_rake_task.md
86
87
  - demo/applique/ae.rb
87
88
  - demo/applique/rubytest.rb
88
89
  - lib/rubytest.rb
@@ -99,6 +100,7 @@ files:
99
100
  - lib/rubytest/format/abstract.rb
100
101
  - lib/rubytest/format/abstract_hash.rb
101
102
  - lib/rubytest/format/dotprogress.rb
103
+ - lib/rubytest/format/html.rb
102
104
  - lib/rubytest/format/outline.rb
103
105
  - lib/rubytest/format/progress.rb
104
106
  - lib/rubytest/format/summary.rb
@@ -106,6 +108,7 @@ files:
106
108
  - lib/rubytest/format/tapj.rb
107
109
  - lib/rubytest/format/tapy.rb
108
110
  - lib/rubytest/format/test.rb
111
+ - lib/rubytest/rake.rb
109
112
  - lib/rubytest/recorder.rb
110
113
  - lib/rubytest/result.rb
111
114
  - lib/rubytest/runner.rb