ruby-changes:53199
From: suke <ko1@a...>
Date: Sun, 28 Oct 2018 15:11:35 +0900 (JST)
Subject: [ruby-changes:53199] suke:r65414 (trunk): use MSXML.DOMDocument instead of InternetExplorer.Application
suke 2018-10-28 15:11:30 +0900 (Sun, 28 Oct 2018) New Revision: 65414 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65414 Log: use MSXML.DOMDocument instead of InternetExplorer.Application * 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. Added files: trunk/spec/ruby/library/win32ole/fixtures/event.xml Modified files: trunk/spec/ruby/library/win32ole/win32ole_event/on_event_spec.rb Index: spec/ruby/library/win32ole/win32ole_event/on_event_spec.rb =================================================================== --- spec/ruby/library/win32ole/win32ole_event/on_event_spec.rb (revision 65413) +++ spec/ruby/library/win32ole/win32ole_event/on_event_spec.rb (revision 65414) @@ -1,62 +1,70 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/win32ole/win32ole_event/on_event_spec.rb#L1 -require_relative '../fixtures/classes' - platform_is :windows do - require 'win32ole' - - def default_handler(event, *args) - @event += event - end - - def alternate_handler(event, *args) - @event2 = "alternate" - end - - def handler3(event, *args) - @event3 += event - end - - - describe "WIN32OLE_EVENT#on_event with no argument" do - before :each do - @ie = WIN32OLESpecs.new_ole('InternetExplorer.Application') - @ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents') - @event = '' - @event2 = '' - @event3 = '' - @ie.StatusBar = true - end - - after :each do - @ie.Quit - end - - it "sets event handler properly, and the handler is invoked by event loop" do - @ev.on_event { |*args| default_handler(*args) } - @ie.StatusText='hello' - WIN32OLE_EVENT.message_loop - @event.should =~ /StatusTextChange/ - end - - it "accepts a String argument, sets event handler properly, and the handler is invoked by event loop" do - @ev.on_event("StatusTextChange") { |*args| @event = 'foo' } - @ie.StatusText='hello' - WIN32OLE_EVENT.message_loop - @event.should =~ /foo/ - end + require_relative '../fixtures/classes' + guard -> { WIN32OLESpecs::MSXML_AVAILABLE } do - it "registers multiple event handlers for the same event" do - @ev.on_event("StatusTextChange") { |*args| default_handler(*args) } - @ev.on_event("StatusTextChange") { |*args| alternate_handler(*args) } - @ie.StatusText= 'hello' - WIN32OLE_EVENT.message_loop - @event2.should == 'alternate' + def handler_global(event, *args) + @event_global += event end - it "accepts a Symbol argument, sets event handler properly, and the handler is invoked by event loop" do - @ev.on_event(:StatusTextChange) { |*args| @event = 'foo' } - @ie.StatusText='hello' - WIN32OLE_EVENT.message_loop - @event.should =~ /foo/ + 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 Index: spec/ruby/library/win32ole/fixtures/event.xml =================================================================== --- spec/ruby/library/win32ole/fixtures/event.xml (nonexistent) +++ spec/ruby/library/win32ole/fixtures/event.xml (revision 65414) @@ -0,0 +1,4 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/win32ole/fixtures/event.xml#L1 +<program> + <name>Ruby</name> + <version>trunk</version> +</program> -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/