Permalink
Browse files

Move most jasmine global usage into boot.

- thor build scripts broken for now.
  • Loading branch information...
1 parent b6c3999 commit e2af08e0a68b1090bd05c55fb9b0969198eb330a Davis W. Frank & Rajan Agaskar committed Dec 3, 2012
View
@@ -1,11 +1,12 @@
source :rubygems
gem "rake"
-gem "jasmine", git: 'https://github.com/pivotal/jasmine-gem.git'
+#gem "jasmine", git: 'https://github.com/pivotal/jasmine-gem.git'
+gem "jasmine", path: '~/workspace/jasmine-gem'
unless ENV["TRAVIS"]
group :debug do
gem 'debugger'
end
end
-
+
gemspec
View
@@ -23,6 +23,14 @@ def node_spec_files
spec_files("node")
end
+ def boot_files
+ ["boot.js"]
+ end
+
+ def boot_dir
+ File.join(path, 'boot')
+ end
+
def spec_files(type)
raise ArgumentError.new("Unrecognized spec type") unless SPEC_TYPES.include?(type)
(Dir.glob(File.join(path, "spec", type, "*.js"))).map { |f| File.join("spec", type, File.basename(f)) }.uniq
@@ -0,0 +1,75 @@
+(function() {
+ var env = jasmine.getEnv();
+
+ var jasmineInterface = {
+ describe: function(description, specDefinitions) {
+ return env.describe(description, specDefinitions);
+ },
+
+ xdescribe: function(description, specDefinitions) {
+ return env.xdescribe(description, specDefinitions);
+ },
+
+ it: function(desc, func) {
+ return env.it(desc, func);
+ },
+
+ xit: function(desc, func) {
+ return env.xit(desc, func);
+ },
+
+ beforeEach: function(beforeEachFunction) {
+ return env.beforeEach(beforeEachFunction);
+ },
+
+ afterEach: function(afterEachFunction) {
+ return env.afterEach(afterEachFunction);
+ },
+
+ expect: function(actual) {
+ return env.currentSpec.expect(actual);
+ },
+
+ runs: function(func) {
+ return env.currentSpec.runs(func);
+ },
+
+ waits: function(timeout) {
+ return env.currentSpec.waits(timeout);
+ },
+
+ waitsFor: function(latchFunction, optional_timeoutMessage, optional_timeout) {
+ return env.currentSpec.waitsFor.apply(jasmine.getEnv().currentSpec, arguments);
+ },
+
+ spyOn: function(obj, methodName) {
+ return env.currentSpec.spyOn(obj, methodName);
+ },
+ jsApiReporter: new jasmine.JsApiReporter()
+ };
+
+ if (typeof window == "undefined" && typeof exports == "object") {
+ jasmine.util.extend(exports, jasmineInterface);
+ } else {
+ jasmine.util.extend(window, jasmineInterface);
+ }
+
+ var htmlReporter = new jasmine.HtmlReporter();
+
+ env.addReporter(jasmineInterface.jsApiReporter);
+ env.addReporter(htmlReporter);
+
+ env.specFilter = function(spec) {
+ return htmlReporter.specFilter(spec);
+ };
+
+ var currentWindowOnload = window.onload;
+
+ window.onload = function() {
+ if (currentWindowOnload) {
+ currentWindowOnload();
+ }
+ env.execute();
+ };
+
+}());
View
@@ -1,12 +1,11 @@
-var isCommonJS = typeof window == "undefined" && typeof exports == "object";
/**
* Top level namespace for Jasmine, a lightweight JavaScript BDD/spec/testing framework.
*
* @namespace
*/
var jasmine = {};
-if (isCommonJS) exports.jasmine = jasmine;
+
/**
* @private
*/
@@ -128,6 +127,7 @@ jasmine.ExpectationResult.prototype.passed = function () {
*/
jasmine.getEnv = function() {
var env = jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env();
+ //jasmine. singletons in here (setTimeout blah blah).
return env;
};
@@ -462,160 +462,6 @@ jasmine.log = function() {
spec.log.apply(spec, arguments);
};
-/**
- * Function that installs a spy on an existing object's method name. Used within a Spec to create a spy.
- *
- * @example
- * // spy example
- * var foo = {
- * not: function(bool) { return !bool; }
- * }
- * spyOn(foo, 'not'); // actual foo.not will not be called, execution stops
- *
- * @see jasmine.createSpy
- * @param obj
- * @param methodName
- * @return {jasmine.Spy} a Jasmine spy that can be chained with all spy methods
- */
-var spyOn = function(obj, methodName) {
- return jasmine.getEnv().currentSpec.spyOn(obj, methodName);
-};
-if (isCommonJS) exports.spyOn = spyOn;
-
-/**
- * Creates a Jasmine spec that will be added to the current suite.
- *
- * // TODO: pending tests
- *
- * @example
- * it('should be true', function() {
- * expect(true).toEqual(true);
- * });
- *
- * @param {String} desc description of this specification
- * @param {Function} func defines the preconditions and expectations of the spec
- */
-var it = function(desc, func) {
- return jasmine.getEnv().it(desc, func);
-};
-if (isCommonJS) exports.it = it;
-
-/**
- * Creates a <em>disabled</em> Jasmine spec.
- *
- * A convenience method that allows existing specs to be disabled temporarily during development.
- *
- * @param {String} desc description of this specification
- * @param {Function} func defines the preconditions and expectations of the spec
- */
-var xit = function(desc, func) {
- return jasmine.getEnv().xit(desc, func);
-};
-if (isCommonJS) exports.xit = xit;
-
-/**
- * Starts a chain for a Jasmine expectation.
- *
- * It is passed an Object that is the actual value and should chain to one of the many
- * jasmine.Matchers functions.
- *
- * @param {Object} actual Actual value to test against and expected value
- * @return {jasmine.Matchers}
- */
-var expect = function(actual) {
- return jasmine.getEnv().currentSpec.expect(actual);
-};
-if (isCommonJS) exports.expect = expect;
-
-/**
- * Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs.
- *
- * @param {Function} func Function that defines part of a jasmine spec.
- */
-var runs = function(func) {
- jasmine.getEnv().currentSpec.runs(func);
-};
-if (isCommonJS) exports.runs = runs;
-
-/**
- * Waits a fixed time period before moving to the next block.
- *
- * @deprecated Use waitsFor() instead
- * @param {Number} timeout milliseconds to wait
- */
-var waits = function(timeout) {
- jasmine.getEnv().currentSpec.waits(timeout);
-};
-if (isCommonJS) exports.waits = waits;
-
-/**
- * Waits for the latchFunction to return true before proceeding to the next block.
- *
- * @param {Function} latchFunction
- * @param {String} optional_timeoutMessage
- * @param {Number} optional_timeout
- */
-var waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) {
- jasmine.getEnv().currentSpec.waitsFor.apply(jasmine.getEnv().currentSpec, arguments);
-};
-if (isCommonJS) exports.waitsFor = waitsFor;
-
-/**
- * A function that is called before each spec in a suite.
- *
- * Used for spec setup, including validating assumptions.
- *
- * @param {Function} beforeEachFunction
- */
-var beforeEach = function(beforeEachFunction) {
- jasmine.getEnv().beforeEach(beforeEachFunction);
-};
-if (isCommonJS) exports.beforeEach = beforeEach;
-
-/**
- * A function that is called after each spec in a suite.
- *
- * Used for restoring any state that is hijacked during spec execution.
- *
- * @param {Function} afterEachFunction
- */
-var afterEach = function(afterEachFunction) {
- jasmine.getEnv().afterEach(afterEachFunction);
-};
-if (isCommonJS) exports.afterEach = afterEach;
-
-/**
- * Defines a suite of specifications.
- *
- * Stores the description and all defined specs in the Jasmine environment as one suite of specs. Variables declared
- * are accessible by calls to beforeEach, it, and afterEach. Describe blocks can be nested, allowing for specialization
- * of setup in some tests.
- *
- * @example
- * // TODO: a simple suite
- *
- * // TODO: a simple suite with a nested describe block
- *
- * @param {String} description A string, usually the class under test.
- * @param {Function} specDefinitions function that defines several specs.
- */
-var describe = function(description, specDefinitions) {
- return jasmine.getEnv().describe(description, specDefinitions);
-};
-if (isCommonJS) exports.describe = describe;
-
-/**
- * Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development.
- *
- * @param {String} description A string, usually the class under test.
- * @param {Function} specDefinitions function that defines several specs.
- */
-var xdescribe = function(description, specDefinitions) {
- return jasmine.getEnv().xdescribe(description, specDefinitions);
-};
-if (isCommonJS) exports.xdescribe = xdescribe;
-
-
// Provide the XMLHttpRequest class for IE 5.x-6.x:
jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() {
function tryIt(f) {
View
@@ -7,14 +7,6 @@ describe("base.js", function() {
});
});
- describe("jasmine.log", function() {
- it("should accept n arguments", function() {
- spyOn(jasmine.getEnv().currentSpec, 'log');
- jasmine.log(1, 2, 3);
- expect(jasmine.getEnv().currentSpec.log).toHaveBeenCalledWith(1, 2, 3);
- });
- });
-
describe("jasmine.getGlobal", function() {
it("should return the global object", function() {
var globalObject = (function() {
@@ -65,7 +65,7 @@ describe("Custom Matchers", function() {
actual: true, expected: jasmine.undefined, message: "Passed." });
var failResult = new jasmine.ExpectationResult({passed: false, matcherName: 'toBeTrue',
actual: false, expected: jasmine.undefined, message: "Expected false to be true." });
- failResult.trace = jasmine.any(Object);
+ failResult.trace = originalJasmine.any(Object);
expect(spec.results().getItems()).toEqual([passResult, failResult]);
});
@@ -94,4 +94,4 @@ describe("Custom Matchers", function() {
expect(matcherCallArgs).toEqual([[], ['arg'], ['arg1', 'arg2']]);
});
-});
+});
View
@@ -17,7 +17,7 @@ describe("jasmine.Env", function() {
var fakeReporter;
beforeEach(function() {
- fakeReporter = jasmine.createSpyObj("fakeReporter", ["log"]);
+ fakeReporter = originalJasmine.createSpyObj("fakeReporter", ["log"]);
});
describe('version', function () {
@@ -391,7 +391,7 @@ describe("jasmine.Matchers", function() {
var matcher;
beforeEach(function () {
matcher = {
- jasmineMatches: jasmine.createSpy("jasmineMatches")
+ jasmineMatches: originalJasmine.createSpy("jasmineMatches")
};
});
@@ -694,7 +694,7 @@ describe("jasmine.Matchers", function() {
TestClass = {
normalFunction: function() {
},
- spyFunction: jasmine.createSpy("My spy")
+ spyFunction: originalJasmine.createSpy("My spy")
};
});
@@ -974,7 +974,7 @@ describe("jasmine.Matchers", function() {
describe("in real life", function () {
var method;
beforeEach(function () {
- method = jasmine.createSpy("method");
+ method = originalJasmine.createSpy("method");
method({a:"b", c:"d"});
});
it("works correctly for positive matches", function () {
@@ -1,7 +1,9 @@
-describe("MockClock", function () {
+// TODO: Disabling b/c this spec isn't testing what it thinks it is.
+// Make a proper unit and intergration tests for this object
+xdescribe("MockClock", function () {
beforeEach(function() {
- jasmine.Clock.useMock();
+ jasmine.Clock.useMock();
});
describe("setTimeout", function () {
Oops, something went wrong.

0 comments on commit e2af08e

Please sign in to comment.