File tree 4 files changed +23
-17
lines changed
4 files changed +23
-17
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ def daemonize
33
33
unless Dir . singleton_methods . include? ( :exists? )
34
34
class Dir
35
35
def self . exists? ( file_name )
36
- warn ( ' exists? is a deprecated name , use exist? instead' )
36
+ warn ( "Dir. exists?(' #{ file_name } ') is deprecated, use Dir. exist? instead" ) if $VERBOSE
37
37
Dir . exist? ( file_name )
38
38
end
39
39
end
@@ -42,7 +42,7 @@ def self.exists?(file_name)
42
42
unless File . singleton_methods . include? ( :exists? )
43
43
class File
44
44
def self . exists? ( file_name )
45
- warn ( ' exists? is a deprecated name , use exist? instead' )
45
+ warn ( "File. exists?(' #{ file_name } ') is deprecated, use File. exist? instead" ) if $VERBOSE
46
46
File . exist? ( file_name )
47
47
end
48
48
end
Original file line number Diff line number Diff line change 1
- # Support code for running stuff with warnings disabled.
1
+ # Support code for running stuff with warnings disabled or enabled
2
2
module Kernel
3
3
def with_verbose_disabled
4
4
verbose , $VERBOSE = $VERBOSE, nil
5
5
result = yield
6
6
$VERBOSE = verbose
7
7
return result
8
8
end
9
+
10
+ def with_verbose_enabled
11
+ verbose , $VERBOSE = $VERBOSE, true
12
+ begin
13
+ yield
14
+ ensure
15
+ $VERBOSE = verbose
16
+ end
17
+ end
9
18
end
Original file line number Diff line number Diff line change @@ -15,19 +15,12 @@ def stop
15
15
end
16
16
end
17
17
18
- def without_warnings
19
- flag = $VERBOSE
20
- $VERBOSE = nil
21
- yield
22
- $VERBOSE = flag
23
- end
24
-
25
18
describe Puppet ::Agent do
26
19
before do
27
20
@agent = Puppet ::Agent . new ( AgentTestClient , false )
28
21
29
22
# make Puppet::Application safe for stubbing; restore in an :after block; silence warnings for this.
30
- without_warnings { Puppet ::Application = Class . new ( Puppet ::Application ) }
23
+ with_verbose_disabled { Puppet ::Application = Class . new ( Puppet ::Application ) }
31
24
allow ( Puppet ::Application ) . to receive ( :clear? ) . and_return ( true )
32
25
Puppet ::Application . class_eval do
33
26
class << self
@@ -44,7 +37,7 @@ def controlled_run(&block)
44
37
45
38
after do
46
39
# restore Puppet::Application from stub-safe subclass, and silence warnings
47
- without_warnings { Puppet ::Application = Puppet ::Application . superclass }
40
+ with_verbose_disabled { Puppet ::Application = Puppet ::Application . superclass }
48
41
end
49
42
50
43
it "should set its client class at initialization" do
Original file line number Diff line number Diff line change 12
12
expect ( Dir . exists? ( __dir__ ) ) . to be true
13
13
end
14
14
15
- if RUBY_VERSION >= '3.2'
15
+ if RUBY_VERSION >= '3.2'
16
16
it 'logs a warning message' do
17
- expect ( Dir ) . to receive ( :warn ) . with ( 'exists? is a deprecated name, use exist? instead' )
18
- Dir . exists? ( __dir__ )
17
+ expect ( Dir ) . to receive ( :warn ) . with ( "Dir.exists?('#{ __dir__ } ') is deprecated, use Dir.exist? instead" )
18
+ with_verbose_enabled do
19
+ Dir . exists? ( __dir__ )
20
+ end
19
21
end
20
22
end
21
23
end
33
35
34
36
if RUBY_VERSION >= '3.2'
35
37
it 'logs a warning message' do
36
- expect ( File ) . to receive ( :warn ) . with ( 'exists? is a deprecated name, use exist? instead' )
37
- File . exists? ( __FILE__ )
38
+ expect ( File ) . to receive ( :warn ) . with ( "File.exists?('#{ __FILE__ } ') is deprecated, use File.exist? instead" )
39
+ with_verbose_enabled do
40
+ File . exists? ( __FILE__ )
41
+ end
38
42
end
39
43
end
40
44
end
You can’t perform that action at this time.
0 commit comments