-
-
Save linojon/4635728 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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