-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathTestCommon_spec.lua
More file actions
70 lines (62 loc) · 2.32 KB
/
Copy pathTestCommon_spec.lua
File metadata and controls
70 lines (62 loc) · 2.32 KB
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
describe("Common", function()
describe("Class creation and use", function()
it("produces error when parent constructors are not called", function()
local ParentClass = newClass("ConstructorTestParentClass")
function ParentClass:init()
return self
end
local ChildClass = newClass("ConstructorTestProblemChildClass", "ConstructorTestParentClass")
function ChildClass:init()
-- Intentionally does not call self:ConstructorTestParentClass()
return self
end
common.classes.ConstructorTestParent = ParentClass
common.classes.ConstructorTestProblemChild = ChildClass
assert.has_error(function()
new("ConstructorTestProblemChild"):init()
end, "Parent class 'ConstructorTestParentClass' of class 'ConstructorTestProblemChild' must be initialised")
common.classes.ConstructorTestParent = nil
common.classes.ConstructorTestProblemChild = nil
end)
it("produces an error if additional arguments are passed", function()
local StupidClass = newClass("NewAbuse")
function StupidClass:init(someParam)
return self
end
common.classes.NewAbuse = StupidClass
assert.has_no.errors(function()
local newObj = new("NewAbuse"):init("fish")
end)
assert.has_error(function()
local newObj = new("NewAbuse", "look I'm using the old syntax")
end)
end)
it("produces an error if it calls a parent class without giving it self", function()
local ParentClass = newClass("ConstructorTestParentClass")
function ParentClass:init()
return self
end
local ChildClass = newClass("ConstructorTestProblemChildClass", "ConstructorTestParentClass")
function ChildClass:init()
self.ConstructorTestParentClass()
return self
end
common.classes.ConstructorTestParent = ParentClass
common.classes.ConstructorTestProblemChild = ChildClass
assert.has_error(function()
new("ConstructorTestProblemChild"):init()
end)
common.classes.ConstructorTestParent = nil
common.classes.ConstructorTestProblemChild = nil
end)
it("produces an error if its constructor doesn't return the object", function()
local StupidClass = newClass("StupidClass")
function StupidClass:init()
end
common.classes.StupidClass = StupidClass
assert.has_error(function()
new("StupidClass"):init()
end, "Class StupidClass constructor did not return a value")
end)
end)
end)