forked from jruby/jruby
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestClasses.rb
93 lines (78 loc) · 1.74 KB
/
testClasses.rb
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
require 'test/minirunit'
test_check "Test Classes"
class Hello
def saveHelloWorld
@hello = "Hello World."
end
def getHelloWorld
@hello
end
end
hello = Hello.new
test_equal("Hello World." , hello.saveHelloWorld)
test_equal("Hello World." , hello.getHelloWorld)
c = Class.new
test_equal(Object, c.superclass)
c = Class.new(String)
test_equal(String, c.superclass)
test_exception(TypeError) {
Class.new(Kernel)
}
module TestClasses
testClass = Class.new
TestClass = testClass
test_equal('TestClasses::TestClass', testClass.name)
DifferentNameForTestClass = testClass
test_equal('TestClasses::TestClass', testClass.name)
testModule = Module.new
TestModule = testModule
test_equal('TestClasses::TestModule', testModule.name)
DifferentNameForTestModule = testModule
test_equal('TestClasses::TestModule', testModule.name)
def TestClasses.virtual
class << self
self
end
end
end
begin
class X < Foo::Bar
end
fail
rescue NameError => e
test_equal("uninitialized constant Foo", e.to_s)
end
begin
class X < TestClasses::Bar
end
fail
rescue NameError => e
test_equal("uninitialized constant TestClasses::Bar", e.to_s)
end
begin
class X < Class
end
fail
rescue TypeError => e
test_equal("can't make subclass of Class", e.to_s)
end
begin
class X < TestClasses.virtual
end
rescue TypeError => e
test_equal("can't make subclass of virtual class", e.to_s)
end
class MockObject
def self.mock methodName
define_method "showBug" do
@results ||= {}
@results["C"] = "Z"
fail "Hash should have something" if @results == {}
@results ||= {}
fail "||= destroyed a perfectly good hash" if @results == {}
end
end
mock :foo
end
mock = MockObject.new
mock.showBug