Skip to content

Commit

Permalink
Merge pull request #9 from rdok/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Rizart Dokollari authored Apr 18, 2019
2 parents 689f389 + 6053237 commit cebf7c9
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 38 deletions.
3 changes: 2 additions & 1 deletion .busted
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
return {
_all = {
helper = 'tests/bootstrap.lua'
helper = 'tests/bootstrap.lua',
ROOT = {'tests'},
}
}
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ before_install:

script:
- sudo chmod +x docker/busted/entry-point.sh
- docker-compose run --rm busted tests -v
- docker-compose run --rm busted -v
2 changes: 1 addition & 1 deletion src/Command.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Command = {
return Pomodoro.new()
end

return HelpPage.new()
return HelpPage.print()
end
}

Expand Down
4 changes: 2 additions & 2 deletions src/HelpPage.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
HelpPage = {

new = function()
print = function()
-- Not using loop due to lua not guarantying any iteration order
-- TODO: find package offering this functionality when this table becomes
-- hard to maintain
Expand All @@ -11,3 +10,4 @@ HelpPage = {
CHAT_SYSTEM.AddMessage(CHAT_SYSTEM, '> stop Stop the current Pomodoro.')
end
}

3 changes: 1 addition & 2 deletions src/Listener.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ Listener = {
dispatch = function()
d(os.date("%d.%m.%Y %H:%M:%S"))
end
}

}
26 changes: 22 additions & 4 deletions src/Pomodoro.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
Pomodoro = {
duration = 1500, -- Seconds = 25 minutes
new = function()
pomodoro = {}
pomodoro.startedAt = os.time()
local pomodoro = Pomodoro
pomodoro.createdAt = os.time()
pomodoro.completedAt = nil

CHAT_SYSTEM.AddMessage(CHAT_SYSTEM, 'Pomodoro started.')

return pomodoro
end
}
end,

ping = function(self)
if (self.completedAt ~= nil) then
error("Error: Attempting to re-check finished Pomodoro. \nPlease report this at https://git.io/fjO3p")
end

local time = os.time()
local currentDuration = time - self.createdAt

if (currentDuration >= Pomodoro.duration) then
self.completedAt = time
CHAT_SYSTEM.AddMessage(CHAT_SYSTEM, 'Pomodoro finished.')
end

return pomodoro
end,
}
6 changes: 3 additions & 3 deletions tests/Acceptance/HelpPomodoro_spec.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
describe("Help Page:", function()
-- See https://github.com/rdok/eso-pomodoro/issues/3
-- https://github.com/rdok/eso-pomodoro/issues/3

it("A player may request the command's help page", function()
-- Given I am acting as a player
local player = require('Player')
require('Player')

-- When I request the help page
player:callHelpPage()
Player:callHelpPage()

-- Then i should see in the chat window a line from the help page
assert.chat_window_contains('Usage: pomodoro COMMAND')
Expand Down
6 changes: 3 additions & 3 deletions tests/Acceptance/StartPomodoro_spec.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
describe("Start pomodoro:", function()
-- See https://github.com/rdok/eso-pomodoro/issues/3
-- https://github.com/rdok/eso-pomodoro/issues/7

it("a player may start a pomodoro", function()
-- Given I am acting as a player
local player = require('Player')
require('Player')

-- When I start a new pomodoro
player:callStartPomodoro()
Player:callStartPomodoro()

-- Then i should see in the chat window message about the new pomodoro
assert.chat_window_contains('Pomodoro started.')
Expand Down
17 changes: 17 additions & 0 deletions tests/Acceptance/StopPomodoro_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
describe("Stop pomodoro:", function()

pending("a player may stop a pomodoro", function()
-- Given I am acting as a player
require('Player')

-- And I have started a pomodoro
Player.callStartPomodoro()

-- When I stop the pomodoro
Player.callStopPomodoro()

-- Then i should see in the chat window message about the new pomodoro
assert.chat_window_contains('Pomodoro stopped.')
end)

end)
10 changes: 5 additions & 5 deletions tests/Unit/Command_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ describe("Command", function()
end)

it("may initialize the help page", function()
spy.on(HelpPage, "new")
spy.on(HelpPage, "print")
Command.call()
assert.spy(HelpPage.new).was_called()
assert.spy(HelpPage.print).was_called()
end)

it("may initialize the help page with 'help' argument", function()
spy.on(HelpPage, "new")
spy.on(HelpPage, "print")
Command.call('help')
assert.spy(HelpPage.new).was_called()
assert.spy(HelpPage.print).was_called()
end)

it("may initialize a new pomodoro with 'start' argument", function()
spy.on(Pomodoro, "new")
Command.call('start')
assert.spy(Pomodoro.new).was_called()
assert.stub(Pomodoro.new).was_called()
end)
end)
2 changes: 1 addition & 1 deletion tests/Unit/HelpPage_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe("HelpPage", function()

it("should print the help page to the chat system upon initialization", function()
spy.on(CHAT_SYSTEM, "AddMessage")
HelpPage.new()
HelpPage.print()
for section, description in pairs(helpMessages) do
assert.spy(CHAT_SYSTEM.AddMessage).was_called_with(CHAT_SYSTEM, description)
end
Expand Down
34 changes: 29 additions & 5 deletions tests/Unit/Pomodoro_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,35 @@ describe("Pomodoro", function()
end)

it("should store the time the pomodoro started", function()
local pomodoro = Pomodoro.new()
assert.is_valid_time(pomodoro.startedAt)
local pomodoro = Pomodoro:new()
assert.is_valid_time(pomodoro.createdAt)
end)

--it("should error if pomodoro hasn't started", function()
-- pending("should error if pomodoro hasn't started")
--end)
it("should print message when pomodoro is completed.", function()
local pomodoro = Pomodoro:new()
pomodoro.createdAt = os.time() - 1500

spy.on(CHAT_SYSTEM, "AddMessage")
pomodoro:ping()
assert.spy(CHAT_SYSTEM.AddMessage)
.was_called_with(CHAT_SYSTEM, 'Pomodoro finished.')
end)

it("should not print completion message if pomodoro hasn't finished.", function()
local pomodoro = Pomodoro:new()
pomodoro.createdAt = os.time() - 1499

spy.on(CHAT_SYSTEM, "AddMessage")
pomodoro:ping()
assert.spy(CHAT_SYSTEM.AddMessage).was.not_called()
end)

it("should error when pomodoro has already been completed", function()
local pomodoro = Pomodoro:new()
pomodoro.completedAt = os.time()

assert.has_error(function()
pomodoro:ping()
end, "Error: Attempting to re-check finished Pomodoro. \nPlease report this at https://git.io/fjO3p")
end)
end)
2 changes: 1 addition & 1 deletion tests/_support/Assertions/ChatWindowAssertion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local say = require("say")

-- Consider instance of table a table that has the same functions key names
local function chat_window_contains(state, arguments)
if not type(arguments[1]) == "table" or #arguments ~= 1 then
if #arguments ~= 1 or not type(arguments[1]) == "string" then
return false
end

Expand Down
20 changes: 11 additions & 9 deletions tests/_support/Player.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
-- Mock player. That is, the eso engine acting in behalf of the user.
local Player = {}
Player = {
callHelpPage = function()
Command.call()
end,

function Player:callHelpPage()
Command.call()
end
callStartPomodoro = function()
Command.call('start')
end,

function Player:callStartPomodoro()
Command.call('start')
end

return Player
callStopPomodoro = function()
Command.call('start')
end,
}

0 comments on commit cebf7c9

Please sign in to comment.