2011-08-08 21:59:23 +00:00
|
|
|
require 'middleclass'
|
|
|
|
|
|
|
|
context('class()', function()
|
|
|
|
|
|
|
|
context('when given no params', function()
|
|
|
|
test('it throws an error', function()
|
|
|
|
assert_error(class)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
context('when given a name', function()
|
2011-08-13 01:12:21 +00:00
|
|
|
local TheClass
|
|
|
|
|
|
|
|
before(function()
|
|
|
|
TheClass = class('TheClass')
|
|
|
|
end)
|
2011-08-08 21:59:23 +00:00
|
|
|
|
|
|
|
test('the resulting class has the correct name', function()
|
|
|
|
assert_equal(TheClass.name, 'TheClass')
|
|
|
|
end)
|
|
|
|
|
|
|
|
test('the resulting class has Object as its superclass', function()
|
2011-08-13 01:38:31 +00:00
|
|
|
assert_equal(TheClass.super, Object)
|
2011-08-08 21:59:23 +00:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
context('when given a name and a superclass', function()
|
|
|
|
local TheSuperClass = class('TheSuperClass')
|
|
|
|
local TheSubClass = class('TheSubClass', TheSuperClass)
|
|
|
|
|
|
|
|
test('the resulting class has the correct name', function()
|
|
|
|
assert_equal(TheSubClass.name, 'TheSubClass')
|
|
|
|
end)
|
|
|
|
|
|
|
|
test('the resulting class has the correct superclass', function()
|
2011-08-13 01:38:31 +00:00
|
|
|
assert_equal(TheSubClass.super, TheSuperClass)
|
2011-08-08 21:59:23 +00:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
end)
|