Class: RSpec::Support::StdErrSplitter
Relationships & Source Files | |
Inherits: | Object |
Defined in: | rspec-support/lib/rspec/support/spec/stderr_splitter.rb |
Class Method Summary
- .new(original) ⇒ StdErrSplitter constructor
Instance Attribute Summary
- #has_output? ⇒ Boolean readonly
Instance Method Summary
- #==(other)
- #clone
- #method_missing(name, *args, &block)
- #output
- #reopen(*args)
- #reset!
-
#to_io
To work around JRuby error: can’t convert RSpec::Support::StdErrSplitter into String.
- #verify_no_warnings!
-
#write(line)
To work around JRuby error: TypeError: $stderr must have write method, RSpec::StdErrSplitter given.
Constructor Details
.new(original) ⇒ StdErrSplitter
# File 'rspec-support/lib/rspec/support/spec/stderr_splitter.rb', line 8
def initialize(original) @orig_stderr = original @output_tracker = ::StringIO.new @last_line = nil end
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block)
[ GitHub ]# File 'rspec-support/lib/rspec/support/spec/stderr_splitter.rb', line 19
def method_missing(name, *args, &block) @output_tracker.__send__(name, *args, &block) if @output_tracker.respond_to?(name) @orig_stderr.__send__(name, *args, &block) end
Instance Attribute Details
#has_output? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'rspec-support/lib/rspec/support/spec/stderr_splitter.rb', line 63
def has_output? !output.empty? end
Instance Method Details
#==(other)
[ GitHub ]# File 'rspec-support/lib/rspec/support/spec/stderr_splitter.rb', line 28
def ==(other) @orig_stderr == other end
#clone
[ GitHub ]# File 'rspec-support/lib/rspec/support/spec/stderr_splitter.rb', line 24
def clone StdErrSplitter.new(@orig_stderr.clone) end
#output
[ GitHub ]# File 'rspec-support/lib/rspec/support/spec/stderr_splitter.rb', line 76
def output @output_tracker.string end
#reopen(*args)
[ GitHub ]# File 'rspec-support/lib/rspec/support/spec/stderr_splitter.rb', line 32
def reopen(*args) reset! @orig_stderr.reopen(*args) end
#reset!
[ GitHub ]# File 'rspec-support/lib/rspec/support/spec/stderr_splitter.rb', line 67
def reset! @output_tracker = ::StringIO.new end
#to_io
To work around JRuby error: can’t convert RSpec::Support::StdErrSplitter into String
# File 'rspec-support/lib/rspec/support/spec/stderr_splitter.rb', line 39
def to_io @orig_stderr.to_io end
#verify_no_warnings!
[ GitHub ]# File 'rspec-support/lib/rspec/support/spec/stderr_splitter.rb', line 71
def verify_no_warnings! raise "Warnings were generated: #{output}" if has_output? reset! end
#write(line)
To work around JRuby error: TypeError: $stderr must have write method, RSpec::StdErrSplitter given
# File 'rspec-support/lib/rspec/support/spec/stderr_splitter.rb', line 45
def write(line) return if line =~ %r{^\S+/gems/\S+:\d+: warning:} # http://rubular.com/r/kqeUIZOfPG # Ruby 2.7.0 warnings from keyword arguments span multiple lines, extend check above # to look for the next line. return if @last_line =~ %r{^\S+/gems/\S+:\d+: warning:} && line =~ %r{warning: The called method .* is defined here} # Ruby 2.7.0 complains about hashes used in place of keyword arguments # Aruba 0.14.2 uses this internally triggering that here return if line =~ %r{lib/ruby/2\.7\.0/fileutils\.rb:622: warning:} @orig_stderr.write(line) @output_tracker.write(line) ensure @last_line = line end