Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- significant updates to run.js

- use MIT license
- update dependencies
- update README
- add Cakefile
- add contrib scripts
- add simple.html
  • Loading branch information...
commit e25d9100d70e4fccf817a8f54d1d8e1e8739e9dd 1 parent ac2bd19
@brianmhunt authored
View
1  .coverignore
@@ -1 +0,0 @@
-test/
View
2  .travis.yml
@@ -1,5 +1,3 @@
language: node_js
node_js:
- - 0.4
- - 0.6
- 0.8
View
90 Cakefile
@@ -0,0 +1,90 @@
+#
+# Cakefile
+# --------
+#
+# Targets:
+#
+# test:
+# print some pretty colors on the console
+#
+# toast:
+# create the javascript files in the build/ directory
+#
+#
+# Based on sample cakefile at
+# https://github.com/kompiro/Cakefile-Sample/
+
+{spawn} = require 'child_process'
+{log} = require 'util'
+fs = require 'fs'
+glob = require 'glob'
+_ = require 'lodash'
+coffee = require 'coffee-script'
+
+SRC_DIR = 'lib'
+COFFEE_SRC = ['casper-chai.coffee']
+DEST = 'build/casper-chai'
+UGLIFY_CMD = './node_modules/uglify-js2/bin/uglifyjs2'
+
+task 'test', 'Print some pretty colors to the console', (options) ->
+ cmd = 'casperjs'
+ args = ["test/run.js"]
+ log "Cake is running: #{cmd} #{args.join(" ")}"
+ spawn cmd, args, customFds: [0, 1, 2]
+
+task 'deploy', 'Publish a patch release on npm (increments patch number)', ->
+ semver = require('semver')
+
+ # read package.json
+ pkg = JSON.parse(fs.readFileSync('package.json', "utf8"))
+
+ # get and increment version
+ version = pkg.version
+ pkg.version = semver.inc(version, 'patch')
+
+ # notify of version change and write new package.json
+ console.log "version incrementing from #{version} => #{pkg.version}"
+ fs.writeFileSync("package.json", JSON.stringify(pkg, null, 2), "utf8")
+
+ # build latest version
+ invoke 'toast'
+
+ # publish
+ args = ['publish']
+ spawn "npm", args, customFds: [0,1,2]
+
+
+
+task 'toast', "Build the project into the build/ dir", (options) ->
+ source_dir = require('path').join(__dirname, SRC_DIR)
+ version = JSON.parse(fs.readFileSync("package.json")).version
+ console.log "Compiling version #{version}"
+ sources = []
+
+ # Get all source files. Preserve the order in COFFEE_SRC
+ _.each(COFFEE_SRC, (src) ->
+ _.each(glob.sync(src, cwd: source_dir), (filename) ->
+ if filename not in sources
+ sources.push(filename)
+ )
+ )
+
+ # get the source as a string
+ source = _.map(sources, (src_file) ->
+ src_file = require('path').join(SRC_DIR, src_file)
+ console.log "Compiling #{src_file}."
+ js = coffee.compile fs.readFileSync(src_file, 'utf8')
+ return "\n// -- from: #{src_file} -- \\\\\n" + js
+ ).join("\n")
+
+ contents = source
+
+ console.log "Writing #{DEST}.js"
+ fs.writeFileSync("#{DEST}.js", contents, 'utf8')
+
+ # minify the content
+ console.log "Creating minified #{DEST}.min.js"
+ args = ["#{DEST}.js", '-o', "#{DEST}.min.js", '-m', '--lint']
+ spawn UGLIFY_CMD, args, customFds: [0, 1, 2]
+
+
View
27 LICENSE.txt
@@ -1,14 +1,19 @@
- DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
- Version 2, December 2004
+Copyright (C) 2012 Brian M Hunt
- Copyright (C) 2012 Domenic Denicola <domenic@domenicdenicola.com>
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
- Everyone is permitted to copy and distribute verbatim or modified
- copies of this license document, and changing it is allowed as long
- as the name is changed.
-
- DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. You just DO WHAT THE FUCK YOU WANT TO.
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
View
165 README.md
@@ -1,169 +1,24 @@
-# Sinon.JS Assertions for Chai
+# Casper.JS Assertions for Chai
-**Sinon–Chai** provides a set of custom assertions for using the [Sinon.JS][] spy, stub, and mocking framework with the
-[Chai][] assertion library. You get all the benefits of Chai with all the powerful tools of Sinon.JS.
+**Casper–Chai** provides a set of custom assertions for use with [CasperJS][].
+You get all the benefits of [Chai][] to test using CasperJS.
-Instead of using Sinon.JS's assertions:
-
-```javascript
-sinon.assertCalledWith(mySpy, "foo");
-```
-
-or awkwardly trying to use Chai's `should` or `expect` interfaces on spy properties:
-
-```javascript
-mySpy.calledWith("foo").should.be.ok;
-expect(mySpy.calledWith("foo")).to.be.ok;
-```
+Instead of using Casper's Tester:
you can say
```javascript
-mySpy.should.have.been.calledWith("foo");
-```
-
-
-## Assertions
-
-All of your favorite Sinon.JS assertions made their way into Sinon–Chai. We show the `should` syntax here; the `expect`
-equivalent is also available.
-
-<table>
- <tr>
- <th>Sinon.JS property/method</th>
- <th>Sinon–Chai assertion</th>
- </tr>
- <tr>
- <td>called</td>
- <td>spy.should.have.been.called</td>
- </tr>
- <tr>
- <td>calledOnce</td>
- <td>spy.should.have.been.calledOnce</td>
- </tr>
- <tr>
- <td>calledTwice</td>
- <td>spy.should.have.been.calledTwice</td>
- </tr>
- <tr>
- <td>calledThrice</td>
- <td>spy.should.have.been.calledThrice</td>
- </tr>
- <tr>
- <td>calledBefore</td>
- <td>spy1.should.have.been.calledBefore(spy2)</td>
- </tr>
- <tr>
- <td>calledAfter</td>
- <td>spy1.should.have.been.calledAfter(spy2)</td>
- </tr>
- <tr>
- <td>calledWithNew</td>
- <td>spy.should.have.been.calledWithNew</td>
- </tr>
- <tr>
- <td>alwaysCalledWithNew</td>
- <td>spy.should.always.have.been.calledWithNew</td>
- </tr>
- <tr>
- <td>calledOn</td>
- <td>spy.should.have.been.calledOn(context)</td>
- </tr>
- <tr>
- <td>alwaysCalledOn</td>
- <td>spy.should.always.have.been.calledOn(context)</td>
- </tr>
- <tr>
- <td>calledWith</td>
- <td>spy.should.have.been.calledWith(...args)</td>
- </tr>
- <tr>
- <td>alwaysCalledWith</td>
- <td>spy.should.always.have.been.calledWith(...args)</td>
- </tr>
- <tr>
- <td>calledWithExactly</td>
- <td>spy.should.always.have.been.calledWithExactly(...args)</td>
- </tr>
- <tr>
- <td>alwaysCalledWithExactly</td>
- <td>spy.should.always.have.been.calledWithExactly(...args)</td>
- </tr>
- <tr>
- <td>returned</td>
- <td>spy.should.have.returned(returnVal)</td>
- </tr>
- <tr>
- <td>alwaysReturned</td>
- <td>spy.should.have.always.returned(returnVal)</td>
- </tr>
- <tr>
- <td>threw</td>
- <td>spy.should.have.thrown(errorObjOrErrorTypeStringOrNothing)</td>
- </tr>
- <tr>
- <td>alwaysThrew</td>
- <td>spy.should.have.always.thrown(errorObjOrErrorTypeStringOrNothing)</td>
- </tr>
-</table>
-
-For more information on the behavior of each assertion, see
-[the documentation for the corresponding spy methods][spymethods]. These of course work on not only spies, but
-individual spy calls, stubs, and mocks as well.
-
-
-## Installation and Usage
-
-### Node
-
-Do an `npm install sinon-chai` to get up and running. Then:
-
-```javascript
-var chai = require("chai");
-var sinonChai = require("sinon-chai");
-
-chai.use(sinonChai);
+***
```
-You can of course put this code in a common test fixture file; for an example using [Mocha][], see
-[the Sinon–Chai tests themselves][fixturedemo].
-
### AMD
-Sinon–Chai supports being used as an [AMD][] module, registering itself anonymously (just like Chai). So, assuming you
-have configured your loader to map the Chai and Sinon–Chai files to the respective module IDs `"chai"` and
-`"sinon-chai"`, you can use them as follows:
-
-```javascript
-define(function (require, exports, module) {
- var chai = require("chai");
- var sinonChai = require("sinon-chai");
-
- chai.use(sinonChai);
-});
-```
-
-### `<script>` tag
-
-If you include Sinon–Chai directly with a `<script>` tag, after the one for Chai itself, then it will automatically plug
-in to Chai and be ready for use. Note that you'll want to get the latest browser build of Sinon.JS as well:
-
-```html
-<script src="chai.js"></script>
-<script src="sinon-chai.js"></script>
-<script src="sinon.js"></script>
-```
-
-### Ruby on Rails
-
-Thanks to [Cymen Vig][], there's now [a Ruby gem][] of Sinon–Chai that integrates it with the Rails asset pipeline!
-
+Casper–Chai supports being used as an [AMD][] module, registering itself
+anonymously (just like Chai). So, assuming you have configured your loader to
+map the Chai and Casper–Chai files to the respective module IDs `"chai"` and
+`"casper-chai"`, you can use them as follows:
-[Sinon.JS]: http://sinonjs.org/
+[CasperJS]: http://casperjs.org/
[Chai]: http://chaijs.com/
-[spymethods]: http://sinonjs.org/docs/#spies-api
[Mocha]: http://visionmedia.github.com/mocha/
-[fixturedemo]: https://github.com/domenic/sinon-chai/tree/master/test/
[AMD]: https://github.com/amdjs/amdjs-api/wiki/AMD
-[Cymen Vig]: https://github.com/cymen
-[a Ruby gem]: https://github.com/cymen/sinon-chai-rails
View
35 build/casper-chai.js
@@ -0,0 +1,35 @@
+
+// -- from: lib/casper-chai.coffee -- \\
+
+/*
+Chai assertions for CasperJS
+
+Copyright (C) 2012 Brian M Hunt
+
+ Repository: http://github.com/brianmhunt/casper-chai.git
+ License: MIT (see LICENSE.txt)
+*/
+
+
+(function() {
+ var casperChai;
+
+ casperChai = function(_chai, utils) {
+ return _chai.Assertion.addProperty('inDOM', function() {
+ var selector;
+ selector = this._obj;
+ return this.assert(casper.exists(selector), 'expected selector #{this} to be in the DOM', 'expected selector #{this} to not be in the DOM');
+ });
+ };
+
+ if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
+ module.exports = casperChai;
+ } else if (typeof define === "function" && define.amd) {
+ define(function() {
+ return casperChai;
+ });
+ } else {
+ chai.use(casperChai);
+ }
+
+}).call(this);
View
1  build/casper-chai.min.js
@@ -0,0 +1 @@
+(function(){var e;e=function(e,t){return e.Assertion.addProperty("inDOM",function(){var e;e=this._obj;return this.assert(casper.exists(e),"expected selector #{this} to be in the DOM","expected selector #{this} to not be in the DOM")})};if(typeof require==="function"&&typeof exports==="object"&&typeof module==="object"){module.exports=e}else if(typeof define==="function"&&define.amd){define(function(){return e})}else{chai.use(e)}}).call(this);
View
3,767 contrib/chai.js
3,767 additions, 0 deletions not shown
View
8 contrib/coffee-script.js
8 additions, 0 deletions not shown
View
4,999 contrib/mocha.js
4,999 additions, 0 deletions not shown
View
41 lib/casper-chai.coffee
@@ -0,0 +1,41 @@
+###
+Chai assertions for CasperJS
+
+Copyright (C) 2012 Brian M Hunt
+
+ Repository: http://github.com/brianmhunt/casper-chai.git
+ License: MIT (see LICENSE.txt)
+
+###
+
+# TODO/FIXME: Pass the casper instance in.
+
+casperChai = (_chai, utils) ->
+
+ # use "inDOM" instead of "exist" so we don't conflict with
+ # chai.js bdd
+ _chai.Assertion.addProperty('inDOM', () ->
+ selector = @_obj
+ @assert(casper.exists(selector),
+ 'expected selector #{this} to be in the DOM',
+ 'expected selector #{this} to not be in the DOM'
+ )
+ )
+
+#
+# "Module systems magic dance"
+#
+if (typeof require == "function" and
+ typeof exports == "object" and
+ typeof module == "object")
+ # NodeJS
+ module.exports = casperChai
+else if (typeof define == "function" and define.amd)
+ # AMD
+ define(() -> return casperChai)
+else
+ # Other environment (usually <script> tag):
+ # plug in to global chai instance directly.
+ chai.use(casperChai)
+
+
View
106 lib/sinon-chai.js
@@ -1,106 +0,0 @@
-(function (sinonChai) {
- "use strict";
-
- // Module systems magic dance.
-
- if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
- // NodeJS
- module.exports = sinonChai;
- } else if (typeof define === "function" && define.amd) {
- // AMD
- define(function () {
- return sinonChai;
- });
- } else {
- // Other environment (usually <script> tag): plug in to global chai instance directly.
- chai.use(sinonChai);
- }
-}(function sinonChai(chai, utils) {
- "use strict";
-
- var slice = Array.prototype.slice;
-
- function isSpy(putativeSpy) {
- return typeof putativeSpy === "function" &&
- typeof putativeSpy.getCall === "function" &&
- typeof putativeSpy.calledWithExactly === "function";
- }
-
- function isCall(putativeCall) {
- return putativeCall && isSpy(putativeCall.proxy);
- }
-
- function assertCanWorkWith(assertion) {
- if (!isSpy(assertion._obj) && !isCall(assertion._obj)) {
- throw new TypeError(utils.inspect(assertion._obj) + " is not a spy or a call to a spy!");
- }
- }
-
- function getMessages(spy, action, nonNegatedSuffix, always, args) {
- var verbPhrase = always ? "always have " : "have ";
- nonNegatedSuffix = nonNegatedSuffix || "";
- spy = spy.proxy || spy;
-
- function printfArray(array) {
- return spy.printf.apply(spy, array);
- }
-
- return {
- affirmative: printfArray(["expected %n to " + verbPhrase + action + nonNegatedSuffix].concat(args)),
- negative: printfArray(["expected %n to not " + verbPhrase + action].concat(args))
- };
- }
-
- function sinonProperty(name, action, nonNegatedSuffix) {
- utils.addProperty(chai.Assertion.prototype, name, function () {
- assertCanWorkWith(this);
-
- var messages = getMessages(this._obj, action, nonNegatedSuffix, false);
- this.assert(this._obj[name], messages.affirmative, messages.negative);
- });
- }
-
- function createSinonMethodHandler(sinonName, action, nonNegatedSuffix) {
- return function () {
- assertCanWorkWith(this);
-
- var alwaysSinonMethod = "always" + sinonName[0].toUpperCase() + sinonName.substring(1);
- var shouldBeAlways = utils.flag(this, "always") && typeof this._obj[alwaysSinonMethod] === "function";
- var sinonMethod = shouldBeAlways ? alwaysSinonMethod : sinonName;
-
- var messages = getMessages(this._obj, action, nonNegatedSuffix, shouldBeAlways, slice.call(arguments));
- this.assert(this._obj[sinonMethod].apply(this._obj, arguments), messages.affirmative, messages.negative);
- };
- }
-
- function sinonMethodAsProperty(name, action, nonNegatedSuffix) {
- var handler = createSinonMethodHandler(name, action, nonNegatedSuffix);
- utils.addProperty(chai.Assertion.prototype, name, handler);
- }
-
- function exceptionalSinonMethod(chaiName, sinonName, action, nonNegatedSuffix) {
- var handler = createSinonMethodHandler(sinonName, action, nonNegatedSuffix);
- utils.addMethod(chai.Assertion.prototype, chaiName, handler);
- }
-
- function sinonMethod(name, action, nonNegatedSuffix) {
- exceptionalSinonMethod(name, name, action, nonNegatedSuffix);
- }
-
- utils.addProperty(chai.Assertion.prototype, "always", function () {
- utils.flag(this, "always", true);
- });
-
- sinonProperty("called", "been called", " at least once, but it was never called");
- sinonProperty("calledOnce", "been called exactly once", ", but it was called %c%C");
- sinonProperty("calledTwice", "been called exactly twice", ", but it was called %c%C");
- sinonProperty("calledThrice", "been called exactly thrice", ", but it was called %c%C");
- sinonMethodAsProperty("calledWithNew", "been called with new");
- sinonMethod("calledBefore", "been called before %1");
- sinonMethod("calledAfter", "been called after %1");
- sinonMethod("calledOn", "been called with %1 as this", ", but it was called with %t instead");
- sinonMethod("calledWith", "been called with arguments %*", "%C");
- sinonMethod("calledWithExactly", "been called with exact arguments %*", "%C");
- sinonMethod("returned", "returned %1");
- exceptionalSinonMethod("thrown", "threw", "thrown %1");
-}));
View
38 package.json
@@ -1,42 +1,40 @@
{
- "name": "sinon-chai",
- "description": "Extends Chai with assertions for the Sinon.JS mocking framework.",
+ "name": "casper-chai",
+ "description": "Extends Chai with assertions for CasperJS testing.",
"keywords": [
- "sinon",
+ "casper",
"chai",
- "testing",
- "spies",
- "stubs",
- "mocks"
+ "casperjs",
+ "phantomjs"
],
- "version": "2.2.0",
- "author": "Domenic Denicola <domenic@domenicdenicola.com> (http://domenicdenicola.com)",
- "license": "WTFPL",
+ "version": "0.1.0",
+ "author": "Brian M Hunt <brianmhunt@gmail.com>",
+ "license": "MIT",
"repository": {
"type": "git",
- "url": "git://github.com/domenic/sinon-chai.git"
+ "url": "git://github.com/brianmhunt/casper-chai.git"
},
"bugs": {
- "url": "http://github.com/domenic/sinon-chai/issues"
+ "url": "http://github.com/brianmhunt/casper-chai/issues"
},
"directories": {
"lib": "./lib"
},
- "main": "./lib/sinon-chai.js",
+ "main": "./build/casper-chai.js",
"scripts": {
"test": "mocha",
- "lint": "jshint ./lib",
- "cover": "cover run node_modules/mocha/bin/_mocha && cover report html && opener ./cover_html/index.html"
+ "lint": "jshint ./lib"
},
"dependencies": {
- "sinon": ">=1.5 <2"
},
"devDependencies": {
+ "icolor": "*",
"chai": ">= 1.3.0",
- "coffee-script": ">= 1.4.0",
- "cover": ">= 0.2.8",
+ "glob": "*",
+ "lodash": "*",
+ "uglify-js2": "*",
"jshint": ">= 0.9.1",
- "mocha": ">= 1.7.0",
- "opener": ">= 1.3.0"
+ "jquery": ">= 1.8.2",
+ "underscore.string": ">= 2.3"
}
}
View
141 test/callArguments.coffee
@@ -1,141 +0,0 @@
-describe "Call arguments", ->
- spy = null
- arg1 = null
- arg2 = null
- notArg = null
-
- beforeEach ->
- spy = sinon.spy()
- arg1 = "A"
- arg2 = "B"
- notArg = "C"
-
- describe "calledWith", ->
- it "should throw an assertion error when the spy is not called", ->
- expect(-> spy.should.have.been.calledWith(arg1, arg2)).to.throw(AssertionError)
-
- it "should not throw when the spy is called with the correct arguments", ->
- spy(arg1, arg2)
-
- expect(-> spy.should.have.been.calledWith(arg1, arg2)).to.not.throw()
- expect(-> spy.getCall(0).should.have.been.calledWith(arg1, arg2)).to.not.throw()
-
- it "should not throw when the spy is called with the correct arguments and more", ->
- spy(arg1, arg2, notArg)
-
- expect(-> spy.should.have.been.calledWith(arg1, arg2)).to.not.throw()
- expect(-> spy.getCall(0).should.have.been.calledWith(arg1, arg2)).to.not.throw()
-
- it "should throw an assertion error when the spy is called with incorrect arguments", ->
- spy(notArg, arg1)
-
- expect(-> spy.should.have.been.calledWith(arg1, arg2)).to.throw(AssertionError)
- expect(-> spy.getCall(0).should.have.been.calledWith(arg1, arg2)).to.throw(AssertionError)
-
- it "should not throw when the spy is called with incorrect arguments but then correct ones", ->
- spy(notArg, arg1)
- spy(arg1, arg2)
-
- expect(-> spy.should.have.been.calledWith(arg1, arg2)).to.not.throw()
- expect(-> spy.getCall(1).should.have.been.calledWith(arg1, arg2)).to.not.throw()
-
-
- describe "always calledWith", ->
- it "should throw an assertion error when the spy is not called", ->
- expect(-> spy.should.always.have.been.calledWith(arg1, arg2)).to.throw(AssertionError)
- expect(-> spy.should.have.always.been.calledWith(arg1, arg2)).to.throw(AssertionError)
- expect(-> spy.should.have.been.always.calledWith(arg1, arg2)).to.throw(AssertionError)
-
- it "should not throw when the spy is called with the correct arguments", ->
- spy(arg1, arg2)
-
- expect(-> spy.should.always.have.been.calledWith(arg1, arg2)).to.not.throw()
- expect(-> spy.should.have.always.been.calledWith(arg1, arg2)).to.not.throw()
- expect(-> spy.should.have.been.always.calledWith(arg1, arg2)).to.not.throw()
-
- it "should not throw when the spy is called with the correct arguments and more", ->
- spy(arg1, arg2, notArg)
-
- expect(-> spy.should.always.have.been.calledWith(arg1, arg2)).to.not.throw()
- expect(-> spy.should.have.always.been.calledWith(arg1, arg2)).to.not.throw()
- expect(-> spy.should.have.been.always.calledWith(arg1, arg2)).to.not.throw()
-
- it "should throw an assertion error when the spy is called with incorrect arguments", ->
- spy(notArg, arg1)
-
- expect(-> spy.should.always.have.been.calledWith(arg1, arg2)).to.throw(AssertionError)
- expect(-> spy.should.have.always.been.calledWith(arg1, arg2)).to.throw(AssertionError)
- expect(-> spy.should.have.been.always.calledWith(arg1, arg2)).to.throw(AssertionError)
-
- it "should throw an assertion error when the spy is called with incorrect arguments but then correct ones", ->
- spy(notArg, arg1)
- spy(arg1, arg2)
-
- expect(-> spy.should.always.have.been.calledWith(arg1, arg2)).to.throw(AssertionError)
- expect(-> spy.should.have.always.been.calledWith(arg1, arg2)).to.throw(AssertionError)
- expect(-> spy.should.have.been.always.calledWith(arg1, arg2)).to.throw(AssertionError)
-
- describe "calledWithExactly", ->
- it "should throw an assertion error when the spy is not called", ->
- expect(-> spy.should.have.been.calledWithExactly(arg1, arg2)).to.throw(AssertionError)
-
- it "should not throw when the spy is called with the correct arguments", ->
- spy(arg1, arg2)
-
- expect(-> spy.should.have.been.calledWithExactly(arg1, arg2)).to.not.throw()
- expect(-> spy.getCall(0).should.have.been.calledWithExactly(arg1, arg2)).to.not.throw()
-
- it "should throw an assertion error when the spy is called with the correct arguments and more", ->
- spy(arg1, arg2, notArg)
-
- expect(-> spy.should.have.been.calledWithExactly(arg1, arg2)).to.throw(AssertionError)
- expect(-> spy.getCall(0).should.have.been.calledWithExactly(arg1, arg2)).to.throw(AssertionError)
-
- it "should throw an assertion error when the spy is called with incorrect arguments", ->
- spy(notArg, arg1)
-
- expect(-> spy.should.have.been.calledWithExactly(arg1, arg2)).to.throw(AssertionError)
- expect(-> spy.getCall(0).should.have.been.calledWithExactly(arg1, arg2)).to.throw(AssertionError)
-
- it "should not throw when the spy is called with incorrect arguments but then correct ones", ->
- spy(notArg, arg1)
- spy(arg1, arg2)
-
- expect(-> spy.should.have.been.calledWithExactly(arg1, arg2)).to.not.throw()
- expect(-> spy.getCall(1).should.have.been.calledWithExactly(arg1, arg2)).to.not.throw()
-
-
- describe "always calledWithExactly", ->
- it "should throw an assertion error when the spy is not called", ->
- expect(-> spy.should.always.have.been.calledWithExactly(arg1, arg2)).to.throw(AssertionError)
- expect(-> spy.should.have.always.been.calledWithExactly(arg1, arg2)).to.throw(AssertionError)
- expect(-> spy.should.have.been.always.calledWithExactly(arg1, arg2)).to.throw(AssertionError)
-
- it "should not throw when the spy is called with the correct arguments", ->
- spy(arg1, arg2)
-
- expect(-> spy.should.always.have.been.calledWithExactly(arg1, arg2)).to.not.throw()
- expect(-> spy.should.have.always.been.calledWithExactly(arg1, arg2)).to.not.throw()
- expect(-> spy.should.have.been.always.calledWithExactly(arg1, arg2)).to.not.throw()
-
- it "should throw an assertion error when the spy is called with the correct arguments and more", ->
- spy(arg1, arg2, notArg)
-
- expect(-> spy.should.always.have.been.calledWithExactly(arg1, arg2)).to.throw(AssertionError)
- expect(-> spy.should.have.always.been.calledWithExactly(arg1, arg2)).to.throw(AssertionError)
- expect(-> spy.should.have.been.always.calledWithExactly(arg1, arg2)).to.throw(AssertionError)
-
- it "should throw an assertion error when the spy is called with incorrect arguments", ->
- spy(notArg, arg1)
-
- expect(-> spy.should.always.have.been.calledWithExactly(arg1, arg2)).to.throw(AssertionError)
- expect(-> spy.should.have.always.been.calledWithExactly(arg1, arg2)).to.throw(AssertionError)
- expect(-> spy.should.have.been.always.calledWithExactly(arg1, arg2)).to.throw(AssertionError)
-
- it "should throw an assertion error when the spy is called with incorrect arguments but then correct ones", ->
- spy(notArg, arg1)
- spy(arg1, arg2)
-
- expect(-> spy.should.always.have.been.calledWithExactly(arg1, arg2)).to.throw(AssertionError)
- expect(-> spy.should.have.always.been.calledWithExactly(arg1, arg2)).to.throw(AssertionError)
- expect(-> spy.should.have.been.always.calledWithExactly(arg1, arg2)).to.throw(AssertionError)
View
74 test/callContext.coffee
@@ -1,74 +0,0 @@
-describe "Call context", ->
- spy = null
- target = null
- notTheTarget = null
-
- beforeEach ->
- spy = sinon.spy()
- target = {}
- notTheTarget = {}
-
- describe "calledOn", ->
- it "should throw an assertion error if the spy is never called", ->
- expect(-> spy.should.have.been.calledOn(target)).to.throw(AssertionError)
-
- it "should throw an assertion error if the spy is called without a context", ->
- spy()
-
- expect(-> spy.should.have.been.calledOn(target)).to.throw(AssertionError)
- expect(-> spy.getCall(0).should.have.been.calledOn(target)).to.throw(AssertionError)
-
- it "should throw an assertion error if the spy is called on the wrong context", ->
- spy.call(notTheTarget)
-
- expect(-> spy.should.have.been.calledOn(target)).to.throw(AssertionError)
- expect(-> spy.getCall(0).should.have.been.calledOn(target)).to.throw(AssertionError)
-
- it "should not throw if the spy is called on the specified context", ->
- spy.call(target)
-
- expect(-> spy.should.have.been.calledOn(target)).to.not.throw()
- expect(-> spy.getCall(0).should.have.been.calledOn(target)).to.not.throw()
-
- it "should not throw if the spy is called on another context and also the specified context", ->
- spy.call(notTheTarget)
- spy.call(target)
-
- expect(-> spy.should.have.been.calledOn(target)).to.not.throw()
- expect(-> spy.getCall(1).should.have.been.calledOn(target)).to.not.throw()
-
- describe "always calledOn", ->
- it "should throw an assertion error if the spy is never called", ->
- expect(-> spy.should.always.have.been.calledOn(target)).to.throw(AssertionError)
- expect(-> spy.should.have.always.been.calledOn(target)).to.throw(AssertionError)
- expect(-> spy.should.have.been.always.calledOn(target)).to.throw(AssertionError)
-
- it "should throw an assertion error if the spy is called without a context", ->
- spy()
-
- expect(-> spy.should.always.have.been.calledOn(target)).to.throw(AssertionError)
- expect(-> spy.should.have.always.been.calledOn(target)).to.throw(AssertionError)
- expect(-> spy.should.have.been.always.calledOn(target)).to.throw(AssertionError)
-
- it "should throw an assertion error if the spy is called on the wrong context", ->
- spy.call(notTheTarget)
-
- expect(-> spy.should.always.have.been.calledOn(target)).to.throw(AssertionError)
- expect(-> spy.should.have.always.been.calledOn(target)).to.throw(AssertionError)
- expect(-> spy.should.have.been.always.calledOn(target)).to.throw(AssertionError)
-
- it "should not throw if the spy is called on the specified context", ->
- spy.call(target)
-
- expect(-> spy.should.always.have.been.calledOn(target)).to.not.throw()
- expect(-> spy.should.have.always.been.calledOn(target)).to.not.throw()
- expect(-> spy.should.have.been.always.calledOn(target)).to.not.throw()
-
- it "should throw an assertion error if the spy is called on another context and also the specified context", ->
- spy.call(notTheTarget)
- spy.call(target)
-
- expect(-> spy.should.always.have.been.calledOn(target)).to.throw(AssertionError)
- expect(-> spy.should.have.always.been.calledOn(target)).to.throw(AssertionError)
- expect(-> spy.should.have.been.always.calledOn(target)).to.throw(AssertionError)
-
View
96 test/callCount.coffee
@@ -1,96 +0,0 @@
-describe "Call count", ->
- spy = null
-
- beforeEach ->
- spy = sinon.spy()
-
- describe "called", ->
- it "should throw an assertion error when the spy is not called", ->
- expect(-> spy.should.have.been.called).to.throw(AssertionError)
-
- it "should not throw when the spy is called once", ->
- spy()
-
- expect(-> spy.should.have.been.called).to.not.throw()
-
- it "should not throw when the spy is called twice", ->
- spy()
- spy()
-
- expect(-> spy.should.have.been.called).to.not.throw()
-
- describe "not called", ->
- it "should not throw when the spy is not called", ->
- expect(-> spy.should.not.have.been.called).to.not.throw()
-
- it "should throw an assertion error when the spy is called once", ->
- spy()
-
- expect(-> spy.should.not.have.been.called).to.throw(AssertionError)
-
- describe "calledOnce", ->
- it "should throw an assertion error when the spy is not called", ->
- expect(-> spy.should.have.been.calledOnce).to.throw(AssertionError)
-
- it "should not throw when the spy is called once", ->
- spy()
-
- expect(-> spy.should.have.been.calledOnce).to.not.throw()
-
- it "should throw an assertion error when the spy is called twice", ->
- spy()
- spy()
-
- expect(-> spy.should.have.been.calledOnce).to.throw(AssertionError)
-
- describe "calledTwice", ->
- it "should throw an assertion error when the spy is not called", ->
- expect(-> spy.should.have.been.calledTwice).to.throw(AssertionError)
-
- it "should throw an assertion error when the spy is called once", ->
- spy()
-
- expect(-> spy.should.have.been.calledTwice).to.throw(AssertionError)
-
- it "should not throw when the spy is called twice", ->
- spy()
- spy()
-
- expect(-> spy.should.have.been.calledTwice).to.not.throw()
-
- it "should throw an assertion error when the spy is called thrice", ->
- spy()
- spy()
- spy()
-
- expect(-> spy.should.have.been.calledTwice).to.throw(AssertionError)
-
- describe "calledThrice", ->
- it "should throw an assertion error when the spy is not called", ->
- expect(-> spy.should.have.been.calledThrice).to.throw(AssertionError)
-
- it "should throw an assertion error when the spy is called once", ->
- spy()
-
- expect(-> spy.should.have.been.calledThrice).to.throw(AssertionError)
-
- it "should throw an assertion error when the spy is called twice", ->
- spy()
- spy()
-
- expect(-> spy.should.have.been.calledThrice).to.throw(AssertionError)
-
- it "should not throw when the spy is called thrice", ->
- spy()
- spy()
- spy()
-
- expect(-> spy.should.have.been.calledThrice).to.not.throw()
-
- it "should throw an assertion error when the spy is called four times", ->
- spy()
- spy()
- spy()
- spy()
-
- expect(-> spy.should.have.been.calledThrice).to.throw(AssertionError)
View
59 test/callOrder.coffee
@@ -1,59 +0,0 @@
-describe "Call order", ->
- spy1 = null
- spy2 = null
-
- beforeEach ->
- spy1 = sinon.spy()
- spy2 = sinon.spy()
-
- describe "spy1 calledBefore spy2", ->
- it "should throw an assertion error when neither spy is called", ->
- expect(-> spy1.should.have.been.calledBefore(spy2)).to.throw(AssertionError)
-
- it "should not throw when only spy 1 is called", ->
- spy1()
-
- expect(-> spy1.should.have.been.calledBefore(spy2)).to.not.throw()
-
- it "should throw an assertion error when only spy 2 is called", ->
- spy2()
-
- expect(-> spy1.should.have.been.calledBefore(spy2)).to.throw(AssertionError)
-
- it "should not throw when spy 1 is called before spy 2", ->
- spy1()
- spy2()
-
- expect(-> spy1.should.have.been.calledBefore(spy2)).to.not.throw()
-
- it "should throw an assertion error when spy 1 is called after spy 2", ->
- spy2()
- spy1()
-
- expect(-> spy1.should.have.been.calledBefore(spy2)).to.throw(AssertionError)
-
- describe "spy1 calledAfter spy2", ->
- it "should throw an assertion error when neither spy is called", ->
- expect(-> spy1.should.have.been.calledAfter(spy2)).to.throw(AssertionError)
-
- it "should throw an assertion error when only spy 1 is called", ->
- spy1()
-
- expect(-> spy1.should.have.been.calledAfter(spy2)).to.throw(AssertionError)
-
- it "should throw an assertion error when only spy 2 is called", ->
- spy2()
-
- expect(-> spy1.should.have.been.calledAfter(spy2)).to.throw(AssertionError)
-
- it "should throw an assertion error when spy 1 is called before spy 2", ->
- spy1()
- spy2()
-
- expect(-> spy1.should.have.been.calledAfter(spy2)).to.throw(AssertionError)
-
- it "should not throw when spy 1 is called after spy 2", ->
- spy2()
- spy1()
-
- expect(-> spy1.should.have.been.calledAfter(spy2)).to.not.throw()
View
58 test/callingWithNew.coffee
@@ -1,58 +0,0 @@
-describe "Calling with new", ->
- spy = null
-
- beforeEach ->
- spy = sinon.spy()
-
- describe "calledWithNew", ->
- it "should throw an assertion error if the spy is never called", ->
- expect(-> spy.should.have.been.calledWithNew).to.throw(AssertionError)
-
- it "should throw an assertion error if the spy is called without `new`", ->
- spy()
-
- expect(-> spy.should.have.been.calledWithNew).to.throw(AssertionError)
- expect(-> spy.getCall(0).should.have.been.calledWithNew).to.throw(AssertionError)
-
- it "should not throw if the spy is called with `new`", ->
- new spy()
-
- expect(-> spy.should.have.been.calledWithNew).to.not.throw()
- expect(-> spy.getCall(0).should.have.been.calledWithNew).to.not.throw()
-
- it "should not throw if the spy is called with `new` and also without `new`", ->
- spy()
- new spy()
-
- expect(-> spy.should.have.been.calledWithNew).to.not.throw()
- expect(-> spy.getCall(1).should.have.been.calledWithNew).to.not.throw()
-
- describe "always calledWithNew", ->
- it "should throw an assertion error if the spy is never called", ->
- expect(-> spy.should.always.have.been.calledWithNew).to.throw(AssertionError)
- expect(-> spy.should.have.always.been.calledWithNew).to.throw(AssertionError)
- expect(-> spy.should.have.been.always.calledWithNew).to.throw(AssertionError)
-
- it "should throw an assertion error if the spy is called without `new`", ->
- spy()
-
- expect(-> spy.should.always.have.been.calledWithNew).to.throw(AssertionError)
- expect(-> spy.should.have.always.been.calledWithNew).to.throw(AssertionError)
- expect(-> spy.should.have.been.always.calledWithNew).to.throw(AssertionError)
-
- it "should not throw if the spy is called with `new`", ->
- new spy()
-
- expect(-> spy.should.always.have.been.calledWithNew).to.not.throw()
- expect(-> spy.should.have.always.been.calledWithNew).to.not.throw()
- expect(-> spy.should.have.been.always.calledWithNew).to.not.throw()
-
- it "should throw an assertion error if the spy is called with `new` and also without `new`", ->
- spy()
- new spy()
-
- expect(-> spy.should.always.have.been.calledWithNew).to.throw(AssertionError)
- expect(-> spy.should.have.always.been.calledWithNew).to.throw(AssertionError)
- expect(-> spy.should.have.been.always.calledWithNew).to.throw(AssertionError)
-
-
View
11 test/common.coffee
@@ -0,0 +1,11 @@
+
+describe "the casperChai addons to Chai", ->
+
+ it "includes the 'inDOM' property", ->
+ casper.open "#{serverAddr}/test"
+ casper.then ->
+ expect("#hello").to.not.be.inDOM
+ expect("#hello").to.not.be.inDOM
+
+
+
View
14 test/common.js
@@ -1,14 +0,0 @@
-global.sinon = require("sinon");
-global.chai = require("chai");
-global.should = require("chai").should();
-global.expect = require("chai").expect;
-global.AssertionError = require("chai").AssertionError;
-
-global.swallow = function (thrower) {
- try {
- thrower();
- } catch (e) { }
-};
-
-var sinonChai = require("../lib/sinon-chai");
-chai.use(sinonChai);
View
256 test/messages.coffee
@@ -1,256 +0,0 @@
-describe "Messages", ->
- describe "about call count", ->
- it "should be correct for the base cases", ->
- spy = sinon.spy()
-
- expect(-> spy.should.have.been.called).to
- .throw("expected spy to have been called at least once, but it was never called")
- expect(-> spy.should.have.been.calledOnce).to
- .throw("expected spy to have been called exactly once, but it was called 0 times")
- expect(-> spy.should.have.been.calledTwice).to
- .throw("expected spy to have been called exactly twice, but it was called 0 times")
- expect(-> spy.should.have.been.calledThrice).to
- .throw("expected spy to have been called exactly thrice, but it was called 0 times")
-
- it "should be correct for the negated cases", ->
- calledOnce = sinon.spy()
- calledTwice = sinon.spy()
- calledThrice = sinon.spy()
-
- calledOnce()
- calledTwice()
- calledTwice()
- calledThrice()
- calledThrice()
- calledThrice()
-
- expect(-> calledOnce.should.not.have.been.called).to
- .throw("expected spy to not have been called")
- expect(-> calledOnce.should.not.have.been.calledOnce).to
- .throw("expected spy to not have been called exactly once")
- expect(-> calledTwice.should.not.have.been.calledTwice).to
- .throw("expected spy to not have been called exactly twice")
- expect(-> calledThrice.should.not.have.been.calledThrice).to
- .throw("expected spy to not have been called exactly thrice")
-
- describe "about call order", ->
- it "should be correct for the base cases", ->
- spyA = sinon.spy()
- spyB = sinon.spy()
-
- spyA.displayName = "spyA"
- spyB.displayName = "spyB"
-
- expect(-> spyA.should.have.been.calledBefore(spyB)).to
- .throw("expected spyA to have been called before function spyB() {}")
- expect(-> spyB.should.have.been.calledAfter(spyA)).to
- .throw("expected spyB to have been called after function spyA() {}")
-
- it "should be correct for the negated cases", ->
- spyA = sinon.spy()
- spyB = sinon.spy()
-
- spyA.displayName = "spyA"
- spyB.displayName = "spyB"
-
- spyA()
- spyB()
-
- expect(-> spyA.should.not.have.been.calledBefore(spyB)).to
- .throw("expected spyA to not have been called before function spyB() {}")
- expect(-> spyB.should.not.have.been.calledAfter(spyA)).to
- .throw("expected spyB to not have been called after function spyA() {}")
-
- describe "about call context", ->
- it "should be correct for the basic case", ->
- spy = sinon.spy()
- context = {}
- badContext = { x: "y" }
-
- spy.call(badContext)
-
- expected = "expected spy to have been called with { } as this, but it was called with " +
- spy.printf("%t") + " instead"
- expect(-> spy.should.have.been.calledOn(context)).to.throw(expected)
- expect(-> spy.getCall(0).should.have.been.calledOn(context)).to.throw(expected)
-
- it "should be correct for the negated case", ->
- spy = sinon.spy()
- context = {}
-
- spy.call(context)
-
- expected = "expected spy to not have been called with { } as this"
- expect(-> spy.should.not.have.been.calledOn(context)).to.throw(expected)
- expect(-> spy.getCall(0).should.not.have.been.calledOn(context)).to.throw(expected)
-
- it "should be correct for the always case", ->
- spy = sinon.spy()
- context = {}
- badContext = { x: "y" }
-
- spy.call(badContext)
-
- expected = "expected spy to always have been called with { } as this, but it was called with " +
- spy.printf("%t") + " instead"
- expect(-> spy.should.always.have.been.calledOn(context)).to.throw(expected)
-
- describe "about calling with new", ->
- it "should be correct for the basic case", ->
- spy = sinon.spy()
-
- spy()
-
- expected = "expected spy to have been called with new"
- expect(-> spy.should.have.been.calledWithNew).to.throw(expected)
- expect(-> spy.getCall(0).should.have.been.calledWithNew).to.throw(expected)
-
- it "should be correct for the negated case", ->
- spy = sinon.spy()
-
- new spy()
-
- expected = "expected spy to not have been called with new"
- expect(-> spy.should.not.have.been.calledWithNew).to.throw(expected)
- expect(-> spy.getCall(0).should.not.have.been.calledWithNew).to.throw(expected)
-
- it "should be correct for the always case", ->
- spy = sinon.spy()
-
- new spy()
- spy()
-
- expected = "expected spy to always have been called with new"
- expect(-> spy.should.always.have.been.calledWithNew).to.throw(expected)
-
- describe "about call arguments", ->
- it "should be correct for the basic cases", ->
- spy = sinon.spy()
-
- spy(1, 2, 3)
-
- expect(-> spy.should.have.been.calledWith("a", "b", "c")).to
- .throw("expected spy to have been called with arguments a, b, c\n spy(1, 2, 3)")
- expect(-> spy.should.have.been.calledWithExactly("a", "b", "c")).to
- .throw("expected spy to have been called with exact arguments a, b, c\n spy(1, 2, 3)")
-
- expect(-> spy.getCall(0).should.have.been.calledWith("a", "b", "c")).to
- .throw("expected spy to have been called with arguments a, b, c\n spy(1, 2, 3)")
- expect(-> spy.getCall(0).should.have.been.calledWithExactly("a", "b", "c")).to
- .throw("expected spy to have been called with exact arguments a, b, c\n spy(1, 2, 3)")
-
- it "should be correct for the negated cases", ->
- spy = sinon.spy()
-
- spy(1, 2, 3)
-
- expect(-> spy.should.not.have.been.calledWith(1, 2, 3)).to
- .throw("expected spy to not have been called with arguments 1, 2, 3")
- expect(-> spy.should.not.have.been.calledWithExactly(1, 2, 3)).to
- .throw("expected spy to not have been called with exact arguments 1, 2, 3")
-
- expect(-> spy.getCall(0).should.not.have.been.calledWith(1, 2, 3)).to
- .throw("expected spy to not have been called with arguments 1, 2, 3")
- expect(-> spy.getCall(0).should.not.have.been.calledWithExactly(1, 2, 3)).to
- .throw("expected spy to not have been called with exact arguments 1, 2, 3")
-
- it "should be correct for the always cases", ->
- spy = sinon.spy()
-
- spy(1, 2, 3)
- spy("a", "b", "c")
-
- expected = "expected spy to always have been called with arguments 1, 2, 3\n spy(1, 2, 3)\n" +
- " spy(a, b, c)"
- expect(-> spy.should.always.have.been.calledWith(1, 2, 3)).to.throw(expected)
-
- expectedExactly = "expected spy to always have been called with exact arguments 1, 2, 3\n" +
- " spy(1, 2, 3)\n spy(a, b, c)"
- expect(-> spy.should.always.have.been.calledWithExactly(1, 2, 3)).to
- .throw(expectedExactly)
-
- describe "about returning", ->
- it "should be correct for the basic case", ->
- spy = sinon.spy.create(-> 1)
-
- spy()
-
- expect(-> spy.should.have.returned(2)).to.throw("expected spy to have returned 2")
- expect(-> spy.getCall(0).should.have.returned(2)).to.throw("expected spy to have returned 2")
-
- it "should be correct for the negated case", ->
- spy = sinon.spy.create(-> 1)
-
- spy()
-
- expect(-> spy.should.not.have.returned(1)).to.throw("expected spy to not have returned 1")
- expect(-> spy.getCall(0).should.not.have.returned(1)).to.throw("expected spy to not have returned 1")
-
- it "should be correct for the always case", ->
- spy = sinon.spy.create(-> 1)
-
- spy()
-
- expect(-> spy.should.always.have.returned(2)).to.throw("expected spy to always have returned 2")
-
- describe "about throwing", ->
- it "should be correct for the basic cases", ->
- spy = sinon.spy()
- throwingSpy = sinon.spy.create(-> throw new Error())
-
- spy()
- swallow(throwingSpy)
-
- expect(-> spy.should.have.thrown()).to.throw("expected spy to have thrown")
- expect(-> spy.getCall(0).should.have.thrown()).to.throw("expected spy to have thrown")
-
- expect(-> throwingSpy.should.have.thrown("TypeError")).to.throw("expected spy to have thrown TypeError")
- expect(-> throwingSpy.getCall(0).should.have.thrown("TypeError")).to
- .throw("expected spy to have thrown TypeError")
-
- expect(-> throwingSpy.should.have.thrown({ message: "x" })).to
- .throw('expected spy to have thrown { message: "x" }')
- expect(-> throwingSpy.getCall(0).should.have.thrown({ message: "x" })).to
- .throw('expected spy to have thrown { message: "x" }')
-
- it "should be correct for the negated cases", ->
- error = new Error("boo!")
- spy = sinon.spy.create(-> throw error)
-
- swallow(spy)
-
- expect(-> spy.should.not.have.thrown()).to.throw("expected spy to not have thrown")
- expect(-> spy.getCall(0).should.not.have.thrown()).to.throw("expected spy to not have thrown")
-
- expect(-> spy.should.not.have.thrown("Error")).to.throw("expected spy to not have thrown Error")
- expect(-> spy.getCall(0).should.not.have.thrown("Error")).to.throw("expected spy to not have thrown Error")
-
- expect(-> spy.should.not.have.thrown(error)).to
- .throw("expected spy to not have thrown Error: boo!")
- expect(-> spy.getCall(0).should.not.have.thrown(error)).to
- .throw("expected spy to not have thrown Error: boo!")
-
- it "should be correct for the always cases", ->
- spy = sinon.spy()
- throwingSpy = sinon.spy.create(-> throw new Error())
-
- spy()
- swallow(throwingSpy)
-
- expect(-> spy.should.have.always.thrown()).to
- .throw("expected spy to always have thrown")
-
- expect(-> throwingSpy.should.have.always.thrown("TypeError")).to
- .throw("expected spy to always have thrown TypeError")
-
- expect(-> throwingSpy.should.have.always.thrown({ message: "x" })).to
- .throw('expected spy to always have thrown { message: "x" }')
-
- describe "when used on a non-spy/non-call", ->
- notSpy = ->
-
- it "should be informative for properties", ->
- expect(-> notSpy.should.have.been.called).to.throw(TypeError, /not a spy/)
-
- it "should be informative for methods", ->
- expect(-> notSpy.should.have.been.calledWith("foo")).to.throw(TypeError, /not a spy/)
View
3  test/mocha.opts
@@ -1,3 +0,0 @@
---compilers coffee:coffee-script
---reporter spec
---require test/common
View
56 test/returning.coffee
@@ -1,56 +0,0 @@
-describe "Returning", ->
- describe "returned", ->
- it "should throw an assertion error if the spy does not return the correct value", ->
- spy = sinon.spy.create(-> 1)
-
- spy()
-
- expect(-> spy.should.have.returned(2)).to.throw(AssertionError)
- expect(-> spy.getCall(0).should.have.returned(2)).to.throw(AssertionError)
-
- it "should not throw if the spy returns the correct value", ->
- spy = sinon.spy.create(-> 1)
-
- spy()
-
- expect(-> spy.should.have.returned(1)).to.not.throw()
- expect(-> spy.getCall(0).should.have.returned(1)).to.not.throw()
-
- it "should not throw if the spy returns the correct value amongst others", ->
- values = [1, 2, 3]
- spy = sinon.spy.create(-> values[spy.callCount - 1])
-
- spy()
- spy()
- spy()
-
- expect(-> spy.should.have.returned(1)).to.not.throw()
- expect(-> spy.getCall(0).should.have.returned(1)).to.not.throw()
-
- describe "always returned", ->
- it "should throw an assertion error if the spy does not return the correct value", ->
- spy = sinon.spy.create(-> 1)
-
- spy()
-
- expect(-> spy.should.always.have.returned(2)).to.throw(AssertionError)
- expect(-> spy.should.have.always.returned(2)).to.throw(AssertionError)
-
- it "should not throw if the spy returns the correct value", ->
- spy = sinon.spy.create(-> 1)
-
- spy()
-
- expect(-> spy.should.have.always.returned(1)).to.not.throw()
- expect(-> spy.should.always.have.returned(1)).to.not.throw()
-
- it "should throw an assertion error if the spy returns the correct value amongst others", ->
- values = [1, 2, 3]
- spy = sinon.spy.create(-> values[spy.callCount - 1])
-
- spy()
- spy()
- spy()
-
- expect(-> spy.should.always.have.returned(1)).to.throw(AssertionError)
- expect(-> spy.should.have.always.returned(1)).to.throw(AssertionError)
View
317 test/run.js
@@ -0,0 +1,317 @@
+#!/usr/bin/env casperjs
+
+if (!phantom.casperLoaded) {
+ console.log('This script must be invoked using the casperjs executable');
+ phantom.exit(1);
+}
+
+var fs = require('fs'),
+ colorizer = require('colorizer'),
+ utils = require('utils'),
+ cwd = fs.workingDirectory,
+ serverPort = 8523, // the port where we create a server
+ serverAddr = "localhost:"+serverPort,
+ any_failures = false, // true when there has been a failure
+ casper;
+
+
+/* Change to the /test directory
+ *
+ * Figure out where we are by looking for package.json
+ */
+if (fs.exists(cwd + "/package.json")) {
+ // we are in casper-chai
+ fs.changeWorkingDirectory("test");
+} else if (fs.exists(cwd + "/../package.json")) {
+ // we are in casper-chai/*/ (likely * = test)
+ fs.changeWorkingDirectory("../test");
+} else {
+ // oh for __file__.
+ console.log("run.js must be called from casper-chai or casper-chai/test");
+ casper.exit(1);
+}
+
+/*
+ * Include modules that were installed with npm.
+ */
+function require_node_module(name) {
+ var node_modules, pkg, pkg_main;
+ node_modules = "../node_modules/";
+
+ pkg = JSON.parse(fs.read(node_modules + name + "/package.json"));
+ pkg_main = node_modules + name + "/" + pkg.main;
+ return require("./" + pkg_main);
+}
+
+/*
+ * Load dependencies
+ */
+_ = require_node_module("lodash");
+_.str = require_node_module('underscore.string');
+$ = require_node_module('jquery');
+require_node_module('icolor');
+
+
+/*
+ * While we could use an npm module for the following, it's a pain because
+ * PhantomJS does not have some modules (eg 'path') that Node does.
+ *
+ * The simple solution we use is to download a "pre-compiled" coffee-script.
+ */
+phantom.injectJs("../contrib/coffee-script.js"); // creates CoffeeScript
+require('../contrib/mocha');
+chai = require("../contrib/chai");
+
+/* chai-isms
+ */
+assert = chai.assert;
+expect = chai.expect;
+
+// FIXME: the following throws
+// RangeError: Maximum call stack size exceeded.
+// should = chai.should();
+
+/*
+ * Create the casper object we'll use for testing
+ */
+casper = require('casper').create({
+ exitOnError: false,
+ pageSettings: {
+ loadImages: false,
+ loadPlugins: false
+ },
+ onLoadError: function (err) {
+ console.log("Unable to load resource: ".redbg.white + err);
+ },
+ onTimeout: function (err) {
+ console.log(("Timeout: " + err).redbg.white);
+ },
+ logLevel: 'debug',
+ verbose: true,
+});
+
+/*
+ * Create a custom Mocha reporter.
+ *
+ * See conversation at https://github.com/n1k0/casperjs/issues/278
+ */
+function CasperReporter(runner) {
+ var self = this,
+ stats = this.stats = {
+ suites: 0,
+ tests: 0,
+ passes: 0,
+ pending: 0,
+ failures: 0
+ },
+ failures = [],
+ indents = 0,
+ symbols = {
+ ok: '',
+ err: '',
+ middot: '',
+ dot: ''
+ };
+
+ function indent(str) {
+ return _.str.pad("", 2 * indents) + str;
+ }
+
+ if (!runner) {
+ return;
+ }
+
+ this.runner = runner;
+ runner.stats = stats;
+
+ runner.on('start', function() {});
+
+ runner.on('suite', function(suite) {
+ console.log("\n" + indent(suite.title.cyan.underline));
+ ++indents;
+ });
+
+ runner.on('suite end', function(suite) {
+ --indents;
+ if (1 === indents) {
+ console.log();
+ }
+ });
+
+ runner.on('test', function(test) {
+ console.log("\n" + indent(symbols.middot + " " + test.title));
+ });
+
+ runner.on('pending', function(){
+ console.log(indent("pending ".magenta + test.title));
+ });
+
+ runner.on('pass', function(test){
+ console.log(indent(symbols.ok + " (" + test.title + ")").green);
+ stats.passes++;
+ });
+
+ runner.on('fail', function(test, err){
+ stats.failures++;
+ test.err = err;
+ failures.push(test);
+ console.log(indent(symbols.err + " (" + test.title + ")").red +
+ ": " + err);
+ });
+
+ runner.on('test end', function(test){
+ stats.tests = stats.tests || 0;
+ stats.tests++;
+ });
+
+ runner.on('end', function(){
+ if (stats.failures) {
+ msg = (stats.failures + " tests failed").red;
+ any_failures = true;
+ } else {
+ msg = "All tests passed".green;
+ }
+ msg = "\n" + msg + " (" + stats.tests + " tests run).";
+ console.log(msg);
+ });
+}
+
+/*
+ * Set up Mocha with our custom reporter and BDD-style settings
+ */
+mocha.setup({
+ ui: 'bdd',
+ reporter: CasperReporter
+});
+
+/*
+ * After every Mocha test we flush the Casper 'steps' stack.
+ *
+ * Because afterEach calls the asynchronous Casper steps, the actual
+ * those tests can be synchronous. All Casper tests will occur in this
+ * afterEach.
+ */
+afterEach(function (done) {
+ // There is no need to print here b/c mocha test emit will
+ // capture.
+ if (casper.steps.length) {
+ // There's work to be done.
+ casper.run(function () { done(); });
+ } else {
+ // Nothing to see here. Move along.
+ done();
+ }
+});
+
+/*
+ * Set up some color logging.
+ */
+casper.on('http.status.200', function(resource) {
+ console.log("[HTTP 200]".greenbg.black + " <" + resource.url.green + ">");
+});
+
+casper.on('http.status.404', function(resource) {
+ console.log("[HTTP 404]".redbg.black + " <" + resource.url.red + ">");
+});
+
+casper.on('http.status.500', function(resource) {
+ console.log("[HTTP 500]".redbg.black + " <" + resource.url.red + ">");
+});
+
+//
+// Capture remote log messages
+//
+casper.on('remote.message', function(msg) {
+ console.log(">>> ".cyan + msg.bluebg.yellow);
+});
+
+// Set up casperChai.
+// TODO: option to use ../lib/casper-chai (i.e. unbuilt coffeescript)
+casperChai = require("../build/casper-chai");
+chai.use(casperChai);
+
+/*
+ * Load all the .coffee files
+ */
+_.each(fs.list("./"), function (specFile) {
+ // grep out files that do not end with .coffee
+ if (!_.str.endsWith(specFile, ".coffee")) {
+ return;
+ }
+
+ console.log("Loading", specFile.yellow);
+
+ // the specFiles contain the tests i.e. describe(..., it ...)
+ CoffeeScript.run(fs.read(specFile));
+});
+
+
+/* Patch Function.prototype.bind
+ *
+ * Workaround for PhantomJS 1.7.0 bug
+ * http://code.google.com/p/phantomjs/issues/detail?id=522
+ *
+ * The following function is from:
+ * https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Function/bind
+ */
+if (!Function.prototype.bind) {
+ Function.prototype.bind = function (oThis) {
+ if (typeof this !== "function") {
+ // closest thing possible to the ECMAScript 5 internal IsCallable function
+ throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
+ }
+
+ var aArgs = Array.prototype.slice.call(arguments, 1),
+ fToBind = this,
+ fNOP = function () {},
+ fBound = function () {
+ return fToBind.apply(this instanceof fNOP && oThis
+ ? this
+ : oThis,
+ aArgs.concat(Array.prototype.slice.call(arguments)));
+ };
+
+ fNOP.prototype = this.prototype;
+ fBound.prototype = new fNOP();
+
+ return fBound;
+ };
+}
+/*
+ * Start Mongoose webserver
+ * https://github.com/ariya/phantomjs/wiki/API-Reference
+ */
+require('webserver').create().listen(serverPort, function (request, response) {
+ var fileToRead;
+ response.statusCode = 200;
+
+ /* For obvious reasons, don't leave this running. It can read any file passed
+ * in.
+ */
+ fileToRead = _.str.strRightBack(request.url, "/");
+
+ if (fileToRead.indexOf('..') !== -1) {
+ response.statusCode = 403; // forbidden
+ response.write("Forbidden: " + fileToRead);
+ }
+
+ console.log("Sending file", fileToRead);
+
+ response.write(fs.read(fileToRead));
+
+ response.close();
+});
+
+
+
+
+/*
+ * Start casper.
+ */
+casper.start();
+
+// here we go.
+mocha.run(function () {
+ casper.exit(any_failures);
+});
+
View
11 test/simple.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>The Title</title>
+ </head>
+ <body>
+ <h1>A Header</h1>
+
+ Text.
+ </body>
+</html>
View
145 test/throwing.coffee
@@ -1,145 +0,0 @@
-describe "Throwing", ->
- describe "thrown()", ->
- it "should throw an assertion error if the spy does not throw at all", ->
- spy = sinon.spy.create(->)
-
- spy()
-
- expect(-> spy.should.have.thrown()).to.throw(AssertionError)
- expect(-> spy.getCall(0).should.have.thrown()).to.throw(AssertionError)
-
- it "should not throw if the spy throws", ->
- spy = sinon.spy.create(-> throw new Error())
-
- swallow(spy)
-
- expect(-> spy.should.have.thrown()).to.not.throw()
- expect(-> spy.getCall(0).should.have.thrown()).to.not.throw()
-
- it "should not throw if the spy throws once but not the next time", ->
- spy = sinon.spy.create(-> throw new Error() unless spy.callCount > 1)
-
- swallow(spy)
- swallow(spy)
-
- expect(-> spy.should.have.thrown()).to.not.throw()
- expect(-> spy.getCall(0).should.have.thrown()).to.not.throw()
-
- describe "thrown(errorObject)", ->
- error = null
-
- beforeEach ->
- error = new Error("boo!")
-
- it "should throw an assertion error if the spy does not throw at all", ->
- spy = sinon.spy.create(->)
-
- spy()
-
- expect(-> spy.should.have.thrown(error)).to.throw(AssertionError)
- expect(-> spy.getCall(0).should.have.thrown(error)).to.throw(AssertionError)
-
- it "should throw an assertion error if the spy throws the wrong error", ->
- spy = sinon.spy.create(-> new Error("eek!"))
-
- swallow(spy)
-
- expect(-> spy.should.have.thrown(error)).to.throw(AssertionError)
- expect(-> spy.getCall(0).should.have.thrown(error)).to.throw(AssertionError)
-
- it "should not throw if the spy throws", ->
- spy = sinon.spy.create(-> throw error)
-
- swallow(spy)
-
- expect(-> spy.should.have.thrown(error)).to.not.throw()
- expect(-> spy.getCall(0).should.have.thrown(error)).to.not.throw()
-
- it "should not throw if the spy throws once but not the next time", ->
- spy = sinon.spy.create(-> throw error unless spy.callCount > 1)
-
- swallow(spy)
- swallow(spy)
-
- expect(-> spy.should.have.thrown(error)).to.not.throw()
- expect(-> spy.getCall(0).should.have.thrown(error)).to.not.throw()
-
- describe "thrown(errorTypeString)", ->
- error = null
-
- beforeEach ->
- error = new TypeError("boo!")
-
- it "should throw an assertion error if the spy does not throw at all", ->
- spy = sinon.spy.create(->)
-
- spy()
-
- expect(-> spy.should.have.thrown("TypeError")).to.throw(AssertionError)
- expect(-> spy.getCall(0).should.have.thrown("TypeError")).to.throw(AssertionError)
-
- it "should throw an assertion error if the spy throws the wrong type of error", ->
- spy = sinon.spy.create(-> throw new Error("boo!"))
-
- swallow(spy)
-
- expect(-> spy.should.have.thrown("TypeError")).to.throw(AssertionError)
- expect(-> spy.getCall(0).should.have.thrown("TypeError")).to.throw(AssertionError)
-
- it "should not throw if the spy throws the correct type of error", ->
- spy = sinon.spy.create(-> throw new TypeError("eek!"))
-
- swallow(spy)
-
- expect(-> spy.should.have.thrown("TypeError")).to.not.throw()
- expect(-> spy.getCall(0).should.have.thrown("TypeError")).to.not.throw()
-
- it "should not throw if the spy throws once but not the next time", ->
- spy = sinon.spy.create(-> throw error unless spy.callCount > 1)
-
- swallow(spy)
- swallow(spy)
-
- expect(-> spy.should.have.thrown("TypeError")).to.not.throw()
- expect(-> spy.getCall(0).should.have.thrown("TypeError")).to.not.throw()
-
- describe "always thrown", ->
- error = null
-
- beforeEach ->
- error = new TypeError("boo!")
-
- it "should throw an assertion error if the spy throws once but not the next time", ->
- spy = sinon.spy.create(-> throw error unless spy.callCount > 1)
-
- swallow(spy)
- swallow(spy)
-
- expect(-> spy.should.have.always.thrown()).to.throw(AssertionError)
- expect(-> spy.should.always.have.thrown()).to.throw(AssertionError)
- expect(-> spy.should.have.always.thrown(error)).to.throw(AssertionError)
- expect(-> spy.should.always.have.thrown(error)).to.throw(AssertionError)
- expect(-> spy.should.have.always.thrown("TypeError")).to.throw(AssertionError)
- expect(-> spy.should.always.have.thrown("TypeError")).to.throw(AssertionError)
-
- it "should throw an assertion error if the spy throws the wrong error the second time", ->
- spy = sinon.spy.create(-> if spy.callCount is 1 then throw error else throw new Error())
-
- swallow(spy)
- swallow(spy)
-
- expect(-> spy.should.have.always.thrown(error)).to.throw(AssertionError)
- expect(-> spy.should.always.have.thrown(error)).to.throw(AssertionError)
- expect(-> spy.should.have.always.thrown("TypeError")).to.throw(AssertionError)
- expect(-> spy.should.always.have.thrown("TypeError")).to.throw(AssertionError)
-
- it "should not throw if the spy always throws the right error", ->
- spy = sinon.spy.create(-> throw error)
-
- swallow(spy)
- swallow(spy)
-
- expect(-> spy.should.have.always.thrown(error)).to.not.throw()
- expect(-> spy.should.always.have.thrown(error)).to.not.throw()
- expect(-> spy.should.have.always.thrown("TypeError")).to.not.throw()
- expect(-> spy.should.always.have.thrown("TypeError")).to.not.throw()
Please sign in to comment.
Something went wrong with that request. Please try again.