ext/win32ole/tests/testOLEEVENT.rb


DEFINITIONS

This source file includes following functions.


   1  require 'rubyunit'
   2  require 'win32ole'
   3  
   4  class TestWIN32OLE_EVENT < RUNIT::TestCase
   5    def setup
   6      @excel = WIN32OLE.new("Excel.Application")
   7      @excel.visible = true
   8    end
   9    def test_on_event
  10      book = @excel.workbooks.Add
  11      value = ""
  12      begin
  13        ev = WIN32OLE_EVENT.new(book, 'WorkbookEvents')
  14        ev.on_event('SheetChange'){|arg1, arg2| 
  15          begin
  16            value = arg1.value
  17          rescue
  18            value = $!.message
  19          end
  20        }
  21        book.Worksheets(1).Range("A1").value = "OK"
  22      ensure
  23        book.saved = true
  24      end
  25      assert_equal("OK", value)
  26    end
  27    def teardown
  28      @excel.quit
  29      @excel = nil
  30      GC.start
  31    end
  32  end
  33