Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions library/win32ole/fixtures/classes.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
require 'win32ole'

# win32ole deprecated constants like WIN32OLE_TYPELIB in Ruby 3.4
# but only added the replacements like WIN32OLE::TypeLib in Ruby 3.4.
# So we use the new-style constants in specs to avoid deprecation warnings
# and we define the new-style constants as the old ones if they don't exist yet.
WIN32OLE::TypeLib ||= WIN32OLE_TYPELIB
WIN32OLE::RuntimeError ||= WIN32OLERuntimeError
WIN32OLE::Method ||= WIN32OLE_METHOD
WIN32OLE::Type ||= WIN32OLE_TYPE
WIN32OLE::Event ||= WIN32OLE_EVENT
WIN32OLE::Param ||= WIN32OLE_PARAM

module WIN32OLESpecs
MSXML_AVAILABLE = WIN32OLE_TYPELIB.typelibs.any? { |t| t.name.start_with?('Microsoft XML') }
SYSTEM_MONITOR_CONTROL_AVAILABLE = WIN32OLE_TYPELIB.typelibs.any? { |t| t.name.start_with?('System Monitor Control') }
MSXML_AVAILABLE = WIN32OLE::TypeLib.typelibs.any? { |t| t.name.start_with?('Microsoft XML') }
SYSTEM_MONITOR_CONTROL_AVAILABLE = WIN32OLE::TypeLib.typelibs.any? { |t| t.name.start_with?('System Monitor Control') }

def self.new_ole(name)
tries = 0
begin
WIN32OLE.new(name)
rescue WIN32OLERuntimeError => e
rescue WIN32OLE::RuntimeError => e
if tries < 3
tries += 1
$stderr.puts "WIN32OLESpecs#new_ole retry (#{tries}): #{e.class}: #{e.message}"
Expand Down
4 changes: 2 additions & 2 deletions library/win32ole/win32ole/locale_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
begin
begin
WIN32OLE.locale = 1041
rescue WIN32OLERuntimeError
rescue WIN32OLE::RuntimeError
STDERR.puts("\n#{__FILE__}:#{__LINE__}:#{self.class.name}.test_s_locale_set is skipped(Japanese locale is not installed)")
return
end

WIN32OLE.locale.should == 1041
WIN32OLE.locale = WIN32OLE::LOCALE_SYSTEM_DEFAULT
-> { WIN32OLE.locale = 111 }.should raise_error WIN32OLERuntimeError
-> { WIN32OLE.locale = 111 }.should raise_error WIN32OLE::RuntimeError
WIN32OLE.locale.should == WIN32OLE::LOCALE_SYSTEM_DEFAULT
ensure
WIN32OLE.locale.should == WIN32OLE::LOCALE_SYSTEM_DEFAULT
Expand Down
4 changes: 2 additions & 2 deletions library/win32ole/win32ole/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
-> { WIN32OLESpecs.new_ole(42) }.should raise_error( TypeError )
end

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

end
Expand Down
4 changes: 2 additions & 2 deletions library/win32ole/win32ole/ole_func_methods_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
-> { @dict.ole_func_methods(1) }.should raise_error ArgumentError
end

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

it "contains a 'AddRef' method for Scripting Dictionary" do
Expand Down
4 changes: 2 additions & 2 deletions library/win32ole/win32ole/ole_get_methods_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
@win32ole = WIN32OLESpecs.new_ole('Shell.Application')
end

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

end
Expand Down
4 changes: 2 additions & 2 deletions library/win32ole/win32ole/ole_methods_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
-> { @dict.ole_methods(1) }.should raise_error ArgumentError
end

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

it "contains a 'AddRef' method for Scripting Dictionary" do
Expand Down
4 changes: 2 additions & 2 deletions library/win32ole/win32ole/ole_obj_help_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
-> { @dict.ole_obj_help(1) }.should raise_error ArgumentError
end

