Skip to content

Instantly share code, notes, and snippets.

@linojon
Forked from anonymous/controllers.js
Last active December 11, 2015 17:38
Show Gist options
  • Save linojon/4635728 to your computer and use it in GitHub Desktop.
Save linojon/4635728 to your computer and use it in GitHub Desktop.
// app/assets/javascripts/myapp/controllers.js
function PostListCtrl($scope) {
$scope.posts = [
{ "title": "My First Post", "intro": "Subtitle of my post" },
{ "title": "Another Post", "intro": "Something interesting about this post" },
{ "title": "One More Thng", "intro": "There's always something more" }
]
}
// html contains <div ng-app="myapp">
// this runs correctly in the browser
# spec/javascripts/controllers_spec.coffee
describe 'myapp controllers', ->
describe 'PostListCtrl', ->
it 'creates "posts" model with 3 posts', ->
scope = {}
ctrl = new PostListCtrl(scope)
expect(scope.posts.length).toBe(3)
# this passes
# app/assets/javascripts/myapp/controllers.js.coffee (replaces the js version)
app = angular.module 'myapp', []
app.controller "PostListCtrl", ($scope) ->
$scope.posts = [
{ "title": "My First Post", "intro": "Subtitle of my post" },
{ "title": "Another Post", "intro": "Something interesting about this post" },
{ "title": "One More Thng", "intro": "There's always something more" }
]
# note how i defined the controller function to get it to work. It runs in the browser.
# but the test reports
# ReferenceError: PostListCtrl is not defined in http://localhost:3000/assets/controllers_spec.js?body=1 (line 8)
# how do i get the tests to find it?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment