@@ -17,39 +17,40 @@ def unexpected_log_entry
1717 end
1818
1919 def test_logger
20- log = Tempfile . new ( 'logfile' )
21- log . close
20+ in_temp_dir do | path |
21+ log_path = 'logfile.log'
2222
23- logger = Logger . new ( log . path )
24- logger . level = Logger ::DEBUG
23+ logger = Logger . new ( log_path , level : Logger ::DEBUG )
2524
26- @git = Git . open ( @wdir , :log => logger )
27- @git . branches . size
25+ @git = Git . open ( @wdir , :log => logger )
26+ @git . branches . size
2827
29- logc = File . read ( log . path )
28+ logc = File . read ( log_path )
3029
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 )
3332
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
3636 end
3737
3838 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'
4341
44- @git = Git . open ( @wdir , :log => logger )
45- @git . branches . size
42+ logger = Logger . new ( log_path , level : Logger ::INFO )
4643
47- logc = File . read ( log . path )
44+ @git = Git . open ( @wdir , :log => logger )
45+ @git . branches . size
4846
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 )
5148
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
5455 end
5556end
0 commit comments