it "returns an instance of WIN32OLE_TYPE" do
@dict.ole_obj_help.kind_of?(WIN32OLE_TYPE).should be_true
it "returns an instance of WIN32OLE::Type" do
@dict.ole_obj_help.kind_of?(WIN32OLE::Type).should be_true
end
end
end
4 changes: 2 additions & 2 deletions library/win32ole/win32ole/ole_put_methods_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
-> { @dict.ole_put_methods(1) }.should raise_error ArgumentError
end

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

it "contains a 'Key' method for Scripting Dictionary" do
Expand Down
4 changes: 2 additions & 2 deletions library/win32ole/win32ole/shared/ole_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
-> { @dict.send(@method) }.should raise_error ArgumentError
end

it "returns the WIN32OLE_METHOD 'Add' if given 'Add'" do
it "returns the WIN32OLE::Method 'Add' if given 'Add'" do
result = @dict.send(@method, "Add")
result.kind_of?(WIN32OLE_METHOD).should be_true
result.kind_of?(WIN32OLE::Method).should be_true
result.name.should == 'Add'
end
end
Expand Down
14 changes: 7 additions & 7 deletions library/win32ole/win32ole_event/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require_relative '../fixtures/classes'

guard -> { WIN32OLESpecs::MSXML_AVAILABLE } do
describe "WIN32OLE_EVENT.new" do
describe "WIN32OLE::Event.new" do
before :all do
@xml_dom = WIN32OLESpecs.new_ole('MSXML.DOMDocument')
end
Expand All @@ -13,21 +13,21 @@
end

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

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

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

it "creates WIN32OLE_EVENT object" do
ev = WIN32OLE_EVENT.new(@xml_dom)
ev.should be_kind_of WIN32OLE_EVENT
it "creates WIN32OLE::Event object" do
ev = WIN32OLE::Event.new(@xml_dom)
ev.should be_kind_of WIN32OLE::Event
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions library/win32ole/win32ole_event/on_event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ def handler_spec_alt(*args)
@event_spec_alt = "spec_alt"
end

describe "WIN32OLE_EVENT#on_event" do
describe "WIN32OLE::Event#on_event" do
before :all do
@fn_xml = File.absolute_path "../fixtures/event.xml", __dir__
end

before :each do
@xml_dom = WIN32OLESpecs.new_ole 'MSXML.DOMDocument'
@xml_dom.async = true
@ev = WIN32OLE_EVENT.new @xml_dom
@ev = WIN32OLE::Event.new @xml_dom
@event_global = ''
@event_specific = ''
@event_spec_alt = ''
Expand All @@ -37,21 +37,21 @@ def handler_spec_alt(*args)
it "sets global event handler properly, and the handler is invoked by event loop" do
@ev.on_event { |*args| handler_global(*args) }
@xml_dom.loadXML "<program><name>Ruby</name><version>trunk</version></program>"
WIN32OLE_EVENT.message_loop
WIN32OLE::Event.message_loop
@event_global.should =~ /onreadystatechange/
end

it "accepts a String argument and the handler is invoked by event loop" do
@ev.on_event("onreadystatechange") { |*args| @event = 'foo' }
@xml_dom.loadXML "<program><name>Ruby</name><version>trunk</version></program>"
WIN32OLE_EVENT.message_loop
WIN32OLE::Event.message_loop
@event.should =~ /foo/
end

it "accepts a Symbol argument and the handler is invoked by event loop" do
@ev.on_event(:onreadystatechange) { |*args| @event = 'bar' }
@xml_dom.loadXML "<program><name>Ruby</name><version>trunk</version></program>"
WIN32OLE_EVENT.message_loop
WIN32OLE::Event.message_loop
@event.should =~ /bar/
end

Expand All @@ -60,7 +60,7 @@ def handler_spec_alt(*args)
@ev.on_event("onreadystatechange") { |*args| handler_specific(*args) }
@ev.on_event("onreadystatechange") { |*args| handler_spec_alt(*args) }
@xml_dom.load @fn_xml
WIN32OLE_EVENT.message_loop
WIN32OLE::Event.message_loop
@event_global.should == 'ondataavailable'
@event_global.should_not =~ /onreadystatechange/
@event_specific.should == ''
Expand Down
6 changes: 3 additions & 3 deletions library/win32ole/win32ole_method/dispid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
platform_is :windows do
require 'win32ole'

