@@ -17,39 +17,40 @@ def unexpected_log_entry
17
17
end
18
18
19
19
def test_logger
20
- log = Tempfile . new ( 'logfile' )
21
- log . close
20
+ in_temp_dir do | path |
21
+ log_path = 'logfile.log'
22
22
23
- logger = Logger . new ( log . path )
24
- logger . level = Logger ::DEBUG
23
+ logger = Logger . new ( log_path , level : Logger ::DEBUG )
25
24
26
- @git = Git . open ( @wdir , :log => logger )
27
- @git . branches . size
25
+ @git = Git . open ( @wdir , :log => logger )
26
+ @git . branches . size
28
27
29
- logc = File . read ( log . path )
28
+ logc = File . read ( log_path )
30
29
31
- expected_log_entry = /INFO -- : \[ "git", "(?<global_options>.*?)", "branch", "-a"/
32
- assert_match ( expected_log_entry , logc , missing_log_entry )
30
+ expected_log_entry = /INFO -- : \[ "git", "(?<global_options>.*?)", "branch", "-a"/
31
+ assert_match ( expected_log_entry , logc , missing_log_entry )
33
32
34
- expected_log_entry = /DEBUG -- : stdout:\n " cherry/
35
- assert_match ( expected_log_entry , logc , missing_log_entry )
33
+ expected_log_entry = /DEBUG -- : stdout:\n " cherry/
34
+ assert_match ( expected_log_entry , logc , missing_log_entry )
35
+ end
36
36
end
37
37
38
38
def test_logging_at_info_level_should_not_show_debug_messages
39
- log = Tempfile . new ( 'logfile' )
40
- log . close
41
- logger = Logger . new ( log . path )
42
- logger . level = Logger ::INFO
39
+ in_temp_dir do |path |
40
+ log_path = 'logfile.log'
43
41
44
- @git = Git . open ( @wdir , :log => logger )
45
- @git . branches . size
42
+ logger = Logger . new ( log_path , level : Logger ::INFO )
46
43
47
- logc = File . read ( log . path )
44
+ @git = Git . open ( @wdir , :log => logger )
45
+ @git . branches . size
48
46
49
- expected_log_entry = /INFO -- : \[ "git", "(?<global_options>.*?)", "branch", "-a"/
50
- assert_match ( expected_log_entry , logc , missing_log_entry )
47
+ logc = File . read ( log_path )
51
48
52
- expected_log_entry = /DEBUG -- : stdout:\n " cherry/
53
- assert_not_match ( expected_log_entry , logc , unexpected_log_entry )
49
+ expected_log_entry = /INFO -- : \[ "git", "(?<global_options>.*?)", "branch", "-a"/
50
+ assert_match ( expected_log_entry , logc , missing_log_entry )
51
+
52
+ expected_log_entry = /DEBUG -- : stdout:\n " cherry/
53
+ assert_not_match ( expected_log_entry , logc , unexpected_log_entry )
54
+ end
54
55
end
55
56
end
0 commit comments