std_capture 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/std_capture.rb +13 -0
  2. data/test_std_capture.rb +19 -0
  3. metadata +69 -0
data/std_capture.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'stringio'
2
+ module StdCapture
3
+ def self.capture
4
+ x = $stdout
5
+ s = StringIO.new
6
+ $stdout = s
7
+ yield
8
+ $stdout = x
9
+ s.rewind
10
+ s.read
11
+ end
12
+ end
13
+
@@ -0,0 +1,19 @@
1
+ require 'test/unit'
2
+ require './std_capture'
3
+ class TestStdCapture < Test::Unit::TestCase
4
+
5
+ #include StdoutCatcher
6
+ def test_simple
7
+
8
+ h = StdCapture.capture {
9
+ puts "Hello"
10
+ }
11
+ puts "done"
12
+ assert_equal "Hello\n",h
13
+ h = StdCapture.capture {
14
+ puts "goodbye"
15
+ }
16
+ puts "done"
17
+ assert_equal "goodbye\n",h
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: std_capture
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Dominic Tarr
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-10 00:00:00 +12:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: "\t\ts = StdCatch.capture do puts \"akakadaka\" end; \n\
23
+ \t\ts == \"akakadaka\" -> true\n"
24
+ email: dominic.tarr@gmail.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - test_std_capture.rb
33
+ - std_capture.rb
34
+ has_rdoc: true
35
+ homepage: http://github.com/dominictarr/std_capture
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - ./
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ hash: 3
49
+ segments:
50
+ - 0
51
+ version: "0"
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ requirements: []
62
+
63
+ rubyforge_project:
64
+ rubygems_version: 1.3.7
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: grab std output withing context of a block
68
+ test_files: []
69
+