Skip to content

Commit

Permalink
Added file assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
tredfern committed Mar 1, 2020
1 parent 3f3c227 commit 438ec58
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion moonpie/test_helpers/busted_extensions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ require "moonpie.test_helpers.string_assertions"
require "moonpie.test_helpers.number_assertions"
require "moonpie.test_helpers.array_assertions"
require "moonpie.test_helpers.mock_love"
require "moonpie.test_helpers.spy_helpers"
require "moonpie.test_helpers.spy_helpers"
require "moonpie.test_helpers.file_assertions"
12 changes: 12 additions & 0 deletions moonpie/test_helpers/file_assertations_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- Copyright (c) 2020 Trevor Redfern
--
-- This software is released under the MIT License.
-- https://opensource.org/licenses/MIT

describe("moonpie.test_helpers.file_assertions", function()
it("can assert that a file exists", function()
assert.file_exists("moonpie/test_helpers/file_assertions.lua")
assert.not_file_exists("some/totally_random/file/name.foo")
end)

end)
21 changes: 21 additions & 0 deletions moonpie/test_helpers/file_assertions.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- Copyright (c) 2020 Trevor Redfern
--
-- This software is released under the MIT License.
-- https://opensource.org/licenses/MIT


local assert = require("luassert")
local say = require("say")

local function file_exists(state, arguments)
local path = arguments[1]
local f = io.open(path, "r")
local result = f ~= nil
if f then f:close() end
return result
end


say:set("assertion.file_exists.positive", "File %s does not exist.")
say:set("assertion.file_exists.negative", "File %s exists and should not.")
assert:register("assertion", "file_exists", file_exists, "assertion.file_exists.positive", "assertion.file_exists.negative")

0 comments on commit 438ec58

Please sign in to comment.