summaryrefslogtreecommitdiff
path: root/spec/ruby/core/array
diff options
context:
space:
mode:
authorKoichi ITO <koic.ito@gmail.com>2025-02-02 16:17:37 +0900
committergit <svn-admin@ruby-lang.org>2025-03-10 10:19:58 +0000
commitf4c16c57aad9138f236f4fa966893b21d5a64cbf (patch)
treefa51bdab05ecba3792c5d00f60d515deeca85f8e /spec/ruby/core/array
parent45e8dc1e85eced97c7e3b29c947757736a6fcf79 (diff)
[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. https://github.com/ruby/optparse/commit/262cf6f9ac
Diffstat (limited to 'spec/ruby/core/array')
0 files changed, 0 insertions, 0 deletions