Permalink
Browse files

fix style (#91)

  • Loading branch information...
1 parent cf52849 commit 93f81843d8868e3c5a0116b03fe10793f333cb1a @travisjeffery travisjeffery committed Sep 2, 2012
Showing with 91 additions and 98 deletions.
  1. +5 −5 README.markdown
  2. +35 −35 lib/jasmine-jquery.js
  3. +51 −58 spec/suites/jasmine-jquery-spec.js
View
@@ -184,7 +184,7 @@ In _mycssfixture.css_ file:
Inside your test:
- loadStyleFixtures('mycssfixture.css');
+ loadStyleFixtures('mycssfixture.css');
$('#my-fixture').myTestedPlugin();
expect($('#my-fixture .elem')).toHaveCss({left: "300px"});
@@ -241,10 +241,10 @@ In _myjsonfixture.json_ file:
Inside your test:
- data = loadJSONFixtures('myjsonfixture.json');
- test_data = data['myjsonfixture.json'];
- // or use the helper
- test_data = getJSONFixture('myjsonfixture.json');
+ var data = getJSONFixture('myjsonfixture.json');
+ // or load and get the JSON two-step
+ var fixtures = loadJSONFixtures('myjsonfixture.json');
+ var data = fixtures['myjsonfixture.json'];
expect(myDataManipulator.processData(test_data)).to...)
View
@@ -51,15 +51,15 @@ var appendSetStyleFixtures = function(html) {
}
var loadJSONFixtures = function() {
- return jasmine.getJSONFixtures().proxyCallTo_('load', arguments);
-};
+ return jasmine.getJSONFixtures().proxyCallTo_('load', arguments)
+}
var getJSONFixture = function(url) {
- return jasmine.getJSONFixtures().proxyCallTo_('read', arguments)[url];
-};
+ return jasmine.getJSONFixtures().proxyCallTo_('read', arguments)[url]
+}
jasmine.spiedEventsKey = function (selector, eventName) {
- return [$(selector).selector, eventName].toString();
+ return [$(selector).selector, eventName].toString()
}
jasmine.getFixtures = function() {
@@ -203,7 +203,7 @@ jasmine.StyleFixtures.prototype.cleanUp = function() {
jasmine.StyleFixtures.prototype.createStyle_ = function(html) {
var style = jQuery('<style></style>').text(html)
- this.fixturesNodes_.push(style);
+ this.fixturesNodes_.push(style)
jQuery('head').append(style)
}
@@ -223,57 +223,57 @@ jasmine.StyleFixtures.prototype.proxyCallTo_ = jasmine.Fixtures.prototype.proxyC
/** jasmine json fixtures */
jasmine.getJSONFixtures = function() {
- return jasmine.currentJSONFixtures_ = jasmine.currentJSONFixtures_ || new jasmine.JSONFixtures();
-};
+ return jasmine.currentJSONFixtures_ = jasmine.currentJSONFixtures_ || new jasmine.JSONFixtures()
+}
jasmine.JSONFixtures = function() {
- this.fixturesCache_ = {};
- this.fixturesPath = 'spec/javascripts/fixtures/json';
-};
+ this.fixturesCache_ = {}
+ this.fixturesPath = 'spec/javascripts/fixtures/json'
+}
jasmine.JSONFixtures.prototype.load = function() {
- this.read.apply(this, arguments);
+ this.read.apply(this, arguments)
return this.fixturesCache_
-};
+}
jasmine.JSONFixtures.prototype.read = function() {
- var fixtureUrls = arguments;
+ var fixtureUrls = arguments
for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) {
- this.getFixtureData_(fixtureUrls[urlIndex]);
+ this.getFixtureData_(fixtureUrls[urlIndex])
}
return this.fixturesCache_
-};
+}
jasmine.JSONFixtures.prototype.clearCache = function() {
- this.fixturesCache_ = {};
-};
+ this.fixturesCache_ = {}
+}
jasmine.JSONFixtures.prototype.getFixtureData_ = function(url) {
- this.loadFixtureIntoCache_(url);
- return this.fixturesCache_[url];
-};
+ this.loadFixtureIntoCache_(url)
+ return this.fixturesCache_[url]
+}
jasmine.JSONFixtures.prototype.loadFixtureIntoCache_ = function(relativeUrl) {
- var self = this;
- var url = this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + 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: 'json',
url: url,
success: function(data) {
- console.log("Loading data into " + relativeUrl);
- self.fixturesCache_[relativeUrl] = data;
+ console.log("Loading data into " + relativeUrl)
+ self.fixturesCache_[relativeUrl] = data
},
error: function(jqXHR, status, errorThrown) {
- throw Error('JSONFixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + errorThrown.message + ')');
+ throw Error('JSONFixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + errorThrown.message + ')')
}
- });
-};
+ })
+}
jasmine.JSONFixtures.prototype.proxyCallTo_ = function(methodName, passedArguments) {
- return this[methodName].apply(this, passedArguments);
-};
+ return this[methodName].apply(this, passedArguments)
+}
jasmine.JQuery = function() {}
@@ -289,7 +289,7 @@ jasmine.JQuery.elementToString = function(element) {
return element.toString()
}
-jasmine.JQuery.matchersClass = {};
+jasmine.JQuery.matchersClass = {}
!function(namespace) {
var data = {
@@ -309,7 +309,7 @@ jasmine.JQuery.matchersClass = {};
eventName: eventName,
handler: handler,
reset: function(){
- delete data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)];
+ delete data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
}
}
},
@@ -470,7 +470,7 @@ jasmine.JQuery.matchersClass = {};
|| jasmine.isDomNode(this.actual))) {
this.actual = $(this.actual)
var result = jQueryMatchers[methodName].apply(this, arguments)
- var element;
+ var element
if (this.actual.get && (element = this.actual.get()[0]) && !$.isWindow(element) && element.tagName !== "HTML")
this.actual = jasmine.JQuery.elementToString(this.actual)
return result
@@ -505,7 +505,7 @@ beforeEach(function() {
this.addMatchers({
toHaveBeenTriggered: function(){
var eventName = this.actual.eventName,
- selector = this.actual.selector;
+ selector = this.actual.selector
this.message = function() {
return [
"Expected event " + eventName + " to have been triggered on " + selector,
@@ -529,7 +529,7 @@ beforeEach(function() {
this.addMatchers({
toHaveBeenPrevented: function() {
var eventName = this.actual.eventName,
- selector = this.actual.selector;
+ selector = this.actual.selector
this.message = function() {
return [
"Expected event " + eventName + " to have been prevented on " + selector,
@@ -1138,8 +1138,8 @@ describe("jasmine.StyleFixtures", function() {
var stylesNumOld = $('head style').length
jasmine.getStyleFixtures().load(fixtureUrl)
- expect($('head style').length - stylesNumOld).toEqual(1);
- expect(fixturesContainer().html()).toEqual(ajaxData);
+ expect($('head style').length - stylesNumOld).toEqual(1)
+ expect(fixturesContainer().html()).toEqual(ajaxData)
})
it("should insert duplicated CSS fixture into one style tag when the same url is provided twice in a single call", function() {
@@ -1167,8 +1167,8 @@ describe("jasmine.StyleFixtures", function() {
var stylesNumOld = $('head style').length
jasmine.getStyleFixtures().appendLoad(fixtureUrl)
- expect($('head style').length - stylesNumOld).toEqual(1);
- expect(fixturesContainer().html()).toEqual(ajaxData);
+ expect($('head style').length - stylesNumOld).toEqual(1)
+ expect(fixturesContainer().html()).toEqual(ajaxData)
})
it("should insert duplicated CSS fixture into one style tag when the same url is provided twice in a single call", function() {
@@ -1284,9 +1284,9 @@ describe("jasmine.StyleFixtures", function() {
var stylesNumOld = $('head style').length
jasmine.getStyleFixtures().load(fixtureUrl, anotherFixtureUrl)
- jasmine.getStyleFixtures().cleanUp();
+ jasmine.getStyleFixtures().cleanUp()
- expect($('head style').length).toEqual(stylesNumOld);
+ expect($('head style').length).toEqual(stylesNumOld)
})
})
@@ -1330,79 +1330,81 @@ describe("jasmine.StyleFixtures using real AJAX call", function() {
describe("jasmine.JSONFixtures", function() {
- var ajaxData = {a:1, b:2, arr: [1,2,'stuff'], hsh: { blurp: 8, blop: 'blip' }};
- var moreAjaxData = [1,2,'stuff'];
+ var ajaxData = {a:1, b:2, arr: [1,2,'stuff'], hsh: { blurp: 8, blop: 'blip' }}
+ var moreAjaxData = [1,2,'stuff']
var fixtureUrl = 'some_json'
var anotherFixtureUrl = 'another_json'
+ var _sortedKeys = function(obj) {
+ var arr = []
+ for(var k in obj) arr.push(k)
+ return arr.sort()
+ }
beforeEach(function() {
jasmine.getJSONFixtures().clearCache()
spyOn(jasmine.JSONFixtures.prototype, 'loadFixtureIntoCache_').andCallFake(function(relativeUrl){
- fakeData = {};
+ fakeData = {}
// we put the data directly here, instead of using the variables to simulate rereading the file
- fakeData[fixtureUrl] = {a:1, b:2, arr: [1,2,'stuff'], hsh: { blurp: 8, blop: 'blip' }};
- fakeData[anotherFixtureUrl] = [1,2,'stuff'];
- this.fixturesCache_[relativeUrl] = fakeData[relativeUrl];
- });
- });
+ fakeData[fixtureUrl] = {a:1, b:2, arr: [1,2,'stuff'], hsh: { blurp: 8, blop: 'blip' }}
+ fakeData[anotherFixtureUrl] = [1,2,'stuff']
+ this.fixturesCache_[relativeUrl] = fakeData[relativeUrl]
+ })
+ })
describe("default initial config values", function() {
it("should set 'spec/javascripts/fixtures/json' as the default style fixtures path", function() {
- expect(jasmine.getJSONFixtures().fixturesPath).toEqual('spec/javascripts/fixtures/json');
- });
- });
+ expect(jasmine.getJSONFixtures().fixturesPath).toEqual('spec/javascripts/fixtures/json')
+ })
+ })
describe("load", function() {
it("should load the JSON data under the key 'fixture_url'", function() {
- data = jasmine.getJSONFixtures().load(fixtureUrl);
- expect(_sortedKeys(data)).toEqual([fixtureUrl]);
- expect(data[fixtureUrl]).toEqual(ajaxData);
- });
+ data = jasmine.getJSONFixtures().load(fixtureUrl)
+ expect(_sortedKeys(data)).toEqual([fixtureUrl])
+ expect(data[fixtureUrl]).toEqual(ajaxData)
+ })
it("should load the JSON data under the key 'fixture_url', even if it's loaded twice in one call", function() {
- data = jasmine.getJSONFixtures().load(fixtureUrl, fixtureUrl);
- expect(_sortedKeys(data)).toEqual([fixtureUrl]);
- });
+ data = jasmine.getJSONFixtures().load(fixtureUrl, fixtureUrl)
+ expect(_sortedKeys(data)).toEqual([fixtureUrl])
+ })
it("should load the JSON data under 2 keys given two files in a single call", function() {
- data = jasmine.getJSONFixtures().load(anotherFixtureUrl, fixtureUrl);
- expect(_sortedKeys(data)).toEqual([anotherFixtureUrl, fixtureUrl]);
- expect(data[anotherFixtureUrl]).toEqual(moreAjaxData);
- expect(data[fixtureUrl]).toEqual(ajaxData);
- });
+ data = jasmine.getJSONFixtures().load(anotherFixtureUrl, fixtureUrl)
+ expect(_sortedKeys(data)).toEqual([anotherFixtureUrl, fixtureUrl])
+ expect(data[anotherFixtureUrl]).toEqual(moreAjaxData)
+ expect(data[fixtureUrl]).toEqual(ajaxData)
+ })
it("should have shortcut global method loadJSONFixtures", function() {
- data = loadJSONFixtures(fixtureUrl, anotherFixtureUrl);
- expect(_sortedKeys(data)).toEqual([anotherFixtureUrl, fixtureUrl]);
- expect(data[anotherFixtureUrl]).toEqual(moreAjaxData);
- expect(data[fixtureUrl]).toEqual(ajaxData);
- });
- });
+ data = loadJSONFixtures(fixtureUrl, anotherFixtureUrl)
+ expect(_sortedKeys(data)).toEqual([anotherFixtureUrl, fixtureUrl])
+ expect(data[anotherFixtureUrl]).toEqual(moreAjaxData)
+ expect(data[fixtureUrl]).toEqual(ajaxData)
+ })
+ })
describe('getJSONFixture', function() {
it("fetches the fixture you ask for", function() {
- data = loadJSONFixtures(fixtureUrl);
- data = loadJSONFixtures(anotherFixtureUrl);
-
- expect(getJSONFixture(fixtureUrl)).toEqual(ajaxData);
- expect(getJSONFixture(anotherFixtureUrl)).toEqual(moreAjaxData);
- });
- });
+ expect(getJSONFixture(fixtureUrl)).toEqual(ajaxData)
+ expect(getJSONFixture(anotherFixtureUrl)).toEqual(moreAjaxData)
+ })
+ })
describe("reloading data will restore the fixture data", function() {
- var data;
+ var data
beforeEach(function() {
data = jasmine.getJSONFixtures().load(anotherFixtureUrl)[anotherFixtureUrl]
- });
+ })
// WARNING: this test must be invoked first (before 'SECOND TEST')!
it("FIRST TEST: should pollute the fixture data", function() {
data.push('moredata')
- expect(data.length).toEqual(4);
+ expect(data.length).toEqual(4)
})
// WARNING: this test must be invoked second (after 'FIRST TEST')!
it("SECOND TEST: should see cleansed JSON fixture data", function() {
- expect(data.length).toEqual(3);
+ expect(data.length).toEqual(3)
})
})
})
@@ -1420,22 +1422,13 @@ describe("jasmine.JSONFixtures using real AJAX call", function() {
})
describe("when fixture file exists", function() {
- var fixtureUrl = "jasmine_json_test.json";
+ var fixtureUrl = "jasmine_json_test.json"
it("should load content of fixture file", function() {
- data = jasmine.getJSONFixtures().load(fixtureUrl);
- expect(data[fixtureUrl]).toEqual([1,2,3]);
+ data = jasmine.getJSONFixtures().load(fixtureUrl)
+ expect(data[fixtureUrl]).toEqual([1,2,3])
})
})
})
-/** helper methods */
-var _sortedKeys = function(obj) {
- arr = [];
- for( var k in obj) {
- arr.push(k);
- }
- return arr.sort();
-};
-

0 comments on commit 93f8184

Please sign in to comment.