1
votes

I'm trying to do unit tests for my AngularJS app, but jasmine just do not see the controller, though it's registered in global namespace: ReferenceError: RequestsController is not defined. Gem is https://github.com/searls/jasmine-rails

app/assets/javascripts/requests.js.coffee:

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

spec/javascripts/support/jasmine.yml:

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

spec/javascripts/helpers/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);
1

1 Answers

0
votes

Take a look here where I describe my setup for this scenario: http://blog.zerosum.org/2014/01/17/rails-angular-jasmine.html There's a sample github project linked as well. Hope it helps.