File tree Expand file tree Collapse file tree 4 files changed +23
-17
lines changed Expand file tree Collapse file tree 4 files changed +23
-17
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ def daemonize
3333unless Dir . singleton_methods . include? ( :exists? )
3434 class Dir
3535 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
3737 Dir . exist? ( file_name )
3838 end
3939 end
@@ -42,7 +42,7 @@ def self.exists?(file_name)
4242unless File . singleton_methods . include? ( :exists? )
4343 class File
4444 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
4646 File . exist? ( file_name )
4747 end
4848 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
22module Kernel
33 def with_verbose_disabled
44 verbose , $VERBOSE = $VERBOSE, nil
55 result = yield
66 $VERBOSE = verbose
77 return result
88 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
918end
Original file line number Diff line number Diff line change @@ -15,19 +15,12 @@ def stop
1515 end
1616end
1717
18- def without_warnings
19- flag = $VERBOSE
20- $VERBOSE = nil
21- yield
22- $VERBOSE = flag
23- end
24-
2518describe Puppet ::Agent do
2619 before do
2720 @agent = Puppet ::Agent . new ( AgentTestClient , false )
2821
2922 # 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 ) }
3124 allow ( Puppet ::Application ) . to receive ( :clear? ) . and_return ( true )
3225 Puppet ::Application . class_eval do
3326 class << self
@@ -44,7 +37,7 @@ def controlled_run(&block)
4437
4538 after do
4639 # 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 }
4841 end
4942
5043 it "should set its client class at initialization" do
Original file line number Diff line number Diff line change 1212 expect ( Dir . exists? ( __dir__ ) ) . to be true
1313 end
1414
15- if RUBY_VERSION >= '3.2'
15+ if RUBY_VERSION >= '3.2'
1616 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
1921 end
2022 end
2123 end
3335
3436 if RUBY_VERSION >= '3.2'
3537 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
3842 end
3943 end
4044 end
You can’t perform that action at this time.
0 commit comments