describe "WIN32OLE_METHOD#dispid" do
describe "WIN32OLE::Method#dispid" do
before :each do
ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
@m = WIN32OLE_METHOD.new(ole_type, "namespace")
ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
@m = WIN32OLE::Method.new(ole_type, "namespace")
end

it "raises ArgumentError if argument is given" do
Expand Down
10 changes: 5 additions & 5 deletions library/win32ole/win32ole_method/event_interface_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
require_relative '../fixtures/classes'
guard -> { WIN32OLESpecs::SYSTEM_MONITOR_CONTROL_AVAILABLE } do

describe "WIN32OLE_METHOD#event_interface" do
describe "WIN32OLE::Method#event_interface" do
before :each do
ole_type = WIN32OLE_TYPE.new("System Monitor Control", "SystemMonitor")
@on_dbl_click_method = WIN32OLE_METHOD.new(ole_type, "OnDblClick")
ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
@namespace_method = WIN32OLE_METHOD.new(ole_type, "namespace")
ole_type = WIN32OLE::Type.new("System Monitor Control", "SystemMonitor")
@on_dbl_click_method = WIN32OLE::Method.new(ole_type, "OnDblClick")
ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
@namespace_method = WIN32OLE::Method.new(ole_type, "namespace")
end

it "raises ArgumentError if argument is given" do
Expand Down
6 changes: 3 additions & 3 deletions library/win32ole/win32ole_method/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
require_relative '../fixtures/classes'
guard -> { WIN32OLESpecs::SYSTEM_MONITOR_CONTROL_AVAILABLE } do

describe "WIN32OLE_METHOD#event?" do
describe "WIN32OLE::Method#event?" do
before :each do
ole_type = WIN32OLE_TYPE.new("System Monitor Control", "SystemMonitor")
@on_dbl_click_method = WIN32OLE_METHOD.new(ole_type, "OnDblClick")
ole_type = WIN32OLE::Type.new("System Monitor Control", "SystemMonitor")
@on_dbl_click_method = WIN32OLE::Method.new(ole_type, "OnDblClick")
end

it "raises ArgumentError if argument is given" do
Expand Down
10 changes: 5 additions & 5 deletions library/win32ole/win32ole_method/helpcontext_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
platform_is :windows do
require 'win32ole'

describe "WIN32OLE_METHOD#helpcontext" do
describe "WIN32OLE::Method#helpcontext" do
before :each do
ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "FileSystemObject")
@get_file_version = WIN32OLE_METHOD.new(ole_type, "GetFileVersion")
ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "File")
@m_file_name = WIN32OLE_METHOD.new(ole_type, "name")
ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "FileSystemObject")
@get_file_version = WIN32OLE::Method.new(ole_type, "GetFileVersion")
ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "File")
@m_file_name = WIN32OLE::Method.new(ole_type, "name")
end

it "raises ArgumentError if argument is given" do
Expand Down
6 changes: 3 additions & 3 deletions library/win32ole/win32ole_method/helpfile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
platform_is :windows do
require 'win32ole'

describe "WIN32OLE_METHOD#helpfile" do
describe "WIN32OLE::Method#helpfile" do
before :each do
ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "File")
@m_file_name = WIN32OLE_METHOD.new(ole_type, "name")
ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "File")
@m_file_name = WIN32OLE::Method.new(ole_type, "name")
end

it "raises ArgumentError if argument is given" do
Expand Down
6 changes: 3 additions & 3 deletions library/win32ole/win32ole_method/helpstring_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
platform_is :windows do
require 'win32ole'

describe "WIN32OLE_METHOD#helpstring" do
describe "WIN32OLE::Method#helpstring" do
before :each do
ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "File")
@m_file_name = WIN32OLE_METHOD.new(ole_type, "name")
ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "File")
@m_file_name = WIN32OLE::Method.new(ole_type, "name")
end

