2013-05-12 182 views
1

我想爲我的AngularJS應用程序做單元測試,但茉莉花只是看不到控制器,儘管它在全局名稱空間中註冊:ReferenceError:RequestsController未定義。 寶石是https://github.com/searls/jasmine-rails在rails中測試angularjs與茉莉花

應用程序/資產/ Java腳本/ requests.js.coffee:

@RequestsController = ($scope) -> 
    $scope.entries = [ 
    {type: "first"}, 
    {type: "second"} 
    ] 

規格/ Java腳本/支持/ jasmine.yml:

src_dir: "app/assets/javascripts" 
src_files: 
    - "app/assets/javascripts/requests.js.coffee" 
spec_files: 
    - "**/*[Ss]pec.{js,coffee}" 

規格/ Java腳本/助理/ spec_helper.coffee:

#= require angular 
#= require angular-mocks 

spec/javascripts/requests_spec.coffee :

#= require helpers/spec_helper 
describe 'RequestsCtrl', -> 
    it 'have entries of request types', -> 
    scope = {} 
    ctrl = new RequestsController(scope) 
    expect(scope.entries.length).toBe(2); 

回答