title: Coffeescript unit test failing with Mocha, Should, Node.js
body: <p>I am trying to run a sample CoffeeScript unit test for a CoffeeScript sample class hierarchy, using Mocha. But I keep getting errors and it doesn't seem I can fix them without some help. This is my sample CoffeeScript file, in /src folder :</p>
  
  <pre><code> #Animal.coffee
    class Animal
      constructor: (@name) -&gt;
  
      move: (meters) -&gt;
        console.log @name + " moved #{meters}m."
  
    class Snake extends Animal
      move: -&gt;
        console.log "Slithering..."
        super 5
  
    class Horse extends Animal
      move: -&gt;
        console.log "Galloping..."
        super 45
  
    #module.exports = new Snake()
    module.exports.Snake = Snake
  </code></pre>
  
  <p>And this is the CoffeeScript Unit Test in /Tests folder :</p>
  
  <pre><code>  #AnimalTest.coffee
    should  = require 'should'
    { Snake } = require "../src/Animal"
  
    describe 'sample', -&gt;
       it 'should pass', -&gt;
           snake = new Snake "Venomous python"
           snake.should.be.an.instanceOf(Snake)
  </code></pre>
  
  <p>I have installed all these libraries globally. So when I execute this command through command line (Windows 7) :</p>
  
  <pre><code>   Desktop&gt;mocha --compilerscoffee:coffee-script/register Tests
  </code></pre>
  
  <p>It throws me this error: </p>
  
  <pre><code>    desktop\Tests\sampleTest.coffee:15
      snake.should.be.an.instanceOf(Snake);
      ^
      ReferenceError: snake is not defined
      at Object.&lt;anonymous&gt; (c:\users\ap\desktop\Tests\AnimalTest.coffee:8:3)
      at Object.&lt;anonymous&gt; (c:\users\ap\desktop\Tests\AnimalTest.coffee:2:1)
      at Module._compile (module.js:456:26)
      at Object.loadFile (C:\Users\ap\AppData\Roaming\npm\node_modules\coffee-sc
      ript\lib\coffee-script\register.js:16:19)
      at Module.load (C:\Users\ap\AppData\Roaming\npm\node_modules\coffee-script
      \lib\coffee-script\register.js:45:36)
      at Function.Module._load (module.js:312:12)
      at Module.require (module.js:364:17)
      at require (module.js:380:17)
      at C:\Users\ap\AppData\Roaming\npm\node_modules\mocha\lib\mocha.js:172:27
      at Array.forEach (native)
      at Mocha.loadFiles (C:\Users\ap\AppData\Roaming\npm\node_modules\mocha\lib
      \mocha.js:169:14)
      at Mocha.run (C:\Users\ap\AppData\Roaming\npm\node_modules\mocha\lib\mocha
      .js:356:31)
      at Object.&lt;anonymous&gt; (C:\Users\ap\AppData\Roaming\npm\node_modules\mocha\
      bin\_mocha:359:16)
      at Module._compile (module.js:456:26)
      at Object.Module._extensions..js (module.js:474:10)
      at Module.load (module.js:356:32)
      at Function.Module._load (module.js:312:12)
      at Function.Module.runMain (module.js:497:10)
      at startup (node.js:119:16)
      at node.js:902:3
  </code></pre>
  
  <p>I am using CoffeeScript version 1.7.1, Mocha version 1.18.2 and Node version 0.10.26. I have tried looking everywhere and tried all combinations between the tests, but I cannot figure out for my life how to make it create the objects successfully and run the test.</p>
  
  <p>For reference, I tried these, of all other combinations : 
  <a href="https://stackoverflow.com/questions/9939672/requiring-coffeescript-file-from-within-another-coffeescript-file-with-nodejs">Requiring CoffeeScript file from within another CoffeeScript file with nodejs</a></p>
  
  <p><a href="https://stackoverflow.com/questions/20335719/how-to-check-for-class-inheritance-in-coffeescript-mocha-test">How to check for class inheritance in Coffeescript Mocha Test?</a></p>
  
  <p>Can someone point out what could possibly be wrong?</p>
  
  <p><strong>Update 1:</strong> Modified everything as pointed by dule, but now I get this error:</p>
  
  <pre><code>module.js:340
      throw err;
        ^
      Error: Cannot find module 'should'
       at Function.Module._resolveFilename (module.js:338:15)
       at Function.Module._load (module.js:280:25)
       at Module.require (module.js:364:17)
       at require (module.js:380:17)
       at Object.&lt;anonymous&gt; (C:\Users\ap\Desktop\Tests\AnimalTest.coffee:2:11)
       at Object.&lt;anonymous&gt; (C:\Users\ap\Desktop\Tests\AnimalTest.coffee:2:1)
       at Module._compile (module.js:456:26)
       at Object.loadFile (C:\Users\ap\AppData\Roaming\npm\node_modules\coffee-sc
       ript\lib\coffee-script\register.js:16:19)
       at Module.load (C:\Users\ap\AppData\Roaming\npm\node_modules\coffee-script
       \lib\coffee-script\register.js:45:36)
       at Function.Module._load (module.js:312:12)
       at Module.require (module.js:364:17)
       at require (module.js:380:17)
       at C:\Users\ap\AppData\Roaming\npm\node_modules\mocha\lib\mocha.js:172:27
       at Array.forEach (native)
       at Mocha.loadFiles (C:\Users\ap\AppData\Roaming\npm\node_modules\mocha\lib
       \mocha.js:169:14)
       at Mocha.run (C:\Users\ap\AppData\Roaming\npm\node_modules\mocha\lib\mocha
       .js:356:31)
       at Object.&lt;anonymous&gt; (C:\Users\ap\AppData\Roaming\npm\node_modules\mocha\
       bin\_mocha:359:16)
       at Module._compile (module.js:456:26)
       at Object.Module._extensions..js (module.js:474:10)
       at Module.load (module.js:356:32)
       at Function.Module._load (module.js:312:12)
       at Function.Module.runMain (module.js:497:10)
       at startup (node.js:119:16)
       at node.js:902:3
  </code></pre>
  
  <p><strong>Update 2:</strong> I made the following changes to the AnimalTest script and the test passed.</p>
  
  <pre><code>  should  = require ("../npm/node_modules/should/should")
    { Snake } = require ("../src/Animal.coffee")
  
    describe 'sample', -&gt;
       it 'should pass', -&gt;
      console.log(new Snake "Venomous python")
  </code></pre>
  
  <p>However, for some reason, creating an object and saving it for use, still fails. And I get the same <code>snake not defined</code> error.</p>