Skip to content

Commit

Permalink
cleaning tests
Browse files Browse the repository at this point in the history
  • Loading branch information
subnetmarco committed Mar 11, 2015
1 parent 88034b9 commit 21344b8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 35 deletions.
22 changes: 0 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,30 +97,8 @@ function Point:__tostring()
end
```

### Returning constructor errors
```lua
Rect = Point:extend()

function Rect:new(x, y, width, height)
if width > 100 then
return nil, "Width can't be greater than 100"
end

Rect.super.new(self, x, y)
self.width = width or 0
self.height = height or 0
end


local rect, err = Rect(10, 20, 200, 200)
if not rect then
print(err) -- The err variable contains the error message
end
```


## License

This module is free software; you can redistribute it and/or modify it under
the terms of the MIT license. See [LICENSE](LICENSE) for details.

26 changes: 13 additions & 13 deletions spec/classic_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ local BaseClass = Object:extend()
function BaseClass:new(name)
self._name = name
end
function BaseClass:get_name()
function BaseClass:getName()
return self._name
end
function BaseClass.say_something()
function BaseClass.getSomething()
return "something"
end

Expand All @@ -17,15 +17,15 @@ local ClassOne = BaseClass:extend()
function ClassOne:new(name)
ClassOne.super.new(self, name)
end
function ClassOne.say_something()
function ClassOne.getSomething()
return "something better"
end

-- ClassTwo extends BaseClass
local ClassTwo = BaseClass:extend()
function ClassTwo:new(name)
if name == "wrong" then
error({message = "Wrong value"})
error("Wrong value")
end
ClassTwo.super.new(self, name)
end
Expand All @@ -34,25 +34,25 @@ describe("classic #classic", function()
describe("Base tests", function()

it("Constructors should work", function()
local class_one = ClassOne("Mark")
local class_two = ClassTwo("John")
local classOne = ClassOne("Mark")
local classTwo = ClassTwo("John")

assert.are.same("Mark", class_one:get_name())
assert.are.same("John", class_two:get_name())
assert.are.same("Mark", classOne:getName())
assert.are.same("John", classTwo:getName())
end)
it("Static method should work", function()
local class_one = ClassOne("Mark")
local class_two = ClassTwo("John")
local classOne = ClassOne("Mark")
local classTwo = ClassTwo("John")

assert.are.same("something better", class_one:say_something())
assert.are.same("something", class_two:say_something())
assert.are.same("something better", classOne:getSomething())
assert.are.same("something", classTwo:getSomething())
end)
it("Constructor returns error", function()
local status, res = pcall(ClassTwo, "wrong")

assert.falsy(status)
assert.truthy(res)
assert.are.same("Wrong value", res.message)
assert.are.same("Wrong value", string.sub(res, string.len(res) - 10))
end)

end)
Expand Down

0 comments on commit 21344b8

Please sign in to comment.