File tree Expand file tree Collapse file tree 3 files changed +24
-3
lines changed Expand file tree Collapse file tree 3 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -16,8 +16,10 @@ module CodeClimate::TestReporter
16
16
let ( :fixture ) { File . expand_path ( "../../fixtures/encoding_test_iso.rb" , __FILE__ ) }
17
17
18
18
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
21
23
end
22
24
23
25
end
Original file line number Diff line number Diff line change 1
1
require 'spec_helper'
2
2
3
3
describe CodeClimate ::TestReporter do
4
+ let ( :logger ) { double . as_null_object }
4
5
let ( :reporter ) { CodeClimate ::TestReporter . dup }
5
6
7
+ before do
8
+ allow ( CodeClimate ::TestReporter . configuration ) . to receive ( :logger ) . and_return ( logger )
9
+ end
10
+
6
11
describe '.run_on_current_branch?' do
7
12
it 'returns true if there is no branch configured' do
8
13
allow ( reporter ) . to receive ( :configured_branch ) . and_return ( nil )
24
29
end
25
30
26
31
it 'logs a message if false' do
27
- expect_any_instance_of ( Logger ) . to receive ( :info )
32
+ expect ( logger ) . to receive ( :info )
28
33
29
34
allow ( reporter ) . to receive ( :current_branch ) . and_return ( "another-branch" )
30
35
allow ( reporter ) . to receive ( :configured_branch ) . and_return ( :master )
Original file line number Diff line number Diff line change @@ -20,6 +20,20 @@ def capture_requests(stub)
20
20
stub . to_return { |r | requests << r ; { body : "hello" } }
21
21
requests
22
22
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
23
37
end
24
38
25
39
RSpec . configure do |c |
You can’t perform that action at this time.
0 commit comments