it "raises ArgumentError if argument is given" do
Expand Down
6 changes: 3 additions & 3 deletions library/win32ole/win32ole_method/invkind_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
platform_is :windows do
require 'win32ole'

describe "WIN32OLE_METHOD#invkind" do
describe "WIN32OLE::Method#invkind" do
before :each do
ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "File")
@m_file_name = WIN32OLE_METHOD.new(ole_type, "name")
ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "File")
@m_file_name = WIN32OLE::Method.new(ole_type, "name")
end

it "raises ArgumentError if argument is given" do
Expand Down
6 changes: 3 additions & 3 deletions library/win32ole/win32ole_method/invoke_kind_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
platform_is :windows do
require 'win32ole'

describe "WIN32OLE_METHOD#invoke_kind" do
describe "WIN32OLE::Method#invoke_kind" do
before :each do
ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "File")
@m_file_name = WIN32OLE_METHOD.new(ole_type, "name")
ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "File")
@m_file_name = WIN32OLE::Method.new(ole_type, "name")
end

it "raises ArgumentError if argument is given" do
Expand Down
2 changes: 1 addition & 1 deletion library/win32ole/win32ole_method/name_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
platform_is :windows do
require 'win32ole'

describe "WIN32OLE_METHOD#name" do
describe "WIN32OLE::Method#name" do
it_behaves_like :win32ole_method_name, :name

end
Expand Down
22 changes: 11 additions & 11 deletions library/win32ole/win32ole_method/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@
platform_is :windows do
require 'win32ole'

describe "WIN32OLE_METHOD.new" do
describe "WIN32OLE::Method.new" do
before :each do
@ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
@ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
end

it "raises TypeError when given non-strings" do
-> { WIN32OLE_METHOD.new(1, 2) }.should raise_error TypeError
-> { WIN32OLE::Method.new(1, 2) }.should raise_error TypeError
end

it "raises ArgumentError if only 1 argument is given" do
-> { WIN32OLE_METHOD.new("hello") }.should raise_error ArgumentError
-> { WIN32OLE_METHOD.new(@ole_type) }.should raise_error ArgumentError
-> { WIN32OLE::Method.new("hello") }.should raise_error ArgumentError
-> { WIN32OLE::Method.new(@ole_type) }.should raise_error ArgumentError
end

it "returns a valid WIN32OLE_METHOD object" do
WIN32OLE_METHOD.new(@ole_type, "Open").should be_kind_of WIN32OLE_METHOD
WIN32OLE_METHOD.new(@ole_type, "open").should be_kind_of WIN32OLE_METHOD
it "returns a valid WIN32OLE::Method object" do
WIN32OLE::Method.new(@ole_type, "Open").should be_kind_of WIN32OLE::Method
WIN32OLE::Method.new(@ole_type, "open").should be_kind_of WIN32OLE::Method
end

it "raises WIN32OLERuntimeError if the method does not exist" do
-> { WIN32OLE_METHOD.new(@ole_type, "NonexistentMethod") }.should raise_error WIN32OLERuntimeError
it "raises WIN32OLE::RuntimeError if the method does not exist" do
-> { WIN32OLE::Method.new(@ole_type, "NonexistentMethod") }.should raise_error WIN32OLE::RuntimeError
end

it "raises TypeError if second argument is not a String" do
-> { WIN32OLE_METHOD.new(@ole_type, 5) }.should raise_error TypeError
-> { WIN32OLE::Method.new(@ole_type, 5) }.should raise_error TypeError
end

end
Expand Down
6 changes: 3 additions & 3 deletions library/win32ole/win32ole_method/offset_vtbl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
platform_is :windows do
require 'win32ole'

describe "WIN32OLE_METHOD#offset_vtbl" do
describe "WIN32OLE::Method#offset_vtbl" do
before :each do
ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "File")
@m_file_name = WIN32OLE_METHOD.new(ole_type, "name")
ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "File")
@m_file_name = WIN32OLE::Method.new(ole_type, "name")
end

it "raises ArgumentError if argument is given" do
Expand Down
Loading