To run the spec files & assets as coffee script, I decided to go with jasmine-headless-webkit. I believe I have everything installed correctly, but perhaps something wrong in my jasmine.yml file:
src_files:
- spec/support/javascripts/jquery-1.7.2.js
- app/assets/javascripts/application.js
helpers:
- helpers/**/*
spec_files:
- "**/*_spec.*"
src_dir:
- vendor/assets/javascripts
spec_dir: spec/javascripts
When I run the command, I get three errors, all along the same lines:
Editor should have an array named tables. (/Users/aaronmcleod/Documents/awesome_model/spec/javascripts/editor_spec.js.coffee:20)
ReferenceError: Can't find variable: AwesomeModel
The AwesomeModel variable is my hash I’m using that I export to the window object. I then attach things like the Editor class to it. Any ideas as to why this isn’t defined? Here’s my spec file if it helps:
fixture_text = ->
"Company has_many:Employee\n" +
" id : int\n" +
" name : varchar\n" +
"Employee belongs_to:Company\n" +
" id : int\n" +
" name : varchar\n" +
" phone : varchar\n" +
"ComplicatedTable-Name\n" +
" id : int"
class DummyPane
constructor: ->
@viewport = {}
clean_up: ->
describe "Editor", ->
it "should have an array named tables", ->
editor = new AwesomeModel.Editor(fixture_text())
expect(editor.tables).toBeDefined()
describe "#parse_table_names", ->
text = fixture_text()
editor = new AwesomeModel.Editor(text)
it "tables should be of three length", ->
editor.parse_table_names()
expect(editor.tables.length).toEqual(3)
it "the first table name should be 'Company'", ->
editor.parse_table_names()
expect(editor.tables[0].name).toEqual("Company")
it "the third table name should be 'ComplicatedTable-Name'", ->
editor.parse_table_names()
expect(editor.tables[2].name).toEqual("ComplicatedTable-Name")
describe "#add_columns", ->
text = fixture_text()
editor = new AwesomeModel.Editor(text)
editor.parse_table_names()
describe "first table", ->
it "the first table should have two columns", ->
editor.add_columns()
table = editor.tables[0]
expect(table.columns.length).toEqual(2)
it "the first column of first table should be named 'id : int'", ->
editor.add_columns
table = editor.tables[0]
expect(table.columns[0].name).toEqual('id : int')
Found an answer by utilizing guard. No changes to the spec file, a few minor changes to the jasmine.yml file. Here’s my gemfile:
My guardfile:
Jasmine.yml
I changed the assets path to not use the local folder structure, but the asset path properly.
To run this, just run
guardin one tab, andrake jasminein another. As you save spec files, the .js version will be compiled by guard.