Skip to content

Commit 8369559

Browse files
committed
Fix WIN32OLE deprecated constants warnings
1 parent 392c97e commit 8369559

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+202
-191
lines changed

library/win32ole/fixtures/classes.rb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
require 'win32ole'
22

3+
# win32ole deprecated constants like WIN32OLE_TYPELIB in Ruby 3.4
4+
# but only added the replacements like WIN32OLE::TypeLib in Ruby 3.4.
5+
# So we use the new-style constants in specs to avoid deprecation warnings
6+
# and we define the new-style constants as the old ones if they don't exist yet.
7+
WIN32OLE::TypeLib ||= WIN32OLE_TYPELIB
8+
WIN32OLE::RuntimeError ||= WIN32OLERuntimeError
9+
WIN32OLE::Method ||= WIN32OLE_METHOD
10+
WIN32OLE::Type ||= WIN32OLE_TYPE
11+
WIN32OLE::Event ||= WIN32OLE_EVENT
12+
WIN32OLE::Param ||= WIN32OLE_PARAM
13+
314
module WIN32OLESpecs
4-
MSXML_AVAILABLE = WIN32OLE_TYPELIB.typelibs.any? { |t| t.name.start_with?('Microsoft XML') }
5-
SYSTEM_MONITOR_CONTROL_AVAILABLE = WIN32OLE_TYPELIB.typelibs.any? { |t| t.name.start_with?('System Monitor Control') }
15+
MSXML_AVAILABLE = WIN32OLE::TypeLib.typelibs.any? { |t| t.name.start_with?('Microsoft XML') }
16+
SYSTEM_MONITOR_CONTROL_AVAILABLE = WIN32OLE::TypeLib.typelibs.any? { |t| t.name.start_with?('System Monitor Control') }
617

718
def self.new_ole(name)
819
tries = 0
920
begin
1021
WIN32OLE.new(name)
11-
rescue WIN32OLERuntimeError => e
22+
rescue WIN32OLE::RuntimeError => e
1223
if tries < 3
1324
tries += 1
1425
$stderr.puts "WIN32OLESpecs#new_ole retry (#{tries}): #{e.class}: #{e.message}"

library/win32ole/win32ole/locale_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
begin
1414
begin
1515
WIN32OLE.locale = 1041
16-
rescue WIN32OLERuntimeError
16+
rescue WIN32OLE::RuntimeError
1717
STDERR.puts("\n#{__FILE__}:#{__LINE__}:#{self.class.name}.test_s_locale_set is skipped(Japanese locale is not installed)")
1818
return
1919
end
2020

2121
WIN32OLE.locale.should == 1041
2222
WIN32OLE.locale = WIN32OLE::LOCALE_SYSTEM_DEFAULT
23-
-> { WIN32OLE.locale = 111 }.should raise_error WIN32OLERuntimeError
23+
-> { WIN32OLE.locale = 111 }.should raise_error WIN32OLE::RuntimeError
2424
WIN32OLE.locale.should == WIN32OLE::LOCALE_SYSTEM_DEFAULT
2525
ensure
2626
WIN32OLE.locale.should == WIN32OLE::LOCALE_SYSTEM_DEFAULT

library/win32ole/win32ole/new_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
-> { WIN32OLESpecs.new_ole(42) }.should raise_error( TypeError )
1818
end
1919

20-
it "raises WIN32OLERuntimeError if invalid string is given" do
21-
-> { WIN32OLE.new('foo') }.should raise_error( WIN32OLERuntimeError )
20+
it "raises WIN32OLE::RuntimeError if invalid string is given" do
21+
-> { WIN32OLE.new('foo') }.should raise_error( WIN32OLE::RuntimeError )
2222
end
2323

2424
end

library/win32ole/win32ole/ole_func_methods_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
-> { @dict.ole_func_methods(1) }.should raise_error ArgumentError
1212
end
1313

14-
it "returns an array of WIN32OLE_METHODs" do
15-
@dict.ole_func_methods.all? { |m| m.kind_of? WIN32OLE_METHOD }.should be_true
14+
it "returns an array of WIN32OLE::Methods" do
15+
@dict.ole_func_methods.all? { |m| m.kind_of? WIN32OLE::Method }.should be_true
1616
end
1717

1818
it "contains a 'AddRef' method for Scripting Dictionary" do

library/win32ole/win32ole/ole_get_methods_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
@win32ole = WIN32OLESpecs.new_ole('Shell.Application')
99
end
1010

