ask-ruby-harness 0.3.0 → 0.3.1

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: d70bd6e8f4bbf2d01ad1e3b68a49ca668edb25730dc7473690815a4416de02bd
4
- data.tar.gz: c3e5f670a81444bc2022a32d57ea64f0ab09435b6d49a2e31333607b0d758850
3
+ metadata.gz: b57d0a2408bc2432ed17401048b318263ac9e11709d73cd4eba7b2b47d2e9997
4
+ data.tar.gz: 910fa5fdc3a9a8da190fe05bd5326698043f4615853f3908648c05df55316d51
5
5
  SHA512:
6
- metadata.gz: 5f973f3223d742de9f530bd2eaf91f70ef5ed2e6ec0376a5103d9ea6683401bc5002934dd1aa5ffa0731bf4e6fffe387d4f11a4e180258d61439bfbc7955bd73
7
- data.tar.gz: b8326c07280c08a863073d8c01db0e90688799eef058dc63a5ecb44d268c6f153fb70de3db28795c2265a10602a7ad3a3dcc0cb609eec0aa007ee448895bba96
6
+ metadata.gz: 184e86499d3e1eede9de25e6ee241dc01dfaa2f504ae5de616c7e64cf845b83f12ee2e7681e55b7310078e72435db14f7a806e2526dcced4d70c298cecbb7518
7
+ data.tar.gz: 49e9aae381d3d619787f1420f103b1d09732de6370cb43dc367b5d2d82e8cb6f1043394e449812f53abbe13faff70aa3dd1761a020f8d556f41077e477a2942a
@@ -30,6 +30,14 @@ module Ask
30
30
  files = files.map { |f| rel_to_run_root(f, run_root) }
31
31
  runner = detect_runner(run_root)
32
32
 
33
+ # rake test only takes files (TEST env); expand directory args to
34
+ # their *_test.rb files. Rails and rspec expand dirs natively.
35
+ if runner == :minitest
36
+ expanded = expand_minitest_directories(files, run_root)
37
+ return expanded unless expanded.is_a?(Array)
38
+ files = expanded
39
+ end
40
+
33
41
  failed_tests = failed_only ? load_failed_tests(run_root) : nil
34
42
  if failed_only && failed_tests.empty?
35
43
  return Ask::Result.failure("No failed tests from the previous run to rerun.")
@@ -40,6 +48,10 @@ module Ask
40
48
  json_path = artifact_dir.join("last-test.json")
41
49
  status_path = artifact_dir.join("last-failures.json")
42
50
 
51
+ # A child that produces no JSON must not be masked by a previous
52
+ # run's stale file — parse_results only looks at this path.
53
+ json_path.delete if json_path.exist?
54
+
43
55
  command, env = build_command(runner, files, name, failed_tests, json_path)
44
56
  outcome = run(command, env, log_path, timeout, run_root)
45
57
 
@@ -101,6 +113,25 @@ module Ask
101
113
  Pathname.new(File.expand_path(file, app_root)).relative_path_from(run_root).to_s
102
114
  end
103
115
 
116
+ # rake_test_loader requires each arg as a file — a directory arg
117
+ # explodes ("cannot load such file -- .../test"). Replace directory
118
+ # args with the *_test.rb files under them (relative to run_root),
119
+ # mirroring the standard Rake::TestTask pattern.
120
+ def expand_minitest_directories(files, run_root)
121
+ files.flat_map do |f|
122
+ dir = File.join(run_root.to_s, f)
123
+ next f unless File.directory?(dir)
124
+
125
+ matches = Dir.glob(File.join(dir, "**", "*_test.rb"))
126
+ .map { |m| Pathname.new(m).relative_path_from(run_root).to_s }
127
+ .uniq
128
+ if matches.empty?
129
+ return Ask::Result.failure("No *_test.rb files found under '#{f}'.")
130
+ end
131
+ matches
132
+ end.uniq
133
+ end
134
+
104
135
  def build_command(runner, files, name, failed_tests, json_path)
105
136
  case runner
106
137
  when :rspec
@@ -125,11 +156,25 @@ module Ask
125
156
  # arrives via RUBYOPT like everywhere else.
126
157
  args = ["bundle", "exec", "rake", "test"]
127
158
  env = injection_env(json_path)
128
- env["TEST"] = files.first if files.size == 1
159
+ # Rake::TestTask reads TEST/TESTOPTS from the environment, so
160
+ # the child inherits whatever the parent run carried (nested
161
+ # runs!) unless it's overwritten or cleared here — a stray TEST
162
+ # pointing at the outer project's files would abort the inner
163
+ # run before any test loads.
164
+ env["TEST"] = files.any? ? files.join(",") : nil
129
165
  testopts = []
130
166
  testopts << "--name=#{name}" if name
131
167
  testopts << "--name=#{name_pattern(failed_tests)}" if failed_tests
132
- env["TESTOPTS"] = testopts.join(" ") unless testopts.empty?
168
+ if testopts.empty?
169
+ env["TESTOPTS"] = nil
170
+ else
171
+ # rake's test task runs ruby through the shell, so unquoted
172
+ # TESTOPTS with `|` (failed_only alternations) or spaces gets
173
+ # split into bogus commands. Quote each option so it survives
174
+ # as one ARGV entry in rake_test_loader.
175
+ env["TESTOPTS"] = testopts.map { |o| "\"#{o}\"" }.join(" ")
176
+ end
177
+ %w[TESTOPT TEST_OPTS TEST_OPT].each { |k| env[k] = nil }
133
178
  [args, env]
134
179
  end
135
180
  end
@@ -3,7 +3,7 @@
3
3
  module Ask
4
4
  module Ruby
5
5
  module Harness
6
- VERSION = "0.3.0"
6
+ VERSION = "0.3.1"
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ask-ruby-harness
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kaka Ruto