51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/wip/runner/spec/helpers/matchers.rb', line 51
def self.capture(ui, stream, block)
captured = StringIO.new
mappings = {}.tap do |h|
if stream == :combined
out = ui.send(:out)
err = ui.send(:err)
h[out] = out.instance_variable_get(:'@output')
h[err] = err.instance_variable_get(:'@output')
else
io = ui.send(stream)
h[io] = io.instance_variable_get(:'@output')
end
end
mappings.each do |io, original|
io.instance_variable_set(:'@output', captured)
end
block.call
captured.string
ensure
mappings.each do |io, original|
io.instance_variable_set(:'@output', original)
end
end
|