11-
it "returns an array of WIN32OLE_METHOD objects" do
12-
@win32ole.ole_get_methods.all? {|m| m.kind_of? WIN32OLE_METHOD}.should be_true
11+
it "returns an array of WIN32OLE::Method objects" do
12+
@win32ole.ole_get_methods.all? {|m| m.kind_of? WIN32OLE::Method}.should be_true
1313
end
1414

1515
end

library/win32ole/win32ole/ole_methods_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
-> { @dict.ole_methods(1) }.should raise_error ArgumentError
1212
end
1313

14-
it "returns an array of WIN32OLE_METHODs" do
15-
@dict.ole_methods.all? { |m| m.kind_of? WIN32OLE_METHOD }.should be_true
14+
it "returns an array of WIN32OLE::Methods" do
15+
@dict.ole_methods.all? { |m| m.kind_of? WIN32OLE::Method }.should be_true
1616
end
1717

1818
it "contains a 'AddRef' method for Scripting Dictionary" do

library/win32ole/win32ole/ole_obj_help_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
-> { @dict.ole_obj_help(1) }.should raise_error ArgumentError
1313
end
1414

15-
it "returns an instance of WIN32OLE_TYPE" do
16-
@dict.ole_obj_help.kind_of?(WIN32OLE_TYPE).should be_true
15+
it "returns an instance of WIN32OLE::Type" do
16+
@dict.ole_obj_help.kind_of?(WIN32OLE::Type).should be_true
1717
end
1818
end
1919
end

library/win32ole/win32ole/ole_put_methods_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
-> { @dict.ole_put_methods(1) }.should raise_error ArgumentError
1212
end
1313

14-
it "returns an array of WIN32OLE_METHODs" do
15-
@dict.ole_put_methods.all? { |m| m.kind_of? WIN32OLE_METHOD }.should be_true
14+
it "returns an array of WIN32OLE::Methods" do
15+
@dict.ole_put_methods.all? { |m| m.kind_of? WIN32OLE::Method }.should be_true
1616
end
1717

1818
it "contains a 'Key' method for Scripting Dictionary" do

library/win32ole/win32ole/shared/ole_method.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
-> { @dict.send(@method) }.should raise_error ArgumentError
1111
end
1212

13-
it "returns the WIN32OLE_METHOD 'Add' if given 'Add'" do
13+
it "returns the WIN32OLE::Method 'Add' if given 'Add'" do
1414
result = @dict.send(@method, "Add")
15-
result.kind_of?(WIN32OLE_METHOD).should be_true
15+
result.kind_of?(WIN32OLE::Method).should be_true
1616
result.name.should == 'Add'
1717
end
1818
end

library/win32ole/win32ole_event/new_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require_relative '../fixtures/classes'
44

55
guard -> { WIN32OLESpecs::MSXML_AVAILABLE } do
6-
describe "WIN32OLE_EVENT.new" do
6+
describe "WIN32OLE::Event.new" do
77
before :all do
88
@xml_dom = WIN32OLESpecs.new_ole('MSXML.DOMDocument')
99
end
@@ -13,21 +13,21 @@
1313
end
1414

1515
it "raises TypeError given invalid argument" do
16-
-> { WIN32OLE_EVENT.new "A" }.should raise_error TypeError
16+
-> { WIN32OLE::Event.new "A" }.should raise_error TypeError
1717
end
1818

1919
it "raises RuntimeError if event does not exist" do
20-
-> { WIN32OLE_EVENT.new(@xml_dom, 'A') }.should raise_error RuntimeError
20+
-> { WIN32OLE::Event.new(@xml_dom, 'A') }.should raise_error RuntimeError
2121
end
2222

2323
it "raises RuntimeError if OLE object has no events" do
2424
dict = WIN32OLESpecs.new_ole('Scripting.Dictionary')
25-
-> { WIN32OLE_EVENT.new(dict) }.should raise_error RuntimeError
25+
-> { WIN32OLE::Event.new(dict) }.should raise_error RuntimeError
2626
end
2727

28-
it "creates WIN32OLE_EVENT object" do
29-
ev = WIN32OLE_EVENT.new(@xml_dom)
30-
ev.should be_kind_of WIN32OLE_EVENT
28+
it "creates WIN32OLE::Event object" do
29+
ev = WIN32OLE::Event.new(@xml_dom)
30+
ev.should be_kind_of WIN32OLE::Event
3131
end
3232
end
3333
end

0 commit comments

Comments
 (0)