summaryrefslogtreecommitdiff
path: root/spec/ruby/library/win32ole/win32ole_type/new_spec.rb
blob: 3c3aa1c3902fca1dfcf3277c1719bd224f07a52f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
platform_is :windows do
  require 'win32ole'

  describe "WIN32OLE_TYPE.new" do
    it "raises ArgumentError with no argument" do
      -> { WIN32OLE_TYPE.new }.should raise_error ArgumentError
    end

    it "raises ArgumentError with invalid string" do
      -> { WIN32OLE_TYPE.new("foo") }.should raise_error ArgumentError
    end

    it "raises TypeError if second argument is not a String" do
      -> { WIN32OLE_TYPE.new(1,2) }.should raise_error TypeError
      -> {
        WIN32OLE_TYPE.new('Microsoft Shell Controls And Automation',2)
      }.should raise_error TypeError
    end

    it "raise WIN32OLERuntimeError if OLE object specified is not found" do
      -> {
        WIN32OLE_TYPE.new('Microsoft Shell Controls And Automation','foo')
      }.should raise_error WIN32OLERuntimeError
      -> {
        WIN32OLE_TYPE.new('Microsoft Shell Controls And Automation','Application')
      }.should raise_error WIN32OLERuntimeError
    end

    it "creates WIN32OLE_TYPE object from name and valid type" do
      ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
      ole_type.should be_kind_of WIN32OLE_TYPE
    end

    it "creates WIN32OLE_TYPE object from CLSID and valid type" do
      ole_type2 = WIN32OLE_TYPE.new("{13709620-C279-11CE-A49E-444553540000}", "Shell")
      ole_type2.should be_kind_of WIN32OLE_TYPE
    end

  end
end