mock_stdio 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +64 -0
- data/Rakefile +1 -0
- data/lib/mock_stdio.rb +54 -0
- data/mock_stdio.gemspec +23 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 746cde55c6bd554ed6bf259c2b75a99b01121d73
|
4
|
+
data.tar.gz: 4585b7f4fec1e6b69cc2340d781fdc76c0e96238
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9a035d0696904f7a0ec05816d7b26f43d756032a9a1a859efed7e4ebba1605b40521d2e34ec65d244ed1e739942ee61ccb4d8521b733376105da87c40983a72f
|
7
|
+
data.tar.gz: cff0329ec8e5a898d854f64292853be31b18a1afce8f9c8b5394f69f951458e5966bf4cb7158c6b88f41901567c904965728f4f3f74291c2f6699b4fe43fe79a
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 patbenatar
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# MockStdio
|
2
|
+
|
3
|
+
Helpers for working with stdin and stdout in tests
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem "mock_stdio"
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install mock_stdio
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Include in your spec helpers
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require "mock_stdio"
|
25
|
+
|
26
|
+
RSpec.configure do |config|
|
27
|
+
config.include MockStdio
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
Supply input to `gets` or any read from the stdio buffer and return anything
|
32
|
+
written to stdout:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
follow_prompts "Yes", "No", "Maybe" do
|
36
|
+
puts "Should I?"
|
37
|
+
gets
|
38
|
+
puts "Really?"
|
39
|
+
gets
|
40
|
+
puts "Are you sure?"
|
41
|
+
gets
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
Capture and return stdout:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
capture_stdout { puts "Hey" }
|
49
|
+
```
|
50
|
+
|
51
|
+
Silence stdout to keep spec output clean:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
config.before(:all, &:silence_output)
|
55
|
+
config.after(:all, &:enable_output)
|
56
|
+
```
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
1. Fork it
|
61
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
62
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
63
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
64
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/mock_stdio.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require "stringio"
|
2
|
+
|
3
|
+
module MockStdio
|
4
|
+
VERSION = "0.0.1"
|
5
|
+
|
6
|
+
def follow_prompts(*responses, &block)
|
7
|
+
old_stdin = $stdin
|
8
|
+
old_stdout = $stdout
|
9
|
+
|
10
|
+
$stdin = StringIO.new("", "r+")
|
11
|
+
fake_stdout = StringIO.new
|
12
|
+
$stdout = fake_stdout
|
13
|
+
|
14
|
+
responses.each { |r| $stdin << "#{r}\n" }
|
15
|
+
$stdin.rewind
|
16
|
+
|
17
|
+
block.call
|
18
|
+
|
19
|
+
fake_stdout.string
|
20
|
+
ensure
|
21
|
+
$stdin = old_stdin
|
22
|
+
$stdout = old_stdout
|
23
|
+
end
|
24
|
+
|
25
|
+
def capture_stdout(&block)
|
26
|
+
old_stdout = $stdout
|
27
|
+
|
28
|
+
fake_stdout = StringIO.new
|
29
|
+
$stdout = fake_stdout
|
30
|
+
|
31
|
+
block.call
|
32
|
+
|
33
|
+
fake_stdout.string
|
34
|
+
ensure
|
35
|
+
$stdout = old_stdout
|
36
|
+
end
|
37
|
+
|
38
|
+
def silence_output
|
39
|
+
@orig_stderr = $stderr
|
40
|
+
@orig_stdout = $stdout
|
41
|
+
|
42
|
+
# redirect stderr and stdout to /dev/null
|
43
|
+
$stderr = File.new("/dev/null", "w")
|
44
|
+
$stdout = File.new("/dev/null", "w")
|
45
|
+
end
|
46
|
+
|
47
|
+
# Replace stdout and stderr so anything else is output correctly.
|
48
|
+
def enable_output
|
49
|
+
$stderr = @orig_stderr
|
50
|
+
$stdout = @orig_stdout
|
51
|
+
@orig_stderr = nil
|
52
|
+
@orig_stdout = nil
|
53
|
+
end
|
54
|
+
end
|
data/mock_stdio.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "mock_stdio"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mock_stdio"
|
8
|
+
spec.version = MockStdio::VERSION
|
9
|
+
spec.authors = ["patbenatar"]
|
10
|
+
spec.email = ["nick@gophilosophie.com"]
|
11
|
+
spec.description = "Helpers for working with stdin and stdout in tests"
|
12
|
+
spec.summary = "Helpers for working with stdin and stdout in tests"
|
13
|
+
spec.homepage = "http://github.com/patbenatar/mock_stdio"
|
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
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mock_stdio
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- patbenatar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-04 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
|
+
description: Helpers for working with stdin and stdout in tests
|
42
|
+
email:
|
43
|
+
- nick@gophilosophie.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/mock_stdio.rb
|
54
|
+
- mock_stdio.gemspec
|
55
|
+
homepage: http://github.com/patbenatar/mock_stdio
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 2.0.3
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: Helpers for working with stdin and stdout in tests
|
79
|
+
test_files: []
|