norman / telescope

A highly customizable test library for Lua that allows declarative tests with nested contexts.
http://norman.github.com/telescope/
160 stars 35 forks source link

bad argument #1 to 'setfenv' (number expected, got nil) on telescope.lua:289 #2

Closed kikito closed 14 years ago

kikito commented 14 years ago

Hi!

I'd like to use your library in order to make some testing on my lib, MiddleClass. Unfortunately I'm getting the error you see above.

Steps for reproducing:

Installed with luarocks:

sudo luarocks build telescope --from=http://luarocks.luaforge.net/rocks-cvs/

I then tried the following command:

tsc -f test/*.lua

The test folder only has one file, called MiddleClass_test.lua:

require '../MiddleClass.lua'

-- Test base classes (classes that depend directly from Object)
context( 'Root Classes', function()

  context( 'When created using class("name")', function()
    local MyClass = class('MyClass')

    test( 'should have their name set up', function()
      assert_equal(MyClass.name, 'MyClass')
    end)

    test( 'should have Object as their superclass' function()
      assert_equal(MyClass.superclass, Object)
    end)
  end)

end)

This is in Ubuntu 10.04.

kikito commented 14 years ago

Duh. There was a comma missing on the definition of the second test. Please disregard this issue

norman commented 14 years ago

No worries, glad you were able to get it working.

Yeah, the synax for creating tests is unfortunately a little confusing, it's one of the things I like least about telescope. I have plans to integrate Telescope and Shake to provide simpler ways to specify tests, but recently I haven't had much time to do it.

kikito commented 14 years ago

I don't mind having to write assert_true(x) instead of assert(x==true) really.

Having to write function() ... end all the time just takes some effort to get adjusted to. The other thing that took me some time was making sure that my lib was loaded before the tests were launched. A section about that on the doc would probably help others (I ended up using rake so I could get the "current directory" easily)

As far as I know, both problems aren't telescope's; they happen because of limitations in Lua - it has no procs and it doesn't recognize directories natively.

Telescope is awesome. I think it is the best one out there for Lua testing. I'm not only producing lots of tests, but having fun doing it.

Very well done, sir!

norman commented 14 years ago

Thanks for the kind words, much appreciated! I'll look into the current directory issue. IIRC it's easy to do that using lua-filesystem, but I didn't want to introduce the dependency.