From d22af3a936776ba22d358a1777046d81b4f87480 Mon Sep 17 00:00:00 2001 From: William Harris Date: Wed, 24 Apr 2013 13:41:19 -0500 Subject: [PATCH 1/6] add a body tag to jasmine Evn.html for jasmine loadFixtures jasmine.Fixtures.prototype.createContainer_ = function(html) in lib/jasmine-jquery.js assumes there is a body tag to append html to --- src/main/resources/jasmineEnv.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/resources/jasmineEnv.html b/src/main/resources/jasmineEnv.html index 2833b35..db0c5de 100644 --- a/src/main/resources/jasmineEnv.html +++ b/src/main/resources/jasmineEnv.html @@ -1,3 +1,5 @@ + + From 44148f34ea56a025364df5e1c540bedace7b4df6 Mon Sep 17 00:00:00 2001 From: William Harris Date: Wed, 24 Apr 2013 18:15:13 -0500 Subject: [PATCH 2/6] remove the jquery jasmine dependency its easy to add it to an individual project by adding a line like EnvJasmine.loadGlobal(EnvJasmine.testDir + "lib/jasmine-jquery.js"); to you test.dependencies.js not needed in the plugin though --- .../jasmine-jquery/jasmine-jquery-1.2.0.js | 288 ------------------ .../jasmine-jquery/jasmine-jquery.js | 288 ------------------ src/main/resources/jasmineEnv.js | 1 - src/main/resources/sbtjasmine.js | 1 - 4 files changed, 578 deletions(-) delete mode 100644 src/main/resources/jasmine-jquery/jasmine-jquery-1.2.0.js delete mode 100644 src/main/resources/jasmine-jquery/jasmine-jquery.js diff --git a/src/main/resources/jasmine-jquery/jasmine-jquery-1.2.0.js b/src/main/resources/jasmine-jquery/jasmine-jquery-1.2.0.js deleted file mode 100644 index e41001b..0000000 --- a/src/main/resources/jasmine-jquery/jasmine-jquery-1.2.0.js +++ /dev/null @@ -1,288 +0,0 @@ -var readFixtures = function() { - return jasmine.getFixtures().proxyCallTo_('read', arguments); -}; - -var preloadFixtures = function() { - jasmine.getFixtures().proxyCallTo_('preload', arguments); -}; - -var loadFixtures = function() { - jasmine.getFixtures().proxyCallTo_('load', arguments); -}; - -var setFixtures = function(html) { - jasmine.getFixtures().set(html); -}; - -var sandbox = function(attributes) { - return jasmine.getFixtures().sandbox(attributes); -}; - -var spyOnEvent = function(selector, eventName) { - jasmine.JQuery.events.spyOn(selector, eventName); -} - -jasmine.getFixtures = function() { - return jasmine.currentFixtures_ = jasmine.currentFixtures_ || new jasmine.Fixtures(); -}; - -jasmine.Fixtures = function() { - this.containerId = 'jasmine-fixtures'; - this.fixturesCache_ = {}; - this.fixturesPath = 'spec/javascripts/fixtures'; -}; - -jasmine.Fixtures.prototype.set = function(html) { - this.cleanUp(); - this.createContainer_(html); -}; - -jasmine.Fixtures.prototype.preload = function() { - this.read.apply(this, arguments); -}; - -jasmine.Fixtures.prototype.load = function() { - this.cleanUp(); - this.createContainer_(this.read.apply(this, arguments)); -}; - -jasmine.Fixtures.prototype.read = function() { - var htmlChunks = []; - - var fixtureUrls = arguments; - for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) { - htmlChunks.push(this.getFixtureHtml_(fixtureUrls[urlIndex])); - } - - return htmlChunks.join(''); -}; - -jasmine.Fixtures.prototype.clearCache = function() { - this.fixturesCache_ = {}; -}; - -jasmine.Fixtures.prototype.cleanUp = function() { - jQuery('#' + this.containerId).remove(); -}; - -jasmine.Fixtures.prototype.sandbox = function(attributes) { - var attributesToSet = attributes || {}; - return jQuery('
').attr(attributesToSet); -}; - -jasmine.Fixtures.prototype.createContainer_ = function(html) { - var container; - if(html instanceof jQuery) { - container = jQuery('
'); - container.html(html); - } else { - container = '
' + html + '
' - } - jQuery('body').append(container); -}; - -jasmine.Fixtures.prototype.getFixtureHtml_ = function(url) { - if (typeof this.fixturesCache_[url] == 'undefined') { - this.loadFixtureIntoCache_(url); - } - return this.fixturesCache_[url]; -}; - -jasmine.Fixtures.prototype.loadFixtureIntoCache_ = function(relativeUrl) { - var self = this; - var url = this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl; - jQuery.ajax({ - async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded - cache: false, - dataType: 'html', - url: url, - success: function(data) { - self.fixturesCache_[relativeUrl] = data; - }, - error: function(jqXHR, status, errorThrown) { - throw Error('Fixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + errorThrown.message + ')'); - } - }); -}; - -jasmine.Fixtures.prototype.proxyCallTo_ = function(methodName, passedArguments) { - return this[methodName].apply(this, passedArguments); -}; - - -jasmine.JQuery = function() {}; - -jasmine.JQuery.browserTagCaseIndependentHtml = function(html) { - return jQuery('
').append(html).html(); -}; - -jasmine.JQuery.elementToString = function(element) { - return jQuery('
').append(element.clone()).html(); -}; - -jasmine.JQuery.matchersClass = {}; - -(function(namespace) { - var data = { - spiedEvents: {}, - handlers: [] - }; - - namespace.events = { - spyOn: function(selector, eventName) { - var handler = function(e) { - data.spiedEvents[[selector, eventName]] = e; - }; - jQuery(selector).bind(eventName, handler); - data.handlers.push(handler); - }, - - wasTriggered: function(selector, eventName) { - return !!(data.spiedEvents[[selector, eventName]]); - }, - - cleanUp: function() { - data.spiedEvents = {}; - data.handlers = []; - } - } -})(jasmine.JQuery); - -(function(){ - var jQueryMatchers = { - toHaveClass: function(className) { - return this.actual.hasClass(className); - }, - - toBeVisible: function() { - return this.actual.is(':visible'); - }, - - toBeHidden: function() { - return this.actual.is(':hidden'); - }, - - toBeSelected: function() { - return this.actual.is(':selected'); - }, - - toBeChecked: function() { - return this.actual.is(':checked'); - }, - - toBeEmpty: function() { - return this.actual.is(':empty'); - }, - - toExist: function() { - return this.actual.size() > 0; - }, - - toHaveAttr: function(attributeName, expectedAttributeValue) { - return hasProperty(this.actual.attr(attributeName), expectedAttributeValue); - }, - - toHaveId: function(id) { - return this.actual.attr('id') == id; - }, - - toHaveHtml: function(html) { - return this.actual.html() == jasmine.JQuery.browserTagCaseIndependentHtml(html); - }, - - toHaveText: function(text) { - if (text && jQuery.isFunction(text.test)) { - return text.test(this.actual.text()); - } else { - return this.actual.text() == text; - } - }, - - toHaveValue: function(value) { - return this.actual.val() == value; - }, - - toHaveData: function(key, expectedValue) { - return hasProperty(this.actual.data(key), expectedValue); - }, - - toBe: function(selector) { - return this.actual.is(selector); - }, - - toContain: function(selector) { - return this.actual.find(selector).size() > 0; - }, - - toBeDisabled: function(selector){ - return this.actual.is(':disabled'); - }, - - // tests the existence of a specific event binding - toHandle: function(eventName) { - var events = this.actual.data("events"); - return events && events[eventName].length > 0; - }, - - // tests the existence of a specific event binding + handler - toHandleWith: function(eventName, eventHandler) { - var stack = this.actual.data("events")[eventName]; - var i; - for (i = 0; i < stack.length; i++) { - if (stack[i].handler == eventHandler) { - return true; - } - } - return false; - } - }; - - var hasProperty = function(actualValue, expectedValue) { - if (expectedValue === undefined) { - return actualValue !== undefined; - } - return actualValue == expectedValue; - }; - - var bindMatcher = function(methodName) { - var builtInMatcher = jasmine.Matchers.prototype[methodName]; - - jasmine.JQuery.matchersClass[methodName] = function() { - if (this.actual instanceof jQuery) { - var result = jQueryMatchers[methodName].apply(this, arguments); - this.actual = jasmine.JQuery.elementToString(this.actual); - return result; - } - - if (builtInMatcher) { - return builtInMatcher.apply(this, arguments); - } - - return false; - }; - }; - - for(var methodName in jQueryMatchers) { - bindMatcher(methodName); - } -})(); - -beforeEach(function() { - this.addMatchers(jasmine.JQuery.matchersClass); - this.addMatchers({ - toHaveBeenTriggeredOn: function(selector) { - this.message = function() { - return [ - "Expected event " + this.actual + " to have been triggered on" + selector, - "Expected event " + this.actual + " not to have been triggered on" + selector - ]; - }; - return jasmine.JQuery.events.wasTriggered(selector, this.actual); - } - }) -}); - -afterEach(function() { - jasmine.getFixtures().cleanUp(); - jasmine.JQuery.events.cleanUp(); -}); \ No newline at end of file diff --git a/src/main/resources/jasmine-jquery/jasmine-jquery.js b/src/main/resources/jasmine-jquery/jasmine-jquery.js deleted file mode 100644 index e41001b..0000000 --- a/src/main/resources/jasmine-jquery/jasmine-jquery.js +++ /dev/null @@ -1,288 +0,0 @@ -var readFixtures = function() { - return jasmine.getFixtures().proxyCallTo_('read', arguments); -}; - -var preloadFixtures = function() { - jasmine.getFixtures().proxyCallTo_('preload', arguments); -}; - -var loadFixtures = function() { - jasmine.getFixtures().proxyCallTo_('load', arguments); -}; - -var setFixtures = function(html) { - jasmine.getFixtures().set(html); -}; - -var sandbox = function(attributes) { - return jasmine.getFixtures().sandbox(attributes); -}; - -var spyOnEvent = function(selector, eventName) { - jasmine.JQuery.events.spyOn(selector, eventName); -} - -jasmine.getFixtures = function() { - return jasmine.currentFixtures_ = jasmine.currentFixtures_ || new jasmine.Fixtures(); -}; - -jasmine.Fixtures = function() { - this.containerId = 'jasmine-fixtures'; - this.fixturesCache_ = {}; - this.fixturesPath = 'spec/javascripts/fixtures'; -}; - -jasmine.Fixtures.prototype.set = function(html) { - this.cleanUp(); - this.createContainer_(html); -}; - -jasmine.Fixtures.prototype.preload = function() { - this.read.apply(this, arguments); -}; - -jasmine.Fixtures.prototype.load = function() { - this.cleanUp(); - this.createContainer_(this.read.apply(this, arguments)); -}; - -jasmine.Fixtures.prototype.read = function() { - var htmlChunks = []; - - var fixtureUrls = arguments; - for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) { - htmlChunks.push(this.getFixtureHtml_(fixtureUrls[urlIndex])); - } - - return htmlChunks.join(''); -}; - -jasmine.Fixtures.prototype.clearCache = function() { - this.fixturesCache_ = {}; -}; - -jasmine.Fixtures.prototype.cleanUp = function() { - jQuery('#' + this.containerId).remove(); -}; - -jasmine.Fixtures.prototype.sandbox = function(attributes) { - var attributesToSet = attributes || {}; - return jQuery('
').attr(attributesToSet); -}; - -jasmine.Fixtures.prototype.createContainer_ = function(html) { - var container; - if(html instanceof jQuery) { - container = jQuery('
'); - container.html(html); - } else { - container = '
' + html + '
' - } - jQuery('body').append(container); -}; - -jasmine.Fixtures.prototype.getFixtureHtml_ = function(url) { - if (typeof this.fixturesCache_[url] == 'undefined') { - this.loadFixtureIntoCache_(url); - } - return this.fixturesCache_[url]; -}; - -jasmine.Fixtures.prototype.loadFixtureIntoCache_ = function(relativeUrl) { - var self = this; - var url = this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl; - jQuery.ajax({ - async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded - cache: false, - dataType: 'html', - url: url, - success: function(data) { - self.fixturesCache_[relativeUrl] = data; - }, - error: function(jqXHR, status, errorThrown) { - throw Error('Fixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + errorThrown.message + ')'); - } - }); -}; - -jasmine.Fixtures.prototype.proxyCallTo_ = function(methodName, passedArguments) { - return this[methodName].apply(this, passedArguments); -}; - - -jasmine.JQuery = function() {}; - -jasmine.JQuery.browserTagCaseIndependentHtml = function(html) { - return jQuery('
').append(html).html(); -}; - -jasmine.JQuery.elementToString = function(element) { - return jQuery('
').append(element.clone()).html(); -}; - -jasmine.JQuery.matchersClass = {}; - -(function(namespace) { - var data = { - spiedEvents: {}, - handlers: [] - }; - - namespace.events = { - spyOn: function(selector, eventName) { - var handler = function(e) { - data.spiedEvents[[selector, eventName]] = e; - }; - jQuery(selector).bind(eventName, handler); - data.handlers.push(handler); - }, - - wasTriggered: function(selector, eventName) { - return !!(data.spiedEvents[[selector, eventName]]); - }, - - cleanUp: function() { - data.spiedEvents = {}; - data.handlers = []; - } - } -})(jasmine.JQuery); - -(function(){ - var jQueryMatchers = { - toHaveClass: function(className) { - return this.actual.hasClass(className); - }, - - toBeVisible: function() { - return this.actual.is(':visible'); - }, - - toBeHidden: function() { - return this.actual.is(':hidden'); - }, - - toBeSelected: function() { - return this.actual.is(':selected'); - }, - - toBeChecked: function() { - return this.actual.is(':checked'); - }, - - toBeEmpty: function() { - return this.actual.is(':empty'); - }, - - toExist: function() { - return this.actual.size() > 0; - }, - - toHaveAttr: function(attributeName, expectedAttributeValue) { - return hasProperty(this.actual.attr(attributeName), expectedAttributeValue); - }, - - toHaveId: function(id) { - return this.actual.attr('id') == id; - }, - - toHaveHtml: function(html) { - return this.actual.html() == jasmine.JQuery.browserTagCaseIndependentHtml(html); - }, - - toHaveText: function(text) { - if (text && jQuery.isFunction(text.test)) { - return text.test(this.actual.text()); - } else { - return this.actual.text() == text; - } - }, - - toHaveValue: function(value) { - return this.actual.val() == value; - }, - - toHaveData: function(key, expectedValue) { - return hasProperty(this.actual.data(key), expectedValue); - }, - - toBe: function(selector) { - return this.actual.is(selector); - }, - - toContain: function(selector) { - return this.actual.find(selector).size() > 0; - }, - - toBeDisabled: function(selector){ - return this.actual.is(':disabled'); - }, - - // tests the existence of a specific event binding - toHandle: function(eventName) { - var events = this.actual.data("events"); - return events && events[eventName].length > 0; - }, - - // tests the existence of a specific event binding + handler - toHandleWith: function(eventName, eventHandler) { - var stack = this.actual.data("events")[eventName]; - var i; - for (i = 0; i < stack.length; i++) { - if (stack[i].handler == eventHandler) { - return true; - } - } - return false; - } - }; - - var hasProperty = function(actualValue, expectedValue) { - if (expectedValue === undefined) { - return actualValue !== undefined; - } - return actualValue == expectedValue; - }; - - var bindMatcher = function(methodName) { - var builtInMatcher = jasmine.Matchers.prototype[methodName]; - - jasmine.JQuery.matchersClass[methodName] = function() { - if (this.actual instanceof jQuery) { - var result = jQueryMatchers[methodName].apply(this, arguments); - this.actual = jasmine.JQuery.elementToString(this.actual); - return result; - } - - if (builtInMatcher) { - return builtInMatcher.apply(this, arguments); - } - - return false; - }; - }; - - for(var methodName in jQueryMatchers) { - bindMatcher(methodName); - } -})(); - -beforeEach(function() { - this.addMatchers(jasmine.JQuery.matchersClass); - this.addMatchers({ - toHaveBeenTriggeredOn: function(selector) { - this.message = function() { - return [ - "Expected event " + this.actual + " to have been triggered on" + selector, - "Expected event " + this.actual + " not to have been triggered on" + selector - ]; - }; - return jasmine.JQuery.events.wasTriggered(selector, this.actual); - } - }) -}); - -afterEach(function() { - jasmine.getFixtures().cleanUp(); - jasmine.JQuery.events.cleanUp(); -}); \ No newline at end of file diff --git a/src/main/resources/jasmineEnv.js b/src/main/resources/jasmineEnv.js index d5da72c..9db2f70 100644 --- a/src/main/resources/jasmineEnv.js +++ b/src/main/resources/jasmineEnv.js @@ -4,5 +4,4 @@ EnvJasmine.loadLibGlobal("rjs/r-2.0.1.js"); EnvJasmine.loadLibGlobal("envjs/env.rhino.1.2.js"); EnvJasmine.loadLibGlobal("jasmine/jasmine.js"); -EnvJasmine.loadLibGlobal("jasmine-jquery/jasmine-jquery-1.2.0.js"); EnvJasmine.loadLibGlobal("jasmine-rhino-reporter/jasmine-rhino-reporter.js"); diff --git a/src/main/resources/sbtjasmine.js b/src/main/resources/sbtjasmine.js index 6168870..f28ae11 100644 --- a/src/main/resources/sbtjasmine.js +++ b/src/main/resources/sbtjasmine.js @@ -8,7 +8,6 @@ http://www.mozilla.org/rhino/ http://www.envjs.com/ http://pivotal.github.com/jasmine/ - https://github.com/velesin/jasmine-jquery */ importPackage(java.lang); From 3598e5c05928e36735ceb6ec03a85343b7eb691e Mon Sep 17 00:00:00 2001 From: Joe Barnes Date: Fri, 10 Jan 2014 09:53:17 -0600 Subject: [PATCH 3/6] Bumped rhino to the latest (1.7.R4). Specifying the scala version to 2.9.2 --- build.sbt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index fcffb7b..c01d3a7 100644 --- a/build.sbt +++ b/build.sbt @@ -6,11 +6,15 @@ organization := "com.gu" version := "0.8-SNAPSHOT" -libraryDependencies += "org.mozilla" % "rhino" % "1.7R3" +libraryDependencies += "org.mozilla" % "rhino" % "1.7R4" // don't bother publishing javadoc publishArtifact in (Compile, packageDoc) := false +scalaVersion := "2.9.2" + +scalacOptions ++= Seq("-unchecked", "-deprecation") + publishTo <<= (version) { version: String => val publishType = if (version.endsWith("SNAPSHOT")) "snapshots" else "releases" Some( From 7e8d5451d24a1d211f7d2c3da63ffa0df1b29a04 Mon Sep 17 00:00:00 2001 From: Joe Barnes Date: Fri, 10 Jan 2014 10:01:27 -0600 Subject: [PATCH 4/6] Adding build.properties in order to explicitly set the sbt version to 0.12.4 --- project/build.properties | 1 + 1 file changed, 1 insertion(+) create mode 100644 project/build.properties diff --git a/project/build.properties b/project/build.properties new file mode 100644 index 0000000..f069b10 --- /dev/null +++ b/project/build.properties @@ -0,0 +1 @@ +sbt.version=0.12.4 \ No newline at end of file From 4691daba78e5ff77da9d57e7318fc4955bf072cf Mon Sep 17 00:00:00 2001 From: Joe Barnes Date: Fri, 10 Jan 2014 10:57:15 -0600 Subject: [PATCH 5/6] Hack into env.js to implement in in order to support unit testing of angular.js applications. Resolves issue #17 --- src/main/resources/envjs/env.rhino.1.2.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/resources/envjs/env.rhino.1.2.js b/src/main/resources/envjs/env.rhino.1.2.js index cae7be8..8139596 100755 --- a/src/main/resources/envjs/env.rhino.1.2.js +++ b/src/main/resources/envjs/env.rhino.1.2.js @@ -8115,6 +8115,15 @@ __extend__(HTMLAnchorElement.prototype, { set name(val) { this.setAttribute("name",val); }, + get pathname() { + var uri = Envjs.urlsplit(this.href); + return uri.path; + }, + set pathname(val) { + var uri = Envjs.urlsplit(this.href); + uri.path = val + this.href(uri.urlunsplit(uri)); + }, get rel() { return this.getAttribute("rel")||''; }, From bbc4f3125aee0681d7e2355e8152410d0fa28e0d Mon Sep 17 00:00:00 2001 From: Joe Barnes Date: Sun, 2 Feb 2014 12:01:34 -0600 Subject: [PATCH 6/6] Pointing to the new home at barnesjd --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 85dc976..92ed9cc 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -**This plugin is no-longer being actively maintained by the Guardian** +**This plugin is no-longer being actively maintained by the Guardian. Please see visit its [new home](https://github.com/barnesjd/sbt-jasmine-plugin)** ----------------------------------------------------------------