o_stream_catcher 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ccf2252ced57277536504d2de77a66413330c3d9
4
+ data.tar.gz: cd8d497e94270ce300ec2348f275b3ea7674adb1
5
+ SHA512:
6
+ metadata.gz: bccac0eb1e5dd40a69eb51fef84315bcd98ac97b2aa26be381747b7a12d0b1665e2b296cb0eecac4051c1f07932ea1d4e4774d846466bdd7f08f936a01d45986
7
+ data.tar.gz: c5281d02a70bef56e5ee81146c0e3f73f0abe04dfe1341c9a2c6faf28b290d4bfed5fa3feb121af3884f3ccb74fe3bdaaa8c180ce78903babb09e6213891b2bb
@@ -0,0 +1,40 @@
1
+ # SimpleCov
2
+ test/coverage
3
+
4
+ # Bundler
5
+ Gemfile.lock
6
+
7
+ *.gem
8
+ *.rbc
9
+ /.config
10
+ /coverage/
11
+ /InstalledFiles
12
+ /pkg/
13
+ /spec/reports/
14
+ /test/tmp/
15
+ /test/version_tmp/
16
+ /tmp/
17
+
18
+ ## Specific to RubyMotion:
19
+ .dat*
20
+ .repl_history
21
+ build/
22
+
23
+ ## Documentation cache and generated files:
24
+ /.yardoc/
25
+ /_yardoc/
26
+ /doc/
27
+ /rdoc/
28
+
29
+ ## Environment normalisation:
30
+ /.bundle/
31
+ /lib/bundler/man/
32
+
33
+ # for a library or gem, you might want to ignore these files since the code is
34
+ # intended to run in multiple environments; otherwise, check them in:
35
+ # Gemfile.lock
36
+ # .ruby-version
37
+ # .ruby-gemset
38
+
39
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
40
+ .rvmrc
@@ -0,0 +1 @@
1
+ 2.0.0
@@ -0,0 +1,14 @@
1
+ SimpleCov.start do
2
+ coverage_dir "test/coverage"
3
+ command_name "tests"
4
+
5
+ use_merging true
6
+ merge_timeout 3600
7
+
8
+ add_filter "test/"
9
+
10
+ add_group "All", "/lib/*.rb"
11
+
12
+ formatter SimpleCov::Formatter::HTMLFormatter
13
+ end
14
+
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,13 @@
1
+ guard :minitest do
2
+
3
+ # run all tests when lib main module file changes
4
+ watch(%r{^lib/o_stream_catcher.rb$}) { "test" }
5
+
6
+ # run accompanying test for single source file if it changes
7
+ watch(%r{^lib/(.*)\.rb$}) {|m| "test/#{m[1]}_test.rb" }
8
+
9
+ # run test whenever it changes
10
+ watch(%r{^test/(.*)\/?(.*)?_test\.rb$})
11
+
12
+ end
13
+
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Markus Seeger
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,16 @@
1
+ OStreamCatcher
2
+ ==============
3
+
4
+ Catches stdout and stderr for ruby blocks.
5
+
6
+ ## Example
7
+
8
+ TODO
9
+
10
+ ## Further reading
11
+
12
+ For a more detailed description, see (TODO blog link).
13
+
14
+ ## TODO
15
+
16
+ - Add an option to read catched output without muting it.
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake'
5
+ require 'rake/testtask'
6
+
7
+ task :default => [:test]
8
+
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = false
14
+ end
@@ -0,0 +1,4 @@
1
+ module OStreamCatcher
2
+ require 'o_stream_catcher/version.rb'
3
+ require 'o_stream_catcher/o_stream_catcher'
4
+ end
@@ -0,0 +1,39 @@
1
+ module OStreamCatcher
2
+
3
+ def catch(&block)
4
+ stdout_orig, stdout_mock = mock_stdout
5
+ stderr_orig, stderr_mock = mock_stderr
6
+
7
+ stderr_orig = $stderr
8
+ stderr_mock = StringIO.new
9
+ $stderr = stderr_mock
10
+
11
+ begin
12
+ result = block.call
13
+ ensure
14
+ $stdout = stdout_orig
15
+ $stderr = stderr_orig
16
+ end
17
+
18
+ [result, stdout_mock.string, stderr_mock.string]
19
+ end
20
+
21
+ protected
22
+
23
+ def mock_stdout
24
+ orig = $stdout
25
+ mock = StringIO.new
26
+ $stdout = mock
27
+ [orig, mock]
28
+ end
29
+
30
+ def mock_stderr
31
+ orig = $stderr
32
+ mock = StringIO.new
33
+ $sterr = mock
34
+ [orig, mock]
35
+ end
36
+
37
+ extend self
38
+
39
+ end
@@ -0,0 +1,3 @@
1
+ module OStreamCatcher
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'o_stream_catcher/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "o_stream_catcher"
8
+ gem.version = OStreamCatcher::VERSION
9
+ gem.authors = ["Markus Seeger"]
10
+ gem.email = ["mail@codegourmet.de"]
11
+ gem.description = "Catches stdout and stderr for ruby blocks."
12
+ gem.summary = "pass in a block and get the result, stdout and stderr returned."
13
+ gem.homepage = "https://github.com/codegourmet/o_stream_catcher"
14
+ gem.license = "MIT"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_development_dependency "rake", "~> 10.1"
22
+ gem.add_development_dependency "guard-minitest"
23
+ gem.add_development_dependency "minitest"
24
+ gem.add_development_dependency "minitest-reporters"
25
+ gem.add_development_dependency "simplecov"
26
+ end
@@ -0,0 +1,32 @@
1
+ require_relative "../test_helper"
2
+ require_relative "../../lib/o_stream_catcher/o_stream_catcher"
3
+
4
+ module OStreamCatcher
5
+ class OStreamCatcherTest < MiniTest::Test
6
+
7
+ def test_should_return_result_of_block
8
+ result, _stdout, _stderr = OStreamCatcher.catch { 42 }
9
+ assert_equal 42, result
10
+ end
11
+
12
+ def test_should_return_stdout_contents
13
+ _result, stdout, _stderr = OStreamCatcher.catch { print "out: Hello world!" }
14
+ assert_equal "out: Hello world!", stdout
15
+ end
16
+
17
+ def test_should_return_sterr_contents
18
+ _result, _stdout, stderr = OStreamCatcher.catch { $stderr.print "err: Hello world!" }
19
+ assert_equal "err: Hello world!", stderr
20
+ end
21
+
22
+ def test_should_restore_streams_when_exception
23
+ orig_stdout = $stdout
24
+ orig_stderr = $stderr
25
+ _result = (OStreamCatcher.catch { throw "test" }) rescue []
26
+
27
+ assert_equal orig_stdout, $stdout
28
+ assert_equal orig_stderr, $stderr
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,12 @@
1
+ require 'simplecov' # has to be at top, will execute ../.simplecov
2
+
3
+ require 'o_stream_catcher'
4
+
5
+ require 'minitest/autorun'
6
+ require 'minitest/reporters'
7
+
8
+ if ENV["RM_INFO"] || ENV["TEAMCITY_VERSION"]
9
+ MiniTest::Reporters.use! MiniTest::Reporters::RubyMineReporter.new
10
+ else
11
+ MiniTest::Reporters.use! MiniTest::Reporters::SpecReporter.new
12
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: o_stream_catcher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Markus Seeger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '10.1'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '10.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: guard-minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-reporters
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Catches stdout and stderr for ruby blocks.
84
+ email:
85
+ - mail@codegourmet.de
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .ruby-version
92
+ - .simplecov
93
+ - Gemfile
94
+ - Guardfile
95
+ - LICENSE
96
+ - README.md
97
+ - Rakefile
98
+ - lib/o_stream_catcher.rb
99
+ - lib/o_stream_catcher/o_stream_catcher.rb
100
+ - lib/o_stream_catcher/version.rb
101
+ - o_stream_catcher.gemspec
102
+ - test/o_stream_catcher/o_stream_catcher_test.rb
103
+ - test/test_helper.rb
104
+ homepage: https://github.com/codegourmet/o_stream_catcher
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.0.14
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: pass in a block and get the result, stdout and stderr returned.
128
+ test_files:
129
+ - test/o_stream_catcher/o_stream_catcher_test.rb
130
+ - test/test_helper.rb