mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
d6f55c7d42
* spec/ruby/library/win32ole/fixtures/event.xml use MSXML.DOMDocument instead of InternetExplorer.Application. InternetExplorer.Application is not available on some environments. Thanks to MSP-Greg (Greg L). * spec/ruby/library/win32ole/win32ole_event/on_event_spec.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65414 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
70 lines
2.3 KiB
Ruby
70 lines
2.3 KiB
Ruby
platform_is :windows do
|
|
require_relative '../fixtures/classes'
|
|
guard -> { WIN32OLESpecs::MSXML_AVAILABLE } do
|
|
|
|
def handler_global(event, *args)
|
|
@event_global += event
|
|
end
|
|
|
|
def handler_specific(*args)
|
|
@event_specific = "specific"
|
|
end
|
|
|
|
def handler_spec_alt(*args)
|
|
@event_spec_alt = "spec_alt"
|
|
end
|
|
|
|
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
|
|
@event_global = ''
|
|
@event_specific = ''
|
|
@event_spec_alt = ''
|
|
end
|
|
|
|
after :each do
|
|
@xml_dom = nil
|
|
@ev = nil
|
|
end
|
|
|
|
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
|
|
@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
|
|
@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
|
|
@event.should =~ /bar/
|
|
end
|
|
|
|
it "accepts a specific event handler and overrides a global event handler" do
|
|
@ev.on_event { |*args| handler_global(*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
|
|
@event_global.should == 'ondataavailable'
|
|
@event_global.should_not =~ /onreadystatechange/
|
|
@event_specific.should == ''
|
|
@event_spec_alt.should == "spec_alt"
|
|
end
|
|
end
|
|
end
|
|
end
|