Skip to content

Commit

Permalink
Merge pull request #1 from chrishunt/always-mute
Browse files Browse the repository at this point in the history
Always mute when no block is provided
  • Loading branch information
chrishunt committed Jan 19, 2014
2 parents 47a59a9 + 8b95d31 commit 974d4fe
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
11 changes: 10 additions & 1 deletion README.md
Expand Up @@ -42,7 +42,7 @@ puts output
#=> Oops!
```

Or use it in your test suite:
Use it in your test suite to verify output:

```ruby
require 'mute'
Expand All @@ -60,6 +60,15 @@ describe MyLogger do
end
```

Or just mute stdout completely for the whole test suite:

```ruby
# spec/spec_helper.rb
require 'mute'

Mute::IO.capture_stdout
```

## Installation

```bash
Expand Down
2 changes: 1 addition & 1 deletion lib/mute/io.rb
Expand Up @@ -20,7 +20,7 @@ def self.capture(stream, block)

captured.string
ensure
eval "$#{stream} = original"
eval "$#{stream} = original" if block
end
end
end
8 changes: 6 additions & 2 deletions spec/mute/io_spec.rb
Expand Up @@ -43,8 +43,12 @@
expect($stdout).to eq original
end

it 'does not require a block' do
expect { described_class.capture_stdout }.to_not raise_error
it 'captures stdout indefinitely when called without a block' do
expect($stdout).to_not receive(:puts)

described_class.capture_stdout

puts 'hello'
end
end

Expand Down

0 comments on commit 974d4fe

Please sign in to comment.