mute 1.0.0
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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +4 -0
- data/CHANGELOG.md +6 -0
- data/CONTRIBUTING.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +79 -0
- data/Rakefile +15 -0
- data/lib/mute.rb +2 -0
- data/lib/mute/io.rb +26 -0
- data/lib/mute/version.rb +3 -0
- data/mute.gemspec +28 -0
- data/screenshot.png +0 -0
- data/spec/mute/io_spec.rb +62 -0
- data/spec/spec_helper.rb +3 -0
- metadata +160 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9fbad050d8943b84c90dcba8296406c41ca1809e
|
4
|
+
data.tar.gz: bfcdd12c57f38d6a2e90eec60fa5a8b15292bd74
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cdb324d79d6d71ffb34e2ab0f8b9ed512c0b6447ac7755ca1575944e9dff09abfb09f59fec32356adb155e366576fdede4ac115cf925cc3b8aef0e9d6fe2d343
|
7
|
+
data.tar.gz: 6e3a5625524e2a1b7d5ad0b7c5cfd97eb6769a3d1ce1597235a8e88c00ec3dbe7cecf798c4e7e97d592ac9a023806a33a1f3813556c776ff8e9be20a381ecc09
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
Want to contribute? Awesome! Thank you so much.
|
4
|
+
|
5
|
+
## How?
|
6
|
+
|
7
|
+
1. [Fork it](https://help.github.com/articles/fork-a-repo)
|
8
|
+
2. Create a feature branch (`git checkout -b my-new-feature`)
|
9
|
+
3. Commit changes, **with tests** (`git commit -am 'Add some feature'`)
|
10
|
+
4. Run the tests (`bundle exec rake`)
|
11
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
12
|
+
6. Create new [Pull
|
13
|
+
Request](https://help.github.com/articles/using-pull-requests)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Chris Hunt
|
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,79 @@
|
|
1
|
+
[](https://travis-ci.org/chrishunt/mute)
|
2
|
+
[](https://coveralls.io/r/chrishunt/mute)
|
3
|
+
[](https://codeclimate.com/github/chrishunt/mute)
|
4
|
+
|
5
|
+
### Muting test suites since 2014
|
6
|
+
|
7
|
+

|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
Tired of seeing garbage printed to the screen during your test suite? Would you
|
12
|
+
like to prove that your fancy custom Logger is actually working? `Mute` is here
|
13
|
+
to help!
|
14
|
+
|
15
|
+
`Mute` can be used to mute and capture standard out or standard error in your
|
16
|
+
Ruby program. This is most useful in tests where output should be tested, not
|
17
|
+
displayed.
|
18
|
+
|
19
|
+
To capture standard out:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require 'mute'
|
23
|
+
|
24
|
+
output = Mute::IO.capture_stdout do
|
25
|
+
puts 'Hello World!'
|
26
|
+
end
|
27
|
+
|
28
|
+
puts output
|
29
|
+
#=> Hello World!
|
30
|
+
```
|
31
|
+
|
32
|
+
To capture standard error:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
require 'mute'
|
36
|
+
|
37
|
+
output = Mute::IO.capture_stderr do
|
38
|
+
$stderr.puts 'Oops!'
|
39
|
+
end
|
40
|
+
|
41
|
+
puts output
|
42
|
+
#=> Oops!
|
43
|
+
```
|
44
|
+
|
45
|
+
Or use it in your test suite:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
require 'mute'
|
49
|
+
|
50
|
+
describe MyLogger do
|
51
|
+
it 'prints the message to standard out' do
|
52
|
+
message = 'Hello World!'
|
53
|
+
|
54
|
+
output = Mute::IO.capture_stdout do
|
55
|
+
MyLogger.new.print message
|
56
|
+
end
|
57
|
+
|
58
|
+
expect(output).to include message
|
59
|
+
end
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
## Installation
|
64
|
+
|
65
|
+
```bash
|
66
|
+
$ gem install mute
|
67
|
+
```
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
Please see the [Contributing
|
71
|
+
Document](https://github.com/chrishunt/mute/blob/master/CONTRIBUTING.md)
|
72
|
+
|
73
|
+
## Changelog
|
74
|
+
Please see the [Changelog
|
75
|
+
Document](https://github.com/chrishunt/mute/blob/master/CHANGELOG.md)
|
76
|
+
|
77
|
+
## License
|
78
|
+
Copyright (C) 2014 Chris Hunt, [MIT
|
79
|
+
License](https://github.com/chrishunt/mute/blob/master/LICENSE.txt)
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'cane/rake_task'
|
4
|
+
require 'cane/hashcheck'
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
7
|
+
t.rspec_opts = '--color'
|
8
|
+
end
|
9
|
+
|
10
|
+
Cane::RakeTask.new(:quality) do |t|
|
11
|
+
t.use Cane::HashCheck
|
12
|
+
end
|
13
|
+
|
14
|
+
task default: :spec
|
15
|
+
task default: :quality
|
data/lib/mute.rb
ADDED
data/lib/mute/io.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
|
3
|
+
module Mute
|
4
|
+
# Mutes and captures stdout and stderr IO streams
|
5
|
+
class IO
|
6
|
+
[:stdout, :stderr].each do |stream|
|
7
|
+
define_singleton_method("capture_#{stream}") do |&block|
|
8
|
+
capture stream, block
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def self.capture(stream, block)
|
15
|
+
captured = StringIO.new
|
16
|
+
original = eval("$#{stream}")
|
17
|
+
eval "$#{stream} = captured"
|
18
|
+
|
19
|
+
block.call if block
|
20
|
+
|
21
|
+
captured.string
|
22
|
+
ensure
|
23
|
+
eval "$#{stream} = original"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/mute/version.rb
ADDED
data/mute.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mute/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mute"
|
8
|
+
spec.version = Mute::VERSION
|
9
|
+
spec.authors = ["Chris Hunt"]
|
10
|
+
spec.email = ["c@chrishunt.co"]
|
11
|
+
spec.summary = %q{Muting test suites since 2014}
|
12
|
+
spec.description = %q{Muting test suites since 2014}
|
13
|
+
spec.homepage = "https://github.com/chrishunt/mute"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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.5'
|
22
|
+
spec.add_development_dependency 'cane', '~> 2.6.1'
|
23
|
+
spec.add_development_dependency 'cane-hashcheck', '~> 1.2.0'
|
24
|
+
spec.add_development_dependency 'coveralls', '~> 0.7.0'
|
25
|
+
spec.add_development_dependency 'pry', '~> 0.9.12'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.1.1'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 2.14.1'
|
28
|
+
end
|
data/screenshot.png
ADDED
Binary file
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'mute/io'
|
3
|
+
|
4
|
+
describe Mute::IO do
|
5
|
+
describe '.capture_stdout' do
|
6
|
+
it 'mutes stdout' do
|
7
|
+
expect($stdout).to_not receive(:puts)
|
8
|
+
|
9
|
+
described_class.capture_stdout do
|
10
|
+
puts 'hello'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'captures stdout' do
|
15
|
+
message = 'hello'
|
16
|
+
|
17
|
+
output = described_class.capture_stdout do
|
18
|
+
puts message
|
19
|
+
end
|
20
|
+
|
21
|
+
expect(output).to include message
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'unmutes stdout when done' do
|
25
|
+
original = $stdout
|
26
|
+
|
27
|
+
described_class.capture_stdout do
|
28
|
+
puts 'hello'
|
29
|
+
end
|
30
|
+
|
31
|
+
expect($stdout).to eq original
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'unmutes stdout when there is an exception' do
|
35
|
+
original = $stdout
|
36
|
+
|
37
|
+
expect {
|
38
|
+
described_class.capture_stdout do
|
39
|
+
raise StandardError.new('Oops')
|
40
|
+
end
|
41
|
+
}.to raise_error
|
42
|
+
|
43
|
+
expect($stdout).to eq original
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'does not require a block' do
|
47
|
+
expect { described_class.capture_stdout }.to_not raise_error
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '.capture_stderr' do
|
52
|
+
it 'captures stderr' do
|
53
|
+
message = 'oops'
|
54
|
+
|
55
|
+
output = described_class.capture_stderr do
|
56
|
+
$stderr.puts message
|
57
|
+
end
|
58
|
+
|
59
|
+
expect(output).to include message
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mute
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Hunt
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-19 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.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: cane
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.6.1
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.6.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: cane-hashcheck
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.2.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.2.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.7.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.7.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.9.12
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.9.12
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 10.1.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 10.1.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.14.1
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.14.1
|
111
|
+
description: Muting test suites since 2014
|
112
|
+
email:
|
113
|
+
- c@chrishunt.co
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- .travis.yml
|
120
|
+
- CHANGELOG.md
|
121
|
+
- CONTRIBUTING.md
|
122
|
+
- Gemfile
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- lib/mute.rb
|
127
|
+
- lib/mute/io.rb
|
128
|
+
- lib/mute/version.rb
|
129
|
+
- mute.gemspec
|
130
|
+
- screenshot.png
|
131
|
+
- spec/mute/io_spec.rb
|
132
|
+
- spec/spec_helper.rb
|
133
|
+
homepage: https://github.com/chrishunt/mute
|
134
|
+
licenses:
|
135
|
+
- MIT
|
136
|
+
metadata: {}
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
require_paths:
|
140
|
+
- lib
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - '>='
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 2.0.3
|
154
|
+
signing_key:
|
155
|
+
specification_version: 4
|
156
|
+
summary: Muting test suites since 2014
|
157
|
+
test_files:
|
158
|
+
- spec/mute/io_spec.rb
|
159
|
+
- spec/spec_helper.rb
|
160
|
+
has_rdoc:
|