Browse Source

Rename lust.test to lust.it; Remove exclamation points from errors;

bjorn 10 years ago
parent
commit
a8def207cb
2 changed files with 15 additions and 12 deletions
  1. 4 4
      README.md
  2. 11 8
      lust.lua

+ 4 - 4
README.md

@@ -13,12 +13,12 @@ local lust = require 'lust'
 
 lust.describe('my project', function()
   lust.describe('module1', function() -- Can be nested
-    lust.test('feature1', function()
+    lust.it('feature1', function()
       lust.expect(1).to.be.a('number') -- Pass
       lust.expect('astring').to.equal('astring') -- Pass
     end)
 
-    lust.test('feature2', function()
+    lust.it('feature2', function()
       lust.expect(nil).to.exist() -- Fail
     end)
   end)
@@ -32,7 +32,7 @@ Documentation
 
 Used to declare a group of tests.  `name` is a string used to describe the group, and `func` is a function containing all tests and `describe` blocks in the group.  Groups created using `describe` can be nested.
 
-`lust.test(name, func)`
+`lust.it(name, func)`
 
 Used to declare a test, which consists of a set of assertions.  `name` is a string used to describe the test, and `func` is a function containing the assertions.
 
@@ -66,7 +66,7 @@ Fails if `type(x)` is not equal to `type(y)`.
 
 ### Befores and Afters
 
-You can define functions that are called before and after every call to `lust.test`:
+You can define functions that are called before and after every call to `lust.it`:
 
 `lust.before(fn)`
 

+ 11 - 8
lust.lua

@@ -12,7 +12,7 @@ function lust.describe(name, fn)
   lust.level = lust.level - 1
 end
 
-function lust.test(name, fn)
+function lust.it(name, fn)
   print(string.rep('\t', lust.level) .. name)
   lust.level = lust.level + 1
   if type(lust.onbefore) == 'function' then lust.onbefore(name) end
@@ -66,17 +66,17 @@ local paths = {
   [''] = {'to'},
   to = {'have', 'equal', 'be', 'exist'},
   be = {'a', 'an', 'truthy', 'falsy', f = function(v, x)
-    return v == x, tostring(v) .. ' and ' .. tostring(x) .. ' are not equal!'
+    return v == x, tostring(v) .. ' and ' .. tostring(x) .. ' are not equal'
   end},
   a = {f = isa},
   an = {f = isa},
-  exist = {f = function(v) return v == nil, tostring(v) .. ' is nil!' end},
-  truthy = {f = function(v) return v, tostring(v) .. ' is not truthy!' end},
-  falsy = {f = function(v) return not v, tostring(v) .. ' is not falsy!' end},
-  equal = {f = function(v, x) return strict_eq(v, x), tostring(v) .. ' and ' .. tostring(x) .. ' are not strictly equal!' end},
+  exist = {f = function(v) return v == nil, tostring(v) .. ' is nil' end},
+  truthy = {f = function(v) return v, tostring(v) .. ' is not truthy' end},
+  falsy = {f = function(v) return not v, tostring(v) .. ' is not falsy' end},
+  equal = {f = function(v, x) return strict_eq(v, x), tostring(v) .. ' and ' .. tostring(x) .. ' are not strictly equal' end},
   have = {
     f = function(v, x)
-      if type(v) ~= 'table' then return false, 'table "' .. tostring(v) .. '" is not a table!' end
+      if type(v) ~= 'table' then return false, 'table "' .. tostring(v) .. '" is not a table' end
       return has(v, x), 'table "' .. tostring(v) .. '" does not have ' .. tostring(x)
     end
   }
@@ -99,7 +99,7 @@ function lust.expect(v)
       if paths[t.action].f then
         local res, err = paths[t.action].f(t.val, ...)
         if not res then
-          error(err or 'unknown failure!', 2)
+          error(err or 'unknown failure', 2)
         end
       end
     end
@@ -108,4 +108,7 @@ function lust.expect(v)
   return assertion
 end
 
+lust.test = lust.it
+lust.paths = paths
+
 return lust