bootstrap_resty.lua 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. sailor = require "sailor"
  2. local t = require "sailor.test"
  3. local busted = require 'busted.runner'
  4. local lfs = require 'lfs'
  5. -- load fixtures
  6. -- t.load_fixtures()
  7. -- prepare busted
  8. busted()
  9. local busted_lib = {
  10. describe = describe,
  11. it = it,
  12. setup = setup,
  13. assert = assert,
  14. teardown = teardown,
  15. before_each = before_each,
  16. finally = finally,
  17. pending = pending,
  18. spy = spy,
  19. stub = stub,
  20. mock = mock,
  21. async = async,
  22. done = done
  23. }
  24. local test_dirs = {
  25. "tests/unit",
  26. "tests/functional",
  27. }
  28. -- Get busted vars to pass them ahead when loading each test file
  29. local env = {}
  30. for k,v in pairs(_G) do env[k] = v end
  31. for name,f in pairs(busted_lib) do
  32. env[name] = f
  33. end
  34. -- Looping through test dirs and loading them with environment with busted vars
  35. for _,dir in pairs(test_dirs) do
  36. dir = sailor.path..'/'..dir
  37. for file in lfs.dir(dir) do
  38. if file ~= '.' and file ~= '..' then
  39. local t
  40. if _VERSION == "Lua 5.1" then
  41. t = assert(loadfile(dir..'/'..file))
  42. setfenv(t,env)
  43. else
  44. t = assert(loadfile(dir..'/'..file, env))
  45. end
  46. t()
  47. end
  48. end
  49. end