-
-
Notifications
You must be signed in to change notification settings - Fork 763
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #856 from JonRowe/deprecation_io_mk2
Log, count and warn deprecations via configurable io stream
- Loading branch information
Showing
12 changed files
with
200 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module RSpec | ||
module Core | ||
class DeprecationIO | ||
|
||
def initialize | ||
@io = $stderr | ||
@count = 0 | ||
@description = 'STD_ERR' | ||
end | ||
attr_reader :io, :description | ||
|
||
def set_output(io, description = io.inspect) | ||
@description = description | ||
@io = io | ||
end | ||
|
||
def puts(message) | ||
@count += 1 | ||
@io.puts message | ||
end | ||
|
||
def deprecations | ||
@count | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
require 'spec_helper' | ||
require 'tempfile' | ||
|
||
module RSpec::Core | ||
describe DeprecationIO do | ||
let(:std_err) { StringIO.new } | ||
let(:io) { DeprecationIO.new } | ||
|
||
around do |example| | ||
@original = $stderr | ||
$stderr = std_err | ||
example.run | ||
$stderr = @original | ||
end | ||
|
||
describe 'by default' do | ||
it 'starts with 0 deprecations' do | ||
expect(io.deprecations).to eq 0 | ||
end | ||
|
||
it 'counts deprecations' do | ||
io.puts 'WARN' | ||
expect(io.deprecations).to eq 1 | ||
end | ||
|
||
it 'logs to std err by default' do | ||
std_err.should_receive(:puts).with('WARN').once | ||
io.puts 'WARN' | ||
end | ||
|
||
it 'leaves description as stderr' do | ||
expect(io.description).to eq 'STD_ERR' | ||
end | ||
end | ||
|
||
describe 'setting an io' do | ||
let(:stream) { double "stream", :puts => nil } | ||
|
||
before do | ||
io.set_output stream | ||
end | ||
|
||
it 'starts with 0 deprecations' do | ||
expect(io.deprecations).to eq 0 | ||
end | ||
|
||
it 'counts deprecations' do | ||
io.puts 'WARN' | ||
expect(io.deprecations).to eq 1 | ||
end | ||
|
||
it 'logs to the stream' do | ||
stream.should_receive(:puts).with('WARN').once | ||
io.puts 'WARN' | ||
end | ||
|
||
it 'defaults description to the inspect of stream' do | ||
expect(io.description).to eq stream.inspect | ||
end | ||
end | ||
|
||
describe 'setting an io and description' do | ||
it 'sets description' do | ||
io.set_output double, 'filename.txt' | ||
expect(io.description).to eq 'filename.txt' | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters