Pop.Box/spec/instances_spec.lua
Paul Liverman III 8ea4b63878 Squashed 'src/lib/middleclass/' content from commit 27a64f1
git-subtree-dir: src/lib/middleclass
git-subtree-split: 27a64f107e61532006030a6168e4fe6a71eee9a2
2017-10-10 00:17:15 -07:00

66 lines
1.4 KiB
Lua

local class = require 'middleclass'
describe('An instance', function()
describe('attributes', function()
local Person
before_each(function()
Person = class('Person')
function Person:initialize(name)
self.name = name
end
end)
it('are available in the instance after being initialized', function()
local bob = Person:new('bob')
assert.equal(bob.name, 'bob')
end)
it('are available in the instance after being initialized by a superclass', function()
local AgedPerson = class('AgedPerson', Person)
function AgedPerson:initialize(name, age)
Person.initialize(self, name)
self.age = age
end
local pete = AgedPerson:new('pete', 31)
assert.equal(pete.name, 'pete')
assert.equal(pete.age, 31)
end)
end)
describe('methods', function()
local A, B, a, b
before_each(function()
A = class('A')
function A:overridden() return 'foo' end
function A:regular() return 'regular' end
B = class('B', A)
function B:overridden() return 'bar' end
a = A:new()
b = B:new()
end)
it('are available for any instance', function()
assert.equal(a:overridden(), 'foo')
end)
it('are inheritable', function()
assert.equal(b:regular(), 'regular')
end)
it('are overridable', function()
assert.equal(b:overridden(), 'bar')
end)
end)
end)