Skip to content

Conversation

schneems
Copy link
Contributor

@schneems schneems commented Aug 25, 2025

Script

This script runs all test files one by one and reports which cannot be run via being focused

#!/bin/bash
cd "$(dirname "$0")/.."
failed_tests=()
for test in test/test_*.rb; do
  if bundle exec m "$test" >/dev/null 2>&1; then
    echo "$(basename "$test")"
  else
    echo "$(basename "$test")"
    failed_tests+=("$test")
  fi
done

echo

if [ ${#failed_tests[@]} -eq 0 ]; then
  echo "All tests passed! ✨"
else
  echo "Failed tests:"
  printf '%s\n' "${failed_tests[@]}"
  echo
  echo "The above tests cannot be focused with 'bundle exec m <test-name>' fix them"
  exit 1
fi

I was trying to focus test a specific file for a PR and I couldn't due to errors. I wrote a script to print out all the files that couldn't be focused, turns out they were all due to one missing require.

Before:

Failed tests:
test/test_log_writer.rb
test/test_out_of_band_server.rb
test/test_persistent.rb
test/test_puma_localhost_authority.rb
test/test_puma_server_current.rb
test/test_puma_server_hijack.rb
test/test_puma_server_ssl.rb
test/test_puma_server.rb
test/test_rack_server.rb
test/test_request_invalid_multiple.rb
test/test_response_header.rb
test/test_unix_socket.rb
test/test_web_server.rb

The above tests cannot be focused with 'bundle exec m <test-name>' fix them

After:

All tests passed! ✨

Before

```
TestLogWriter#test_parse_error:
NameError: uninitialized constant Puma::Server::UserFileDefaultOptions
    lib/puma/server.rb:80:in 'Puma::Server#initialize'
    test/test_log_writer.rb:128:in 'Class#new'
    test/test_log_writer.rb:128:in 'TestLogWriter#test_parse_error'

14 runs, 34 assertions, 0 failures, 1 errors, 0 skips
```

After:

```
$ be m test/test_log_writer.rb
/Users/rschneeman/.gem/ruby/3.4.5/gems/minitest-5.25.1/lib/minitest/mock.rb:33: warning: redefining 'object_id' may cause serious problems
Run options: -n "/^(test_parse_error|test_strings|test_debug_not_write_to_stdout_if_env_is_not_present|test_stdio|test_custom_log_formatter|test_null|test_log_writes_to_stdout|test_null_log_does_nothing|test_stdio_respects_sync|test_pid_formatter|test_error_writes_to_stderr_and_exits|test_debug_writes_to_stdout_if_env_is_present|test_write_writes_to_stdout|test_ssl_error)$/" --seed 44135

# Running:

..............

Fabulous run in 0.142536s, 98.2208 runs/s, 266.5993 assertions/s.

14 runs, 38 assertions, 0 failures, 0 errors, 0 skips
```
I'm unsure what the exact conditions are that cause this, but it was hiding the "real" error (of a missing class). I think constants are loaded lazilly which happens before server is defined so calling stop on that variable is an error since it's a nil.

```
$ be m test/test_log_writer.rb
/Users/rschneeman/.gem/ruby/3.4.5/gems/minitest-5.25.1/lib/minitest/mock.rb:33: warning: redefining 'object_id' may cause serious problems
Run options: -n "/^(test_debug_writes_to_stdout_if_env_is_present|test_stdio|test_parse_error|test_debug_not_write_to_stdout_if_env_is_not_present|test_log_writes_to_stdout|test_error_writes_to_stderr_and_exits|test_strings|test_stdio_respects_sync|test_custom_log_formatter|test_write_writes_to_stdout|test_null_log_does_nothing|test_null|test_ssl_error|test_pid_formatter)$/" --seed 18564

# Running:

E.............

Fabulous run in 0.030120s, 464.8074 runs/s, 1128.8181 assertions/s.
Errors & Failures:

  1) Error:
TestLogWriter#test_parse_error:
NoMethodError: undefined method 'stop' for nil
    test/test_log_writer.rb:145:in 'TestLogWriter#test_parse_error'

14 runs, 34 assertions, 0 failures, 1 errors, 0 skips
```
@github-actions github-actions bot added the waiting-for-review Waiting on review from anyone label Aug 25, 2025
@schneems schneems merged commit e286732 into master Aug 25, 2025
137 checks passed
@schneems schneems deleted the schneems/test-one-by-one branch August 25, 2025 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-for-review Waiting on review from anyone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant