Skip to content

Commit b8062ba

Browse files
committed
allow writing to a different runtime log for minitest and clarify readme
1 parent 2c97ebe commit b8062ba

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

Readme.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Test groups will often run for different times, making the full test run as slow
129129

130130
**Step 1**: Use these loggers (see below) to record test runtime
131131

132-
**Step 2**: The next test run will use the recorded test runtimes (use `--runtime-log <file>` if you picked a location different from below)
132+
**Step 2**: The next test run will use the recorded test runtimes (use `--runtime-log <file>` if you wrote to a location different from default)
133133

134134
**Step 3**: Automate upload/download of test runtime from your CI system [example](https://github.com/grosser/parallel_rails_example/blob/master/.github/workflows/test.yml) (chunks need to be combined, an alternative is [amend](https://github.com/grosser/amend))
135135

@@ -140,17 +140,17 @@ Rspec: Add to your `.rspec_parallel` (or `.rspec`), but can also be used via `--
140140
--format progress
141141
--format ParallelTests::RSpec::RuntimeLogger --out tmp/parallel_runtime_rspec.log
142142

143-
To use a custom logfile location (default: `tmp/parallel_runtime_rspec.log`), use the CLI: `parallel_test spec -t rspec --runtime-log my.log`
144-
145143
### Minitest
146144

147145
Add to your `test_helper.rb`:
148146
```ruby
149-
require 'parallel_tests/test/runtime_logger' if ENV['RECORD_RUNTIME']
147+
if ENV['RECORD_RUNTIME']
148+
require 'parallel_tests/test/runtime_logger'
149+
# ParallelTests::Test::RuntimeLogger.logfile = "tmp/parallel_runtime_test.log" # where to write it
150+
end
150151
```
151152

152-
results will be logged to `tmp/parallel_runtime_test.log` when `RECORD_RUNTIME` is set,
153-
so it is not always required or overwritten.
153+
results will be logged when `RECORD_RUNTIME` is set, so it is not always required or overwritten.
154154

155155
Loggers
156156
=======

lib/parallel_tests/test/runtime_logger.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class RuntimeLogger
88
@@prepared = false
99

1010
class << self
11+
attr_writer :logfile
12+
1113
def log_test_run(test)
1214
prepare
1315

@@ -66,7 +68,7 @@ def message(test, delta)
6668
end
6769

6870
def logfile
69-
ParallelTests::Test::Runner.runtime_log
71+
@logfile || ParallelTests::Test::Runner.runtime_log
7072
end
7173
end
7274
end

spec/parallel_tests/test/runtime_logger_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,28 @@ def test_foo
5151
)
5252
end
5353
end
54+
55+
it "can write to a custom location" do
56+
skip if RUBY_PLATFORM == "java" # just too slow ...
57+
repo_root = Dir.pwd
58+
59+
use_temporary_directory do
60+
FileUtils.mkdir "test"
61+
File.write("test/a_test.rb", <<-RUBY)
62+
require 'minitest/autorun'
63+
require 'parallel_tests/test/runtime_logger'
64+
ParallelTests::Test::RuntimeLogger.logfile = "foo.log"
65+
66+
class Bar < Minitest::Test
67+
def test_foo
68+
assert true
69+
end
70+
end
71+
RUBY
72+
73+
run_tests(repo_root)
74+
75+
expect(File.exist?("foo.log")).to eq(true)
76+
end
77+
end
5478
end

0 commit comments

Comments
 (0)