2012-06-14 54 views
0

爲了將規格文件&作爲咖啡腳本運行,我決定使用jasmine-headless-webkit。我相信我有正確安裝一切,但也許有些不對勁,我jasmine.yml文件:Jasmine Headless Webkit spec文件在資產之前運行?

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 

當我運行的命令,我得到三個錯誤,都沿着相同的路線:

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 

AwesomeModel變量是我使用的哈希,我導出到窗口對象。然後,我將諸如Editor類的東西附加到它上面。任何想法爲什麼沒有定義?這是我的規格文件,如果有幫助:

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') 

回答

0

通過利用警衛找到了答案。沒有更改spec文件,對jasmine.yml文件進行了一些小的修改。這裏是我的Gemfile:

source 'https://rubygems.org' 

gem 'rails', '3.2.0' 

# Bundle edge Rails instead: 
# gem 'rails', :git => 'git://github.com/rails/rails.git' 

# Gems used only for assets and not required 
# in production environments by default. 
group :assets do 
    gem 'sass-rails', '~> 3.2.3' 
    gem 'coffee-rails', '~> 3.2.1' 

    # See https://github.com/sstephenson/execjs#readme for more supported runtimes 
    # gem 'therubyracer' 

    gem 'uglifier', '>= 1.0.3' 
end 

gem 'haml-rails' 

gem 'jquery-rails' 

platforms :ruby do 
    gem 'pg' 
end 

platforms :jruby do 
    gem 'jruby-openssl' 
    gem 'activerecord-jdbcpostgresql-adapter' 
end 

group :test, :development do 
    gem 'rspec-rails' 
    gem 'capybara' 
    gem 'jasmine' 
    gem 'guard' 
    gem 'guard-coffeescript' 
end 

我guardfile:

# A sample Guardfile 
# More info at https://github.com/guard/guard#readme 

guard 'coffeescript', input: 'spec/javascripts', output: 'spec/javascripts' 

Jasmine.yml

src_dir: 
    - assets/javascripts 
src_files: 
    - assets/application.js 
helpers: 
    - helpers/**/* 
spec_files: 
    - "**/*_spec.js" 

spec_dir: spec/javascripts 

我改變了資產的路徑不使用本地文件夾結構,但正確的資源路徑。

要運行此操作,只需在一個選項卡中運行guard,在另一個選項卡中運行rake jasmine。在保存spec文件時,.js版本將由guard編譯。

相關問題