ruby/test/optparse
Koichi ITO f4c16c57aa [ruby/optparse] Make the result of tty? obtainable with flexible stdout
In mock testing for stdout, `StringIO.new` is sometimes used to redirect the output.
In such cases, the assignment is done with `$stdout = StringIO.new`, not the constant `STDOUT`.
e.g., https://github.com/rubocop/rubocop/blob/v1.71.1/lib/rubocop/rspec/shared_contexts.rb#L154-L164

After assigning `StringIO.new`, `$stdout.tty?` returns `false`,
allowing the standard output destination to be switched during test execution.

```ruby
STDOUT.tty?       # => true
StringIO.new.tty? # => false
```

However, since `STDOUT.tty?` returns `true`, a failure occurred in environments
where the environment variables `RUBY_PAGER` or `PAGER` are set.
e.g., https://github.com/rubocop/rubocop/pull/13784

To address this, `STDOUT` has been updated to `$stdout` so that the result of `tty?` can be flexibly overridden.

A potential concern is that `$stdout`, unlike `STDOUT`,
does not always represent the standard output at the time the Ruby process started.
However, no concrete examples of issues related to this have been identified.

`STDOUT.tty?` is the logic of optparse introduced in https://github.com/ruby/optparse/pull/70.

This PR replaces `STDOUT` with `$stdout` throughout, based on the assumption
that `$stdout` is sufficient for use with optparse.

262cf6f9ac
2025-03-10 10:19:58 +00:00
..
test_acceptable.rb [ruby/optparse] Fix parsing array arguments with :into option 2024-08-05 02:28:12 +00:00
test_autoconf.rb
test_bash_completion.rb
test_cclass.rb
test_did_you_mean.rb
test_getopts.rb
test_kwargs.rb
test_load.rb
test_noarg.rb
test_optarg.rb [ruby/optparse] Adjust arguments for lambda-callbacks 2024-02-09 19:58:31 +09:00
test_optparse.rb [ruby/optparse] Make the result of tty? obtainable with flexible stdout 2025-03-10 10:19:58 +00:00
test_placearg.rb [ruby/optparse] Add post-check of value 2025-03-10 09:55:29 +00:00
test_reqarg.rb [ruby/optparse] Adjust arguments for lambda-callbacks 2024-02-09 19:58:31 +09:00
test_summary.rb
test_zsh_completion.rb