title: Testing Coffeescript with Jasmine and Rails 3.1
body: <p>Say I have a class in Coffeescript:</p>
  
  <pre><code>class MyGame
     constructor: () -&gt;
        @me = new Player
        @opponents = [new Player, new Player]
  </code></pre>
  
  <p>which would like to test in Jasmine:</p>
  
  <pre><code>describe "MyGame", -&gt;
     beforeEach -&gt;
       window.game = new MyGame
  
     it "should have two players", -&gt;
        expect(window.game.opponents.length).toEqual 2
  </code></pre>
  
  <p>But I get the error <code>TypeError: Result of expression 'window.game.opponents' [undefined] is not an object.</code>?</p>
  
  <p>The <code>window.game</code> approach also seem awkward to me. If I try to define it as <code>@game = new MyGame</code> I get the error <code>ReferenceError: Can't find variable: MyGame</code> but I guess that has something to do with the way Coffeescript is wrapping things up?</p>
  
  <p><strong>UPDATE:</strong> The problem seems more like a reference problem as described above. I'm running with <code>guard-jasmine</code> which looks like</p>
  
  <pre><code>guard 'jasmine', :all_on_start =&gt; false, :all_after_pass =&gt; false do
    watch(%r{app/assets/javascripts/(.+)\.(js\.coffee|js)}) { |m| "spec/javascripts/#{m[1]}_spec.#{m[2]}" }
    watch(%r{spec/javascripts/(.+)_spec\.(js\.coffee|js)})  { |m| "spec/javascripts/#{m[1]}_spec.#{m[2]}" }
    watch(%r{spec/javascripts/spec\.(js\.coffee|js)})       { "spec/javascripts" }
  end
  </code></pre>
  
  <p>and my <code>jasmine.yml</code> file has:</p>
  
  <pre><code>src_files:
      - "app/assets/**/*.js"
      - "app/assets/**/*.coffee"
  spec_files: 
      - '**/*[sS]pec.js.coffee' 
  asset_pipeline_paths: 
      - app/assets 
      - spec/javascripts
  </code></pre>
  
  <p>I get the an <code>ReferenceError: Can't find variable: MyGame</code> so I figure it's either something with the Rails 3.1 asset pipeline or the way Coffeescript wraps objects.</p>