Skip to content

Commit 6490ca3

Browse files
committed
Silence noisy specs
1 parent bfbcbe0 commit 6490ca3

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

spec/lib/calculate_blob_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ module CodeClimate::TestReporter
1616
let(:fixture) { File.expand_path("../../fixtures/encoding_test_iso.rb", __FILE__) }
1717

1818
it 'falls back to git' do
19-
expect(File).to receive(:open).and_raise(EncodingError)
20-
expect(subject.blob_id).to eq('eb82c22dadb9c47a7fed87211623f6856e112f46')
19+
capture_io do
20+
expect(File).to receive(:open).and_raise(EncodingError)
21+
expect(subject.blob_id).to eq('eb82c22dadb9c47a7fed87211623f6856e112f46')
22+
end
2123
end
2224

2325
end

spec/lib/test_reporter_spec.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
require 'spec_helper'
22

33
describe CodeClimate::TestReporter do
4+
let(:logger) { double.as_null_object }
45
let(:reporter) { CodeClimate::TestReporter.dup }
56

7+
before do
8+
allow(CodeClimate::TestReporter.configuration).to receive(:logger).and_return(logger)
9+
end
10+
611
describe '.run_on_current_branch?' do
712
it 'returns true if there is no branch configured' do
813
allow(reporter).to receive(:configured_branch).and_return(nil)
@@ -24,7 +29,7 @@
2429
end
2530

2631
it 'logs a message if false' do
27-
expect_any_instance_of(Logger).to receive(:info)
32+
expect(logger).to receive(:info)
2833

2934
allow(reporter).to receive(:current_branch).and_return("another-branch")
3035
allow(reporter).to receive(:configured_branch).and_return(:master)

spec/spec_helper.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ def capture_requests(stub)
2020
stub.to_return { |r| requests << r; {body: "hello"} }
2121
requests
2222
end
23+
24+
def capture_io
25+
stdout = $stdout
26+
stderr = $stderr
27+
$stdout = StringIO.new
28+
$stderr = StringIO.new
29+
30+
yield if block_given?
31+
32+
[$stdout, $stderr]
33+
ensure
34+
$stdout = stdout
35+
$stderr = stderr
36+
end
2337
end
2438

2539
RSpec.configure do |c|

0 commit comments

Comments
 (0)