Sha256: 5ba94d4ff1ea413111357cddc62e5105f506ac66232f8fb832d3073bdcb03e52
Contents?: true
Size: 1.08 KB
Versions: 2
Compression:
Stored size: 1.08 KB
Contents
# Code adapted from rs, written by Eero Saynatkari. require 'fileutils' class Test::Spec::Should # Captures output from the IO given as # the second argument (STDIN by default) # and matches it against a String or # Regexp given as the first argument. def output(expected, to = STDOUT) # Store the old stream old_to = to.dup # Obtain a filehandle to replace (works with Readline) to.reopen File.open("/tmp/should_output_#{$$}", "w+") # Execute @object.call # Restore out = to.dup to.reopen old_to # Grab the data out.rewind output = out.read # Match up case expected when Regexp output.should.match expected else output.should.equal expected end # case expected # Clean up ensure out.close # STDIO redirection will break else begin to.seek 0, IO::SEEK_END rescue Errno::ESPIPE rescue Errno::EPIPE end FileUtils.rm_f out.path end # output end # Test::Spec::Should
Version data entries
2 entries across 2 versions & 2 rubygems
Version | Path |
---|---|
mofo-0.1.1 | vendor/testspec-0.2.0/lib/test/spec/should-output.rb |
test-spec-0.2 | lib/test-spec/test/spec/should-output.rb |