Say I have a class in Coffeescript:
class MyGame
constructor: () ->
@me = new Player
@opponents = [new Player, new Player]
who would like to experience in Jasmine:
describe "MyGame", ->
beforeEach ->
window.game = new MyGame
it "should have two players", ->
expect(window.game.opponents.length).toEqual 2
But am I getting an error TypeError: Result of expression 'window.game.opponents' [undefined] is not an object.?
The approach window.gamealso seems uncomfortable to me. If I try to define it as @game = new MyGame, I get an error ReferenceError: Can't find variable: MyGame, but I think this is due to how Coffeescript wraps things up?
UPDATE: The problem is more like the reference problem described above. I'm running with guard-jasminethat looks like
guard 'jasmine', :all_on_start => false, :all_after_pass => 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
and my jasmine.ymlfile has:
src_files:
- "app/assets/**/*.js"
- "app/assets/**/*.coffee"
spec_files:
- '**/*[sS]pec.js.coffee'
asset_pipeline_paths:
- app/assets
- spec/javascripts
I get a ReferenceError: Can't find variable: MyGame, so I consider this either something with a Rails 3.1 resource pipeline or the way Coffeescript wraps objects.