Created
July 14, 2012 19:31
-
-
Save fish2000/3112936 to your computer and use it in GitHub Desktop.
Mixing Require.js, Jasmine, Sinon.js and Backbone.
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
## ItemView.coffee in the specs/coffee folder ## | |
define ["ItemView"], (ItemView) -> | |
### | |
Specs for ItemView | |
### | |
describe "Item View", -> | |
### | |
Common setup and teardown | |
### | |
beforeEach -> | |
# Make a new arbitraty Backbone.Model | |
@model = new Backbone.Model | |
id: 1 | |
title: "Sample Todo" | |
priority: 2 | |
done: false | |
# And make a view for it. | |
@view = new ItemView model: @model | |
### | |
Rendering tests | |
### | |
describe "Rendering", -> | |
### | |
Common setup and teardown | |
### | |
beforeEach -> | |
@view.render() | |
@el = $ @view.el | |
it "returns the view object", -> | |
# Check that the render method returns the view | |
expect( @view.render() ).toEqual @view |
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
require ["model","collection","view","router","etc"], (main,collection,view,router,etc) -> | |
# Globalize the classes | |
window.main = main | |
window.collection = collection | |
window.view = view | |
window.router = router | |
window.etc = etc | |
# And then run the specs | |
# ... | |
jasmineEnv.execute() | |
# ... |
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
## SpecRunner.js in the specs/js folder ## | |
define( [ | |
"specs/Item", | |
"specs/List", | |
"specs/ItemView", | |
"specs/ListView", | |
"specs/Routes", | |
"specs/MainRouter", | |
], function(){ | |
return SpecRunner = function() { | |
var jasmineEnv = jasmine.getEnv(); | |
jasmineEnv.updateInterval = 1000; | |
var trivialReporter = new jasmine.TrivialReporter(); | |
jasmineEnv.addReporter(trivialReporter); | |
jasmineEnv.specFilter = function(spec) { | |
return trivialReporter.specFilter(spec); | |
}; | |
return jasmineEnv.execute(); | |
} | |
} | |
); |
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
// SpecRunner.html // | |
// ... | |
$(document).ready( function() { | |
window.App = {} | |
// Regular Require.js configuration here. | |
require.config({ | |
baseUrl: '../build/js', // Leave the baseUrl as in your release build | |
paths: { | |
text: 'libs/require/text', | |
specs: '../../specs/js' // Adding this helps a lot... | |
} | |
}); | |
require([ | |
'specs/SpecRunner', // ...as shown here. | |
], | |
function(SpecRunner) { | |
SpecRunner(); | |
} | |
); | |
}); | |
// ... |
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
describe "something", -> | |
it "something else", -> | |
require ["dep1","dep2","..."], (dep1,dep2,...)-> | |
#expectation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment