io-grab 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: 5241f1725ddbaf480263daeac6cc897f8cec46a1
4
+ data.tar.gz: b2c1ca38783c61a6a259d261c22debcff9e0042e
5
+ SHA512:
6
+ metadata.gz: c3ab6aaba8e5fda57a7d153abde454c1f98570e0252a2ac40aad89d15b2081db785d0f1ff13ff2ca8be91372e1a77672ee60ab711f6789028b6b7abd3e04ef6f
7
+ data.tar.gz: 72bdb3967fe09c9dbcdf80e5acd6574806a860044b1404c22717bbdf266aca490d40f1fc82be977a5b983516e7e45b9755bd3425fdb3b51f131b11c50ecf2730
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .kateproject.d
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "IO::Grab"
3
+ , "files": [ { "git": 1 } ]
4
+ }
5
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in io-grab.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Rafał Rzepecki
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ # IO::Grab
2
+
3
+ Capture IO writes.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'io-grab'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install io-grab
18
+
19
+ ## Usage
20
+
21
+ io-grab adds #grab method to IO. (It also extends StringIO for consistency, even though it isn't really an IO.)
22
+ You can use this method to temporarily redirect writes to the object to a string, ie. for later examination.
23
+
24
+ require 'io/grab'
25
+
26
+ STDOUT.grab { puts "foo" }
27
+ # => "foo\n"
28
+
29
+ This is particularly useful for testing, eg. to check for expected messages.
30
+
31
+ describe "Kernel#puts" do
32
+ it "adds a newline at the end" do
33
+ STDOUT.grab { puts "foo" }.should =~ /\n\z/
34
+ end
35
+ end
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'io/grab/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "io-grab"
8
+ spec.version = IO::Grab::VERSION
9
+ spec.authors = ["Rafał Rzepecki"]
10
+ spec.email = ["divided.mind@gmail.com"]
11
+ spec.description = %q{Adds #grab method to IO, which permits capturing all writes to that IO.}
12
+ spec.summary = %q{Capture IO writes}
13
+ spec.homepage = "https://github.com/dividedmind/io-grab"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,28 @@
1
+ require "io/grab/version"
2
+
3
+ class IO
4
+ module Grab
5
+ def grab &block
6
+ @grabbed_output = ""
7
+ class << self
8
+ def write arg
9
+ @grabbed_output += arg
10
+ end
11
+ end
12
+
13
+ begin
14
+ yield
15
+ ensure
16
+ singleton_class.send :remove_method, :write
17
+ end
18
+
19
+ @grabbed_output
20
+ end
21
+ end
22
+
23
+ include Grab
24
+ end
25
+
26
+ class StringIO
27
+ include IO::Grab
28
+ end
@@ -0,0 +1,5 @@
1
+ class IO
2
+ module Grab
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ require 'io/grab'
2
+ require 'stringio'
3
+
4
+ describe "IO#grab" do
5
+ let(:io) { StringIO.new }
6
+
7
+ it "catches the output correctly" do
8
+ io.grab { io.puts "foo" }.should == "foo\n"
9
+ end
10
+
11
+ it "doesn't pass the output to the original implementation" do
12
+ io.grab { io.puts "foo" }
13
+ io.string.should be_empty
14
+ end
15
+
16
+ it "reverts the grab when it's done" do
17
+ io.grab { io.puts "foo" }
18
+ io.puts "bar"
19
+ io.string.should == "bar\n"
20
+ end
21
+
22
+ it "works for STDOUT" do
23
+ STDOUT.grab { puts "foo" }.should == "foo\n"
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: io-grab
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rafał Rzepecki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
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: rspec
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
+ description: 'Adds #grab method to IO, which permits capturing all writes to that
56
+ IO.'
57
+ email:
58
+ - divided.mind@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - .kateproject
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - io-grab.gemspec
70
+ - lib/io/grab.rb
71
+ - lib/io/grab/version.rb
72
+ - spec/io-grab_spec.rb
73
+ homepage: https://github.com/dividedmind/io-grab
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.0.0.rc.2
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Capture IO writes
97
+ test_files:
98
+ - spec/io-grab_spec.rb