Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improve path code and global visibility

  • Loading branch information...
commit 6866f3f9f09490786c4e1e1cf95e078d8b3392cd 1 parent edf60c2
@norman norman authored
Showing with 26 additions and 19 deletions.
  1. +5 −5 README.md
  2. +21 −14 lua_haml_spec.lua
View
10 README.md
@@ -46,12 +46,12 @@ Then, running the Ruby test suite is easy:
### Lua ###
-The Lua test depends on [Telescope](http://telescope.luaforge.net/),
+The Lua test depends on
+[Penlight](http://stevedonovan.github.com/Penlight/),
+[Telescope](http://telescope.luaforge.net/),
[jason4lua](http://json.luaforge.net/), and
-[Lua Haml](http://github.com/norman/lua-haml). Install and
-run `tsc lua_haml_spec.lua`.
-
-## Contributing ##
+[Lua Haml](http://github.com/norman/lua-haml). Install and run `tsc
+lua_haml_spec.lua`.
### Getting it ###
View
35 lua_haml_spec.lua
@@ -1,19 +1,26 @@
-require 'luarocks.require'
-require 'json'
-require 'telescope'
-require 'haml'
+local dir = require 'pl.dir'
+local haml = require 'haml'
+local json = require 'json'
+local path = require 'pl.path'
+local telescope = require 'telescope'
+local assert = assert
+local describe = telescope.describe
+local getinfo = debug.getinfo
+local it = telescope.it
+local open = io.open
+local pairs = pairs
+
+module('hamlspec')
local function get_tests(filename)
- local self = debug.getinfo(1).short_src
- if self:match("/") then return "./" .. self:gsub("[^/]*%.lua$", "/" .. filename)
- elseif self:match("\\") then return self:gsub("[^\\]*%.lua$", "\\" .. filename)
- else return filename
- end
+ local me = path.abspath(getinfo(1).source:match("@(.*)$"))
+ return path.join(path.dirname(me), filename)
end
-local fh = assert(io.open(get_tests("tests.json")))
-local input = fh:read '*a'
-fh:close()
+local json_file = get_tests("tests.json")
+local file = assert(open(json_file))
+local input = file:read '*a'
+file:close()
local contexts = json.decode(input)
@@ -21,10 +28,10 @@ describe("LuaHaml", function()
for context, expectations in pairs(contexts) do
describe("When handling " .. context, function()
for name, exp in pairs(expectations) do
- it(string.format("should correctly render %s", name), function()
+ it(("should correctly render %s"):format(name), function()
assert_equal(haml.render(exp.haml, exp.config or {}, exp.locals or {}), exp.html)
end)
end
end)
end
-end)
+end)
Please sign in to comment.
Something went wrong with that request. Please try again.