lib/irt/extensions/kernel.rb in irt-1.2.5 vs lib/irt/extensions/kernel.rb in irt-1.2.6
- old
+ new
@@ -1,15 +1,22 @@
require 'stringio'
module Kernel
- def capture
- out = StringIO.new
- $stdout = out
- yield
- return out.string
- ensure
- $stdout = STDOUT
+ # copied from ActiveRecord 3.1 because of conflicting name with previous IRT implementation
+ # modified in the argument default in order to be used by both AR and IRT
+ def capture(stream=:stdout)
+ begin
+ stream = stream.to_s
+ eval "$#{stream} = StringIO.new"
+ yield
+ result = eval("$#{stream}").string
+ ensure
+ eval("$#{stream} = #{stream.upcase}")
+ end
+
+ result
end
+ alias :silence :capture
def irt(bind)
raise IRT::ArgumentTypeError, "You must pass binding instead of #{bind.class.name} object" unless bind.is_a?(Binding)
IRT.start
IRT::Session.enter :binding, bind