Class: RSpec::Support::StdErrSplitter

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/support/spec/stderr_splitter.rb

Instance Method Summary collapse

Constructor Details

#initialize(original) ⇒ StdErrSplitter

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)
  @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

Returns:

  • (Boolean)


34
35
36
# File 'lib/rspec/support/spec/stderr_splitter.rb', line 34

def has_output?
  !output.empty?
end

#outputObject



47
48
49
# File 'lib/rspec/support/spec/stderr_splitter.rb', line 47

def output
  @output_tracker.string
end

#reset!Object



38
39
40
# File 'lib/rspec/support/spec/stderr_splitter.rb', line 38

def reset!
  @output_tracker = ::StringIO.new
end

#verify_example!(example) ⇒ Object



42
43
44
45
# File 'lib/rspec/support/spec/stderr_splitter.rb', line 42

def verify_example!(example)
  example.send(:fail,"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



27
28
29
30
31
32
# File 'lib/rspec/support/spec/stderr_splitter.rb', line 27

def write(line)
  if line !~ %r{^\S+/gems/\S+:\d+: warning:} # http://rubular.com/r/kqeUIZOfPG
    @orig_stderr.write(line)
    @output_tracker.write(line)
  end
end