Skip to content
Browse files

Separate repository for sinon-qunit adapter

  • Loading branch information...
0 parents commit 731c236350d0401e757b3a67785958c33d47e181 @cjohansen committed Dec 6, 2010
Showing with 341 additions and 0 deletions.
  1. +3 −0 .gitmodules
  2. +2 −0 AUTHORS
  3. +2 −0 Changelog.txt
  4. +27 −0 LICENSE
  5. +61 −0 build
  6. +1 −0 deps/sinon
  7. +17 −0 jsTestDriver.conf
  8. +30 −0 lib/sinon-qunit.js
  9. +22 −0 package.json
  10. +64 −0 pkg/sinon-qunit-1.0.0.js
  11. +25 −0 test/helper.js
  12. +6 −0 test/plugin-setup.js
  13. +81 −0 test/sinon-qunit-test.js
3 .gitmodules
@@ -0,0 +1,3 @@
+[submodule "deps/sinon"]
+ path = deps/sinon
+ url = git@github.com:cjohansen/Sinon.JS.git
2 AUTHORS
@@ -0,0 +1,2 @@
+Sinon-QUnit was written by
+Christian Johansen, christian@cjohansen.no
2 Changelog.txt
@@ -0,0 +1,2 @@
+== 1.0.0 / 2010-12-06
+* Initial release
27 LICENSE
@@ -0,0 +1,27 @@
+(The BSD License)
+
+Copyright (c) 2010-2011, Christian Johansen, christian@cjohansen.no
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of Christian Johansen nor the names of his contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 build
@@ -0,0 +1,61 @@
+#!/usr/bin/env ruby
+require "fileutils"
+require "pathname"
+
+def add_license(file, version)
+ contents = File.read(file)
+ copyright = Time.now.year == 2010 ? "2010" : "2010-#{Time.now.year}"
+
+ File.open(file, "w") do |f|
+ f.puts <<PREAMBLE
+/**
+ * sinon-qunit #{version}, #{Time.now.strftime("%Y/%m/%d")}
+ *
+ * @author Christian Johansen (christian@cjohansen.no)
+ *
+ * (The BSD License)
+ *
+ * Copyright (c) #{copyright}, Christian Johansen, christian@cjohansen.no
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of Christian Johansen nor the names of his contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+PREAMBLE
+
+ f.puts(contents)
+ end
+end
+
+Dir.chdir(File.dirname(__FILE__)) do
+ version = File.read("package.json").match(/"version":\s+"(.*)"/)[1]
+ version_string = ARGV[0] == "plain" ? "" : "-#{version}"
+ output = "pkg/sinon-qunit#{version_string}.js"
+
+ FileUtils.mkdir("pkg") unless File.exists?("pkg")
+ FileUtils.cp("lib/sinon-qunit.js", "pkg/sinon-qunit#{version_string}.js")
+ add_license("pkg/sinon-qunit#{version_string}.js", version)
+
+ puts "Built sinon-qunit #{version}"
+end
1 deps/sinon
@@ -0,0 +1 @@
+Subproject commit 8f75b12c84c98fdefa8375b4df3bfe5ae1830fa6
17 jsTestDriver.conf
@@ -0,0 +1,17 @@
+server: http://localhost:4224
+
+load:
+ - deps/sinon/lib/sinon.js
+ - deps/sinon/lib/sinon/spy.js
+ - deps/sinon/lib/sinon/stub.js
+ - deps/sinon/lib/sinon/collection.js
+ - deps/sinon/lib/sinon/*.js
+ - deps/sinon/lib/sinon/util/fake_timers.js
+ - deps/sinon/lib/sinon/util/fake_xml_http_request.js
+ - deps/sinon/lib/sinon/util/timers_ie.js
+ - deps/sinon/lib/sinon/util/xhr_ie.js
+ - deps/sinon/lib/sinon/util/*.js
+ - test/plugin-setup.js
+ - lib/*.js
+ - test/helper.js
+ - test/*.js
30 lib/sinon-qunit.js
@@ -0,0 +1,30 @@
+/*jslint indent: 2*/
+/*global sinon, QUnit, test*/
+sinon.assert.fail = function (msg) {
+ QUnit.ok(false, msg);
+};
+
+sinon.assert.pass = function (assertion) {
+ QUnit.ok(true, assertion);
+};
+
+sinon.config = {
+ injectIntoThis: true,
+ injectInto: null,
+ properties: ["spy", "stub", "mock", "clock", "sandbox"],
+ useFakeTimers: true,
+ useFakeServer: false
+};
+
+(function () {
+ var qTest = QUnit.test;
+
+ QUnit.test = test = function (testName, expected, callback, async) {
+ if (arguments.length === 2) {
+ callback = expected;
+ expected = null;
+ }
+
+ return qTest(testName, expected, sinon.test(callback), async);
+ };
+}());
22 package.json
@@ -0,0 +1,22 @@
+{
+ "name": "sinon-qunit",
+ "description": "QUnit adapter for Sinon.JS: JavaScript test spies, stubs and mocks.",
+ "version": "1.0.0",
+ "homepage": "http://cjohansen.no/sinon/sinon-qunit/",
+ "author": "Christian Johansen",
+ "repository": {
+ "type": "git",
+ "url": "http://github.com/cjohansen/sinon-qunit.git"
+ },
+ "bugs": {
+ "mail": "christian@cjohansen.no",
+ "web": "http://github.com/cjohansen/sinon-qunit/issues"
+ },
+ "licenses": [
+ { "type": "BSD",
+ "url": "http://github.com/cjohansen/sinon-qunit/blob/master/LICENSE",
+ }
+ ],
+ "main": "./lib/sinon-qunit.js",
+ "engines": { "node": ">=0.1.103" }
+}
64 pkg/sinon-qunit-1.0.0.js
@@ -0,0 +1,64 @@
+/**
+ * Sinon.JS 1.0.0, 2010/12/06
+ *
+ * @author Christian Johansen (christian@cjohansen.no)
+ *
+ * (The BSD License)
+ *
+ * Copyright (c) 2010, Christian Johansen, christian@cjohansen.no
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of Christian Johansen nor the names of his contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+/*jslint indent: 2*/
+/*global sinon, QUnit, test*/
+sinon.assert.fail = function (msg) {
+ QUnit.ok(false, msg);
+};
+
+sinon.assert.pass = function (assertion) {
+ QUnit.ok(true, assertion);
+};
+
+sinon.config = {
+ injectIntoThis: true,
+ injectInto: null,
+ properties: ["spy", "stub", "mock", "clock", "sandbox"],
+ useFakeTimers: true,
+ useFakeServer: false
+};
+
+(function () {
+ var qTest = QUnit.test;
+
+ QUnit.test = test = function (testName, expected, callback, async) {
+ if (arguments.length === 2) {
+ callback = expected;
+ expected = null;
+ }
+
+ return qTest(testName, expected, sinon.test(callback), async);
+ };
+}());
25 test/helper.js
@@ -0,0 +1,25 @@
+/*jslint indent: 2, onevar: false, eqeqeq: false*/
+/*global TestCase*/
+/**
+ * @author Christian Johansen (christian@cjohansen.no)
+ * @license BSD
+ *
+ * Copyright (c) 2010 Christian Johansen
+ */
+function testCase(name, tests) {
+ var jstdCase = {};
+ var jstdTestCase = TestCase; // Silence JsLint...
+
+ for (var prop in tests) {
+ if (tests.hasOwnProperty(prop)) {
+ if (!/(^(setUp|tearDown)$)|^test/.test(prop) &&
+ typeof tests[prop] == "function") {
+ jstdCase["test " + prop] = tests[prop];
+ } else {
+ jstdCase[prop] = tests[prop];
+ }
+ }
+ }
+
+ jstdTestCase(name, jstdCase);
+}
6 test/plugin-setup.js
@@ -0,0 +1,6 @@
+var QUnit = {
+ ok: function () {},
+ test: sinon.spy()
+};
+
+QUnit.originalTest = QUnit.test;
81 test/sinon-qunit-test.js
@@ -0,0 +1,81 @@
+testCase("SinonQUnitTest", {
+ setUp: function () {
+ sinon.spy(QUnit, "ok");
+ },
+
+ tearDown: function () {
+ if (sinon.test.restore) {
+ sinon.test.restore();
+ }
+
+ QUnit.originalTest.callCount = 0;
+ QUnit.originalTest.args = [];
+ QUnit.ok.restore();
+ },
+
+ "should fail through ok": function () {
+ sinon.assert.fail("Uh-oh!");
+
+ assert(QUnit.ok.calledOnce);
+ assert(QUnit.ok.calledWithExactly(false, "Uh-oh!"));
+ },
+
+ "should pass through ok": function () {
+ sinon.assert.pass("calledOnce");
+
+ assert(QUnit.ok.calledOnce);
+ assert(QUnit.ok.calledWithExactly(true, "calledOnce"));
+ },
+
+ "should pass callback to sinon.test": function () {
+ sinon.spy(sinon, "test");
+ var func = function () {};
+ test("Test", func);
+
+ assert(sinon.test.calledOnce);
+ assert(sinon.test.calledWith(func));
+ },
+
+ "should pass name and sandboxed callback to QUnit": function () {
+ var sandboxed = function () {};
+ sinon.stub(sinon, "test").returns(sandboxed);
+ QUnit.test("Test", function () {});
+
+ assert(QUnit.originalTest.calledOnce);
+ assert(QUnit.originalTest.calledWith("Test", null, sandboxed, undefined));
+ },
+
+ "should pass name, expected and sandboxed callback to QUnit": function () {
+ var sandboxed = function () {};
+ sinon.stub(sinon, "test").returns(sandboxed);
+ QUnit.test("Test This", 23, function () {});
+
+ assert(QUnit.originalTest.calledWith("Test This", 23, sandboxed, undefined));
+ },
+
+ "should pass name, env and sandboxed callback to QUnit": function () {
+ var sandboxed = function () {};
+ var env = { id: 42 };
+ sinon.stub(sinon, "test").returns(sandboxed);
+ QUnit.test("Test This", env, function () {});
+
+ assert(QUnit.originalTest.calledWith("Test This", env, sandboxed, undefined));
+ },
+
+ "should pass name, env, sandboxed callback and async to QUnit": function () {
+ var sandboxed = function () {};
+ var env = { id: 42 };
+ sinon.stub(sinon, "test").returns(sandboxed);
+ QUnit.test("Test This", env, function () {}, true);
+
+ assert(QUnit.originalTest.calledWith("Test This", env, sandboxed, true));
+ },
+
+ "should pass name, expected, sandboxed callback and async to QUnit": function () {
+ var sandboxed = function () {};
+ sinon.stub(sinon, "test").returns(sandboxed);
+ QUnit.test("Test This", 42, function () {}, true);
+
+ assert(QUnit.originalTest.calledWith("Test This", 42, sandboxed, true));
+ }
+});

0 comments on commit 731c236

Please sign in to comment.
Something went wrong with that request. Please try again.