Class: RSpec::Support::StdErrSplitter
- Inherits:
-
Object
- Object
- RSpec::Support::StdErrSplitter
show all
- Defined in:
- lib/rspec/support/spec/stderr_splitter.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of StdErrSplitter.
6
7
8
9
|
# File 'lib/rspec/support/spec/stderr_splitter.rb', line 6
def initialize(original)
@orig_stderr = original
@output_tracker = ::StringIO.new
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
16
17
18
19
|
# File 'lib/rspec/support/spec/stderr_splitter.rb', line 16
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 Method Details
#==(other) ⇒ Object
21
22
23
|
# File 'lib/rspec/support/spec/stderr_splitter.rb', line 21
def ==(other)
@orig_stderr == other
end
|
#has_output? ⇒ Boolean
45
46
47
|
# File 'lib/rspec/support/spec/stderr_splitter.rb', line 45
def has_output?
!output.empty?
end
|
#output ⇒ Object
58
59
60
|
# File 'lib/rspec/support/spec/stderr_splitter.rb', line 58
def output
@output_tracker.string
end
|
#reopen(*args) ⇒ Object
25
26
27
28
|
# File 'lib/rspec/support/spec/stderr_splitter.rb', line 25
def reopen(*args)
reset!
@orig_stderr.reopen(*args)
end
|
#reset! ⇒ Object
49
50
51
|
# File 'lib/rspec/support/spec/stderr_splitter.rb', line 49
def reset!
@output_tracker = ::StringIO.new
end
|
#to_io ⇒ Object
To work around JRuby error: can’t convert RSpec::Support::StdErrSplitter into String
32
33
34
|
# File 'lib/rspec/support/spec/stderr_splitter.rb', line 32
def to_io
@orig_stderr.to_io
end
|
#verify_no_warnings! ⇒ Object
53
54
55
56
|
# File 'lib/rspec/support/spec/stderr_splitter.rb', line 53
def verify_no_warnings!
raise "Warnings were generated: #{output}" if has_output?
reset!
end
|
#write(line) ⇒ Object
To work around JRuby error: TypeError: $stderr must have write method, RSpec::StdErrSplitter given
38
39
40
41
42
43
|
# File 'lib/rspec/support/spec/stderr_splitter.rb', line 38
def write(line)
return if line =~ %r{^\S+/gems/\S+:\d+: warning:}
@orig_stderr.write(line)
@output_tracker.write(line)
end
|