ruby/spec/rubyspec/library/win32ole/win32ole_event/on_event_spec.rb
eregon 95e8c48dd3 Add in-tree mspec and ruby/spec
* For easier modifications of ruby/spec by MRI developers.
* .gitignore: track changes under spec.
* spec/mspec, spec/rubyspec: add in-tree mspec and ruby/spec.
  These files can therefore be updated like any other file in MRI.
  Instructions are provided in spec/README.
  [Feature #13156] [ruby-core:79246]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-07 12:04:49 +00:00

62 lines
1.7 KiB
Ruby

require File.expand_path('../../fixtures/classes', __FILE__)
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
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'
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/
end
end
end