Skip to content

Commit

Permalink
Fixes #70 - moved mock routines to new test_helpers folder
Browse files Browse the repository at this point in the history
  • Loading branch information
tredfern committed Mar 4, 2021
1 parent 8086659 commit 73c80e7
Show file tree
Hide file tree
Showing 30 changed files with 54 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .busted
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ return {
_all = {
lpath = "./?/init.lua;./ext/?.lua;./ext/?/init.lua;./ext/moonpie/?.lua;./ext/moonpie/?/init.lua;",
ROOT = {"game", "assets"},
helper = "test_helper.lua"
helper = "test_helpers/init.lua"
},
travis = {
verbose = true,
Expand Down
2 changes: 1 addition & 1 deletion game/rules/character/actions/heal_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

describe("game.rules.character.actions.heal", function()
local heal = require "game.rules.character.actions.heal"
local mockDispatch = require "mock_dispatch"
local mockDispatch = require "test_helpers.mock_dispatch"
local types = require "game.rules.character.actions.types"

it("dispatches an update to set the character health to a higher value", function()
Expand Down
8 changes: 4 additions & 4 deletions game/rules/character/actions/move_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
describe("game.rules.character.actions.move", function()
local character_move = require "game.rules.character.actions.move"
local types = require "game.rules.character.actions.types"
local mock_dispatch = require "mock_dispatch"
local mockDispatch = require "test_helpers.mock_dispatch"
local wrap_in_function = require "wrap_in_function"
local Skills = require "game.rules.skills"
local Attributes = require "game.rules.character.attributes"
Expand All @@ -22,8 +22,8 @@ describe("game.rules.character.actions.move", function()
}
local action = character_move(c, 19, 10)

action(mock_dispatch, wrap_in_function(state))
assert.is_true(mock_dispatch:received_action(types.character_set_position))
action(mockDispatch, wrap_in_function(state))
assert.is_true(mockDispatch:received_action(types.character_set_position))
end)

it("creates a melee attack action if there is another character in the square attempting to move to", function()
Expand All @@ -38,7 +38,7 @@ describe("game.rules.character.actions.move", function()
}

local action = character_move(player, 20, 11)
action(mock_dispatch, wrap_in_function(state))
action(mockDispatch, wrap_in_function(state))

assert.spy(Combat.actions.meleeAttack).was.called_with(player, enemy)
end)
Expand Down
2 changes: 1 addition & 1 deletion game/rules/character/actions/pickup_items_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

describe("game.rules.character.actions.pickup_items", function()
local pickupItems = require "game.rules.character.actions.pickup_items"
local mockDispatch = require "mock_dispatch"
local mockDispatch = require "test_helpers.mock_dispatch"
local character = require "game.rules.character"

local pickup = { x = 17, y = 19}
Expand Down
2 changes: 1 addition & 1 deletion game/rules/combat/actions/deal_damage_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

describe("game.rules.combat.actions.deal_damage", function()
local dealDamage = require "game.rules.combat.actions.deal_damage"
local mockDispatch = require "mock_dispatch"
local mockDispatch = require "test_helpers.mock_dispatch"
local Character = require "game.rules.character"

it("adjusts the characters health by a random die roll of the damage", function()
Expand Down
2 changes: 1 addition & 1 deletion game/rules/combat/actions/melee_attack_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe("game.rules.combat.actions.melee_attack", function()
local MeleeAttack = require "game.rules.combat.actions.melee_attack"
local attacker, defender, weapon, missWeapon
local Skills = require "game.rules.skills"
local MockDispatch = require "mock_dispatch"
local MockDispatch = require "test_helpers.mock_dispatch"

before_each(function()
MockDispatch:reset()
Expand Down
2 changes: 1 addition & 1 deletion game/rules/enemy/actions/check_spawn_enemy_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
describe("game.rules.enemy.actions.check_spawn_enemy", function()
local checkSpawnEnemy = require "game.rules.enemy.actions.check_spawn_enemy"
local mockRandom = require "moonpie.test_helpers.mock_random"
local mockDispatch = require "mock_dispatch"
local mockDispatch = require "test_helpers.mock_dispatch"

before_each(function()
mockDispatch:reset()
Expand Down
2 changes: 1 addition & 1 deletion game/rules/enemy/actions/think_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

describe("game.rules.enemy.actions.think", function()
local think = require "game.rules.enemy.actions.think"
local mockDispatch = require "mock_dispatch"
local mockDispatch = require "test_helpers.mock_dispatch"


it("calls the ai routine for the enemy", function()
Expand Down
2 changes: 1 addition & 1 deletion game/rules/enemy/ai/move_towards_player_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

describe("game.rules.enemy.ai.move_towards_player", function()
local moveTowardsPlayer = require "game.rules.enemy.ai.move_towards_player"
local mockDispatch = require "mock_dispatch"
local mockDispatch = require "test_helpers.mock_dispatch"

it("dispatches a move action in the direction of the player", function()
local character = require "game.rules.character"
Expand Down
2 changes: 1 addition & 1 deletion game/rules/enemy/ai/random_movement_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

describe("game.rules.enemy.ai.random_movement", function()
local randomMovement = require "game.rules.enemy.ai.random_movement"
local mockDispatch = require "mock_dispatch"
local mockDispatch = require "test_helpers.mock_dispatch"

it("dispatches a move action", function()
local characterActionTypes = require "game.rules.character.actions.types"
Expand Down
4 changes: 2 additions & 2 deletions game/rules/game_state/actions/check_game_over_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

describe("game.rules.game_state.actions", function()
local checkGameOver = require "game.rules.game_state.actions.check_game_over"
local mockDispatch = require "mock_dispatch"
local mockStore = require "mock_store"
local mockDispatch = require "test_helpers.mock_dispatch"
local mockStore = require "test_helpers.mock_store"
local app = require "game.app"

setup(function()
Expand Down
2 changes: 1 addition & 1 deletion game/rules/items/actions/use_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

describe("game.rules.items.actions.use", function()
local use = require "game.rules.items.actions.use"
local mockDispatch = require "mock_dispatch"
local mockDispatch = require "test_helpers.mock_dispatch"

before_each(function()
mockDispatch:reset()
Expand Down
2 changes: 1 addition & 1 deletion game/rules/skills/actions/opposed_check_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
-- https://opensource.org/licenses/MIT

describe("game.rules.skills.actions.opposed_check.lua", function()
local mockDispatch = require "mock_dispatch"
local mockDispatch = require "test_helpers.mock_dispatch"
local opposedCheck = require "game.rules.skills.actions.opposed_check"
local Skills = require "game.rules.skills"
Skills.describe { key = "diplomacy", attribute = "social" }
Expand Down
22 changes: 11 additions & 11 deletions game/rules/turn/actions/process_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
describe("game.rules.turn.actions.process", function()
local process = require "game.rules.turn.actions.process"
local turn_types = require "game.rules.turn.actions.types"
local mock_dispatch = require "mock_dispatch"
local mock_store = require "mock_store"
local mockDispatch = require "test_helpers.mock_dispatch"
local mockStore = require "test_helpers.mock_store"

local player = { x = 5, y = 3, isPlayerControlled = true, health = 3 }
local enemy1 = { isPlayerControlled = false, health = 2 }
Expand All @@ -17,7 +17,7 @@ describe("game.rules.turn.actions.process", function()

local store = require "moonpie.redux.store"
before_each(function()
mock_store {
mockStore {
characters = {
enemy2, player, enemy1, enemy3
},
Expand All @@ -29,26 +29,26 @@ describe("game.rules.turn.actions.process", function()
local player_action = { type = "player_action" }

local action = process(player_action)
action(mock_dispatch, store.getState)
action(mockDispatch, store.getState)

assert.is_true(mock_dispatch:received_action("player_action"))
assert.is_true(mockDispatch:received_action("player_action"))
end)

it("increments the turn when processed", function()
local player_action = {}
local action = process(player_action)

action(mock_dispatch, store.getState)
action(mockDispatch, store.getState)

assert.is_true(mock_dispatch:received_action(turn_types.increment))
assert.is_true(mockDispatch:received_action(turn_types.increment))
end)

it("triggers thinking for all non-player characters", function()
local enemy = require "game.rules.enemy"
spy.on(enemy.actions, "think")

local action = process({})
action(mock_dispatch, store.getState)
action(mockDispatch, store.getState)

assert.spy(enemy.actions.think).was.called(3)
end)
Expand All @@ -58,7 +58,7 @@ describe("game.rules.turn.actions.process", function()
spy.on(camera.actions, "centerOnPlayer")

local action = process({})
action(mock_dispatch, store.getState)
action(mockDispatch, store.getState)

assert.spy(camera.actions.centerOnPlayer).was.called_with(20, 40)
end)
Expand All @@ -68,7 +68,7 @@ describe("game.rules.turn.actions.process", function()
spy.on(character.actions, "remove")

local action = process({})
action(mock_dispatch, store.getState)
action(mockDispatch, store.getState)

assert.spy(character.actions.remove).was.called_with(enemy3)
end)
Expand All @@ -77,7 +77,7 @@ describe("game.rules.turn.actions.process", function()
local game_state = require "game.rules.game_state"
spy.on(game_state.actions, "checkGameOver")
local action = process({})
action(mock_dispatch, store.getState)
action(mockDispatch, store.getState)

assert.spy(game_state.actions.checkGameOver).was.called()

Expand Down
4 changes: 2 additions & 2 deletions game/ui/camera/actions/center_on_player_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
describe("game.ui.camera.actions.center_on_player", function()
local centerOnPlayer = require "game.ui.camera.actions.center_on_player"
local types = require "game.ui.camera.actions.types"
local mock_store = require "mock_store"
local mockStore = require "test_helpers.mock_store"

it("centers on the player location", function()
mock_store({
mockStore({
characters = {
{ isPlayerControlled = true, x = 6, y = 19 }
}
Expand Down
6 changes: 3 additions & 3 deletions game/ui/inputs/keyboard_map_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
describe("game.ui.inputs.keyboard", function()
local keyboard_map = require "game.ui.inputs.keyboard_map"
local key_simulator = require "moonpie.keyboard"
local mock_store = require "mock_store"
local mockStore = require "test_helpers.mock_store"
local character = require "game.rules.character"
local turn = require "game.rules.turn"

Expand All @@ -24,7 +24,7 @@ describe("game.ui.inputs.keyboard", function()
end)

it("can show/hide grid lines", function()
mock_store({})
mockStore({})
local Settings = require "game.settings"
spy.on(Settings.actions, "toggleOption")
key_simulator:keyPressed("shift+g")
Expand All @@ -49,7 +49,7 @@ describe("game.ui.inputs.keyboard", function()
health = 1
}

mock_store({
mockStore({
characters = {
player_character
},
Expand Down
2 changes: 1 addition & 1 deletion game/ui/screens/character_details_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

describe("game.ui.screens.character_details", function()
local CharacterDetails = require "game.ui.screens.character_details"
local mockStore = require "mock_store"
local mockStore = require "test_helpers.mock_store"

before_each(function()
mockStore {
Expand Down
4 changes: 2 additions & 2 deletions game/ui/screens/combat_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
describe("game.ui.screens.combat", function()
local combat_screen = require "game.ui.screens.combat"
local moonpie = require "moonpie"
local mock_store = require "mock_store"
mock_store({
local mockStore = require "test_helpers.mock_store"
mockStore({
characters = {},
turn = {
counter = 10
Expand Down
4 changes: 2 additions & 2 deletions game/ui/screens/create_character_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
describe("game.ui.screens.create_character", function()
local create_character = require "game.ui.screens.create_character"
local character = require "game.rules.character"
local mock_store = require "mock_store"
local mockStore = require "test_helpers.mock_store"
local player = {
name = "Papageno",
isPlayerControlled = true, x = 19, y = 28,
Expand All @@ -16,7 +16,7 @@ describe("game.ui.screens.create_character", function()
local store

before_each(function()
store = mock_store({
store = mockStore ({
characters = {
player
},
Expand Down
2 changes: 1 addition & 1 deletion game/ui/screens/game_over_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

describe("game.ui.screens.game_over", function()
local gameOver = require "game.ui.screens.game_over"
local mockStore = require "mock_store"
local mockStore = require "test_helpers.mock_store"

it("can switch back to the title screen", function()
local app = require "game.app"
Expand Down
2 changes: 1 addition & 1 deletion game/ui/widgets/character_inventory_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

describe("game.ui.widgets.character_inventory", function()
local characterInventory = require "game.ui.widgets.character_inventory"
local mockStore = require "mock_store"
local mockStore = require "test_helpers.mock_store"

setup(function()
mockStore({})
Expand Down
4 changes: 2 additions & 2 deletions game/ui/widgets/character_stats_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

describe("game.ui.widgets.character_stats", function()
local character_stats = require "game.ui.widgets.character_stats"
local mock_store = require "mock_store"
local mockStore = require "test_helpers.mock_store"

before_each(function()
local character = {
Expand All @@ -15,7 +15,7 @@ describe("game.ui.widgets.character_stats", function()
health = 15
}

mock_store {
mockStore {
characters = {
character
}
Expand Down
8 changes: 4 additions & 4 deletions game/ui/widgets/combat_map_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@

describe("game.ui.widgets.combat_map", function()
local combat_map = require "game.ui.widgets.combat_map"
local mock_store = require "mock_store"
local mockStore = require "test_helpers.mock_store"

it("renders a component", function()
assert.is_table(combat_map())
end)

it("connects to the characters state of the store", function()
local c = {}
mock_store({ characters = { c }})
mockStore({ characters = { c }})
local map = combat_map()
assert.same({ c }, map.characters)
end)

it("connects to the map state of the store", function()
local map_state = {}
mock_store({
mockStore({
character = {},
map = map_state
})
Expand All @@ -31,7 +31,7 @@ describe("game.ui.widgets.combat_map", function()

it("connects the camera state to the component", function()
local camera = {}
mock_store({
mockStore({
camera = camera
})

Expand Down
6 changes: 3 additions & 3 deletions game/ui/widgets/game_view_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

describe("game.ui.widgets.game_view", function()
local game_view = require "game.ui.widgets.game_view"
local mock_store = require "mock_store"
local mockStore = require "test_helpers.mock_store"
local mock_view = { id = "mock_view" }

before_each(function()
mock_store {
mockStore {
game_view = {
current = mock_view
}
Expand All @@ -22,7 +22,7 @@ describe("game.ui.widgets.game_view", function()
end)

it("handles when game_view is nil", function()
mock_store {}
mockStore {}
assert.has_no_errors(function()
moonpie.test_render(game_view({ id = "game_view_test" }))
end)
Expand Down
Loading

0 comments on commit 73c80e7

Please sign in to comment.