-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests(openresty): Enables testing through resty
Now it is possible to run tests as if it was run from within openresty. It will also use openresty DB connectors if applicable. Usage: sailor test --resty Known problems: No way to pass flags to Busted
- Loading branch information
Showing
6 changed files
with
114 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
sailor = require "sailor" | ||
local t = require "sailor.test" | ||
local busted = require 'busted.runner' | ||
local lfs = require 'lfs' | ||
|
||
-- load fixtures | ||
|
||
t.load_fixtures('user') | ||
t.load_fixtures('category') | ||
t.load_fixtures('post') | ||
|
||
-- prepare busted | ||
busted() | ||
|
||
local busted_lib = { | ||
describe = describe, | ||
it = it, | ||
setup = setup, | ||
assert = assert, | ||
teardown = teardown, | ||
before_each = before_each, | ||
finally = finally, | ||
pending = pending, | ||
spy = spy, | ||
stub = stub, | ||
mock = mock, | ||
async = async, | ||
done = done | ||
} | ||
|
||
local test_dirs = { | ||
"tests/unit", | ||
"tests/functional", | ||
} | ||
|
||
-- Get busted vars to pass them ahead when loading each test file | ||
|
||
local env = {} | ||
for k,v in pairs(_G) do env[k] = v end | ||
for name,f in pairs(busted_lib) do | ||
env[name] = f | ||
end | ||
|
||
-- Looping through test dirs and loading them with environment with busted vars | ||
|
||
for _,dir in pairs(test_dirs) do | ||
dir = sailor.path..'/'..dir | ||
for file in lfs.dir(dir) do | ||
if file ~= '.' and file ~= '..' then | ||
local t | ||
if _VERSION == "Lua 5.1" then | ||
t = assert(loadfile(dir..'/'..file)) | ||
setfenv(t,env) | ||
else | ||
t = assert(loadfile(dir..'/'..file, env)) | ||
end | ||
t() | ||
end | ||
end | ||
end | ||
|