File tree 6 files changed +32
-54
lines changed
6 files changed +32
-54
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
- result = yield
6
- $VERBOSE = verbose
7
- return result
5
+ begin
6
+ yield
7
+ ensure
8
+ $VERBOSE = verbose
9
+ end
10
+ end
11
+
12
+ def with_verbose_enabled
13
+ verbose , $VERBOSE = $VERBOSE, true
14
+ begin
15
+ yield
16
+ ensure
17
+ $VERBOSE = verbose
18
+ end
8
19
end
9
20
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
- # make Puppet::Application safe for stubbing; restore in an :after block; silence warnings for this.
30
- without_warnings { Puppet ::Application = Class . new ( Puppet ::Application ) }
22
+ # make Puppet::Application safe for stubbing
23
+ stub_const ( ' 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
@@ -42,11 +35,6 @@ def controlled_run(&block)
42
35
allow ( Puppet ::SSL ::StateMachine ) . to receive ( :new ) . and_return ( machine )
43
36
end
44
37
45
- after do
46
- # restore Puppet::Application from stub-safe subclass, and silence warnings
47
- without_warnings { Puppet ::Application = Puppet ::Application . superclass }
48
- end
49
-
50
38
it "should set its client class at initialization" do
51
39
expect ( Puppet ::Agent . new ( "foo" , false ) . client_class ) . to eq ( "foo" )
52
40
end
Original file line number Diff line number Diff line change 3
3
require 'puppet/agent'
4
4
require 'puppet/configurer'
5
5
6
- def without_warnings
7
- flag = $VERBOSE
8
- $VERBOSE = nil
9
- yield
10
- $VERBOSE = flag
11
- end
12
-
13
6
describe Puppet ::Daemon , :unless => Puppet ::Util ::Platform . windows? do
14
7
include PuppetSpec ::Files
15
8
@@ -91,14 +84,8 @@ def run_loop(jobs)
91
84
describe "when stopping" do
92
85
before do
93
86
allow ( Puppet ::Util ::Log ) . to receive ( :close_all )
94
- # to make the global safe to mock, set it to a subclass of itself,
95
- # then restore it in an after pass
96
- without_warnings { Puppet ::Application = Class . new ( Puppet ::Application ) }
97
- end
98
-
99
- after do
100
- # restore from the superclass so we lose the stub garbage
101
- without_warnings { Puppet ::Application = Puppet ::Application . superclass }
87
+ # to make the global safe to mock, set it to a subclass of itself
88
+ stub_const ( 'Puppet::Application' , Class . new ( Puppet ::Application ) )
102
89
end
103
90
104
91
it 'should request a stop from Puppet::Application' do
@@ -143,11 +130,7 @@ def run_loop(jobs)
143
130
144
131
describe "when restarting" do
145
132
before do
146
- without_warnings { Puppet ::Application = Class . new ( Puppet ::Application ) }
147
- end
148
-
149
- after do
150
- without_warnings { Puppet ::Application = Puppet ::Application . superclass }
133
+ stub_const ( 'Puppet::Application' , Class . new ( Puppet ::Application ) )
151
134
end
152
135
153
136
it 'should set Puppet::Application.restart!' do
Original file line number Diff line number Diff line change @@ -266,15 +266,7 @@ def exec_stub(options = {})
266
266
267
267
describe "on platforms where path separator is not :" do
268
268
before :each do
269
- @old_verbosity = $VERBOSE
270
- $VERBOSE = nil
271
- @old_separator = File ::PATH_SEPARATOR
272
- File ::PATH_SEPARATOR = 'q'
273
- end
274
-
275
- after :each do
276
- File ::PATH_SEPARATOR = @old_separator
277
- $VERBOSE = @old_verbosity
269
+ stub_const ( 'File::PATH_SEPARATOR' , 'q' )
278
270
end
279
271
280
272
it "should use the path separator of the current platform" 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