diff --git a/CHANGELOG b/CHANGELOG index e6000d0..f3fe5a3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Remove usage of the `with` statement from unit tests. [Tobie Langel] + * Complete rewrite of the deprecation helper, now renamed UpdateHelper and useable by third-party libs. [Tobie Langel] * Make Element#writeAttribute handle frameborder attribute in IE. Closes #11068. [staaky, Tobie Langel] diff --git a/ext/update_helper/prototype_update_helper.html b/ext/update_helper/prototype_update_helper.html index 0649b07..d2d4325 100644 --- a/ext/update_helper/prototype_update_helper.html +++ b/ext/update_helper/prototype_update_helper.html @@ -76,212 +76,212 @@ }); new Test.Unit.Runner({ - testGetStack: function(){ with(this) { - assertMatch(/prototype_update_helper\.html:\d+\n$/, prototypeUpdateHelper.getStack()); - }}, + testGetStack: function() { + this.assertMatch(/prototype_update_helper\.html:\d+\n$/, prototypeUpdateHelper.getStack()); + }, - testDisplay: function(){ with(this) { + testDisplay: function() { Toggle.display('foo'); - assertInfoNotified('Toggle.display has been deprecated, please use Element.toggle instead.'); + this.assertInfoNotified('Toggle.display has been deprecated, please use Element.toggle instead.'); Element.show('foo', 'bar', 'bla'); - assertErrorNotified('Passing an arbitrary number of elements to Element.show is no longer supported.\n' + + this.assertErrorNotified('Passing an arbitrary number of elements to Element.show is no longer supported.\n' + 'Use [id_1, id_2, ...].each(Element.show) or $(id_1, id_2, ...).invoke("show") instead.'); $('foo', 'bar', 'bla').each(Element.hide); - assertNotNotified(); + this.assertNotNotified(); Element.show('foo'); - assertNotNotified(); + this.assertNotNotified(); Element.hide('foo', 'bar', 'bla'); - assertErrorNotified('Passing an arbitrary number of elements to Element.hide is no longer supported.\n' + + this.assertErrorNotified('Passing an arbitrary number of elements to Element.hide is no longer supported.\n' + 'Use [id_1, id_2, ...].each(Element.hide) or $(id_1, id_2, ...).invoke("hide") instead.'); Element.toggle('foo', 'bar', 'bla'); - assertErrorNotified('Passing an arbitrary number of elements to Element.toggle is no longer supported.\n' + + this.assertErrorNotified('Passing an arbitrary number of elements to Element.toggle is no longer supported.\n' + 'Use [id_1, id_2, ...].each(Element.toggle) or $(id_1, id_2, ...).invoke("toggle") instead.'); - }}, + }, - testElementStyle: function(){ with(this) { + testElementStyle: function() { Element.setStyle('foo', { 'fontSize': '18px' }); - assertNotNotified(); + this.assertNotNotified(); Element.setStyle('foo', { 'font-size': '18px' }); - assertErrorNotified('Use of uncamelized style-property names is no longer supported.\n' + + this.assertErrorNotified('Use of uncamelized style-property names is no longer supported.\n' + 'Use either camelized style-property names or a regular CSS string instead (see online documentation).') Element.setStyle('foo', 'font-size: 18px;'); - assertNotNotified(); + this.assertNotNotified(); $('foo').setStyle({ 'font-size': '18px' }); - assertErrorNotified('Use of uncamelized style-property names is no longer supported.\n' + + this.assertErrorNotified('Use of uncamelized style-property names is no longer supported.\n' + 'Use either camelized style-property names or a regular CSS string instead (see online documentation).') - }}, + }, - testClassNames: function(){ with(this) { + testClassNames: function() { new Element.ClassNames('foo'); - assertInfoNotified('Element.ClassNames has been deprecated.') + this.assertInfoNotified('Element.ClassNames has been deprecated.') $('foo').classNames(); - assertInfoNotified('Element#classNames has been deprecated.\n' + + this.assertInfoNotified('Element#classNames has been deprecated.\n' + 'If you need to access CSS class names as an array, try: $w(element.classname).') Element.getElementsByClassName('foo', 'className'); - assertInfoNotified('Element#getElementsByClassName has been deprecated, please use Element#select instead.') + this.assertInfoNotified('Element#getElementsByClassName has been deprecated, please use Element#select instead.') document.getElementsByClassName('className'); - assertInfoNotified('document.getElementsByClassName has been deprecated, please use $$ instead.') - }}, + this.assertInfoNotified('document.getElementsByClassName has been deprecated, please use $$ instead.') + }, - testDomSelectors: function(){ with(this) { + testDomSelectors: function() { Element.childOf('foo', 'bar'); - assertInfoNotified('Element#childOf has been deprecated, please use Element#descendantOf instead.'); + this.assertInfoNotified('Element#childOf has been deprecated, please use Element#descendantOf instead.'); $('foo').immediateDescendants(); - assertInfoNotified('Element#immediateDescendants has been deprecated, please use Element#childElements instead.'); + this.assertInfoNotified('Element#immediateDescendants has been deprecated, please use Element#childElements instead.'); $('foo').getElementsBySelector('a'); - assertInfoNotified('Element#getElementsBySelector has been deprecated, please use Element#select instead.'); + this.assertInfoNotified('Element#getElementsBySelector has been deprecated, please use Element#select instead.'); $('foo').select('a'); - assertNotNotified(); - }}, + this.assertNotNotified(); + }, - testField: function(){ with(this) { + testField: function() { Field.clear('foo', 'bar', 'bla'); - assertErrorNotified('Passing an arbitrary number of elements to Field.clear is no longer supported.\n' + + this.assertErrorNotified('Passing an arbitrary number of elements to Field.clear is no longer supported.\n' + 'Use [id_1, id_2, ...].each(Form.Element.clear) or $(id_1, id_2, ...).invoke("clear") instead.'); Field.present('foo', 'bar', 'bla'); - assertErrorNotified('Passing an arbitrary number of elements to Field.present is no longer supported.\n' + + this.assertErrorNotified('Passing an arbitrary number of elements to Field.present is no longer supported.\n' + 'Use [id_1, id_2, ...].each(Form.Element.present) or $(id_1, id_2, ...).invoke("present") instead.'); - }}, + }, - testInsertion: function(){ with(this) { + testInsertion: function() { Insertion.Before('foo', 'text'); - assertInfoNotified('Insertion.Before has been deprecated, please use Element#insert instead.'); + this.assertInfoNotified('Insertion.Before has been deprecated, please use Element#insert instead.'); Insertion.Top('foo', 'text'); - assertInfoNotified('Insertion.Top has been deprecated, please use Element#insert instead.'); + this.assertInfoNotified('Insertion.Top has been deprecated, please use Element#insert instead.'); Insertion.Bottom('foo', 'text'); - assertInfoNotified('Insertion.Bottom has been deprecated, please use Element#insert instead.'); + this.assertInfoNotified('Insertion.Bottom has been deprecated, please use Element#insert instead.'); Insertion.After('foo', 'text'); - assertInfoNotified('Insertion.After has been deprecated, please use Element#insert instead.'); - }}, + this.assertInfoNotified('Insertion.After has been deprecated, please use Element#insert instead.'); + }, - testPosition: function(){ with(this) { + testPosition: function() { Position.prepare('foo'); - assertInfoNotified('Position.prepare has been deprecated.'); + this.assertInfoNotified('Position.prepare has been deprecated.'); Position.within('foo'); - assertInfoNotified('Position.within has been deprecated.'); + this.assertInfoNotified('Position.within has been deprecated.'); Position.withinIncludingScrolloffsets('foo'); - assertInfoNotified('Position.withinIncludingScrolloffsets has been deprecated.'); + this.assertInfoNotified('Position.withinIncludingScrolloffsets has been deprecated.'); Position.overlap('foo'); - assertInfoNotified('Position.overlap has been deprecated.'); + this.assertInfoNotified('Position.overlap has been deprecated.'); Position.cumulativeOffset('foo'); - assertInfoNotified('Position.cumulativeOffset has been deprecated, please use Element#cumulativeOffset instead.'); + this.assertInfoNotified('Position.cumulativeOffset has been deprecated, please use Element#cumulativeOffset instead.'); Position.positionedOffset('foo'); - assertInfoNotified('Position.positionedOffset has been deprecated, please use Element#positionedOffset instead.'); + this.assertInfoNotified('Position.positionedOffset has been deprecated, please use Element#positionedOffset instead.'); Position.absolutize('foo'); - assertInfoNotified('Position.absolutize has been deprecated, please use Element#absolutize instead.'); + this.assertInfoNotified('Position.absolutize has been deprecated, please use Element#absolutize instead.'); Position.relativize('foo'); - assertInfoNotified('Position.relativize has been deprecated, please use Element#relativize instead.'); + this.assertInfoNotified('Position.relativize has been deprecated, please use Element#relativize instead.'); Position.realOffset('foo'); - assertInfoNotified('Position.realOffset has been deprecated, please use Element#cumulativeScrollOffset instead.'); + this.assertInfoNotified('Position.realOffset has been deprecated, please use Element#cumulativeScrollOffset instead.'); Position.offsetParent('foo'); - assertInfoNotified('Position.offsetParent has been deprecated, please use Element#getOffsetParent instead.'); + this.assertInfoNotified('Position.offsetParent has been deprecated, please use Element#getOffsetParent instead.'); Position.page('foo'); - assertInfoNotified('Position.page has been deprecated, please use Element#viewportOffset instead.'); + this.assertInfoNotified('Position.page has been deprecated, please use Element#viewportOffset instead.'); Position.clone('foo', 'bar'); - assertInfoNotified('Position.clone has been deprecated, please use Element#clonePosition instead.'); - }}, + this.assertInfoNotified('Position.clone has been deprecated, please use Element#clonePosition instead.'); + }, - testEvent: function(){ with(this) { + testEvent: function() { Event.unloadCache(); - assertErrorNotified('Event.unloadCache has been deprecated.') - }}, + this.assertErrorNotified('Event.unloadCache has been deprecated.') + }, - testHash: function(){ with(this) { + testHash: function() { Hash.toQueryString({}); - assertInfoNotified('Hash.toQueryString has been deprecated.\n' + + this.assertInfoNotified('Hash.toQueryString has been deprecated.\n' + 'Use the instance method Hash#toQueryString or Object.toQueryString instead.'); Hash.toJSON({}); - assertErrorNotified('Hash.toJSON has been removed.\n' + + this.assertErrorNotified('Hash.toJSON has been removed.\n' + 'Use the instance method Hash#toJSON or Object.toJSON instead.'); var h = $H({ foo: 2 }); h.remove('foo'); - assertErrorNotified('Hash#remove is no longer supported, use Hash#unset instead.\n' + + this.assertErrorNotified('Hash#remove is no longer supported, use Hash#unset instead.\n' + 'Please note that Hash#unset only accepts one argument.'); h.merge('foo'); - assertWarnNotified('Hash#merge is no longer destructive and now operates on a clone of the Hash instance.\n' + 'If you need a destructive merge, use Hash#update instead.'); + this.assertWarnNotified('Hash#merge is no longer destructive and now operates on a clone of the Hash instance.\n' + 'If you need a destructive merge, use Hash#update instead.'); h['foo']; - assertErrorNotified('Directly accessing a property of an instance of Hash is no longer supported.\n' + + this.assertErrorNotified('Directly accessing a property of an instance of Hash is no longer supported.\n' + 'Please use Hash#get(\'foo\') instead.') h.foo = 3; - assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' + + this.assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' + 'Please use Hash#set(\'foo\', 3) instead.') h.bar = 'bar'; h.toJSON(); - assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' + + this.assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' + 'Please use Hash#set(\'bar\', \'bar\') instead.') h.bar; - assertErrorNotified('Directly accessing a property of an instance of Hash is no longer supported.\n' + + this.assertErrorNotified('Directly accessing a property of an instance of Hash is no longer supported.\n' + 'Please use Hash#get(\'bar\') instead.') h.baz = 'baz'; h.bar; - assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' + + this.assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' + 'Please use Hash#set(\'baz\', \'baz\') instead.') h.set('toJSON', 'arg'); // make sure hash methods are not overwritten - assertRespondsTo('toJSON', h) - }}, + this.assertRespondsTo('toJSON', h) + }, - testClass: function(){ with(this) { + testClass: function() { Class.create(); - assertInfoNotified('The class API has been fully revised and now allows for mixins and inheritance.\n' + + this.assertInfoNotified('The class API has been fully revised and now allows for mixins and inheritance.\n' + 'You can find more about it here: http://prototypejs.org/learn/class-inheritance'); Class.create({}); - assertNotNotified(); - }}, + this.assertNotNotified(); + }, - testLogDeprecationOption: function(){ with(this) { + testLogDeprecationOption: function() { prototypeUpdateHelper.logLevel = UpdateHelper.Warn; var h = $H({ foo: 2 }); h.merge({ foo: 3 }); - assertWarnNotified('Hash#merge is no longer destructive and now operates on a clone of the Hash instance.\n' + 'If you need a destructive merge, use Hash#update instead.'); + this.assertWarnNotified('Hash#merge is no longer destructive and now operates on a clone of the Hash instance.\n' + 'If you need a destructive merge, use Hash#update instead.'); h.remove('foo'); - assertErrorNotified('Hash#remove is no longer supported, use Hash#unset instead.\n' + + this.assertErrorNotified('Hash#remove is no longer supported, use Hash#unset instead.\n' + 'Please note that Hash#unset only accepts one argument.'); document.getElementsByClassName('className'); - assertNotNotified(); + this.assertNotNotified(); prototypeUpdateHelper.logLevel = UpdateHelper.Info; - }} + } }); diff --git a/test/unit/ajax.html b/test/unit/ajax.html index 3744d34..6ab7c79 100644 --- a/test/unit/ajax.html +++ b/test/unit/ajax.html @@ -81,88 +81,88 @@ var message = 'You must be running your tests from rake to test this feature.'; new Test.Unit.Runner({ - setup: function(){ + setup: function() { $('content').update(''); $('content2').update(''); }, - teardown: function(){ + teardown: function() { // hack to cleanup responders Ajax.Responders.responders = [Ajax.Responders.responders[0]]; }, - testSynchronousRequest: function() {with(this) { - assertEqual("", $("content").innerHTML); + testSynchronousRequest: function() { + this.assertEqual("", $("content").innerHTML); - assertEqual(0, Ajax.activeRequestCount); + this.assertEqual(0, Ajax.activeRequestCount); new Ajax.Request("fixtures/hello.js", { asynchronous: false, method: 'GET', evalJS: 'force' }); - assertEqual(0, Ajax.activeRequestCount); + this.assertEqual(0, Ajax.activeRequestCount); var h2 = $("content").firstChild; - assertEqual("Hello world!", h2.innerHTML); - }}, + this.assertEqual("Hello world!", h2.innerHTML); + }, - testAsynchronousRequest: function() {with(this) { - assertEqual("", $("content").innerHTML); + testAsynchronousRequest: function() { + this.assertEqual("", $("content").innerHTML); new Ajax.Request("fixtures/hello.js", { asynchronous: true, method: 'get', evalJS: 'force' }); - wait(1000, function() { + this.wait(1000, function() { var h2 = $("content").firstChild; - assertEqual("Hello world!", h2.innerHTML); + this.assertEqual("Hello world!", h2.innerHTML); }); - }}, + }, - testUpdater: function() {with(this) { - assertEqual("", $("content").innerHTML); + testUpdater: function() { + this.assertEqual("", $("content").innerHTML); new Ajax.Updater("content", "fixtures/content.html", { method:'get' }); - wait(1000, function() { - assertEqual(sentence, $("content").innerHTML.strip().toLowerCase()); + this.wait(1000, function() { + this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase()); $('content').update(''); - assertEqual("", $("content").innerHTML); + this.assertEqual("", $("content").innerHTML); new Ajax.Updater({ success:"content", failure:"content2" }, "fixtures/content.html", { method:'get', parameters:{ pet:'monkey' } }); new Ajax.Updater("", "fixtures/content.html", { method:'get', parameters:"pet=monkey" }); - wait(1000, function() { - assertEqual(sentence, $("content").innerHTML.strip().toLowerCase()); - assertEqual("", $("content2").innerHTML); + this.wait(1000, function() { + this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase()); + this.assertEqual("", $("content2").innerHTML); }); }); - }}, + }, - testUpdaterWithInsertion: function() {with(this) { + testUpdaterWithInsertion: function() { $('content').update(); new Ajax.Updater("content", "fixtures/content.html", { method:'get', insertion: Insertion.Top }); - wait(1000, function() { - assertEqual(sentence, $("content").innerHTML.strip().toLowerCase()); + this.wait(1000, function() { + this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase()); $('content').update(); new Ajax.Updater("content", "fixtures/content.html", { method:'get', insertion: 'bottom' }); - wait(1000, function() { - assertEqual(sentence, $("content").innerHTML.strip().toLowerCase()); + this.wait(1000, function() { + this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase()); $('content').update(); new Ajax.Updater("content", "fixtures/content.html", { method:'get', insertion: 'after' }); - wait(1000, function() { - assertEqual('five dozen', $("content").next().innerHTML.strip().toLowerCase()); + this.wait(1000, function() { + this.assertEqual('five dozen', $("content").next().innerHTML.strip().toLowerCase()); }); }); }); - }}, + }, - testUpdaterOptions: function() {with(this) { + testUpdaterOptions: function() { var options = { method: 'get', asynchronous: false, @@ -171,26 +171,26 @@ } var request = new Ajax.Updater("content", "fixtures/hello.js", options); request.options.onComplete = function() {}; - assertIdentical(Prototype.emptyFunction, options.onComplete); - }}, + this.assertIdentical(Prototype.emptyFunction, options.onComplete); + }, - testResponders: function(){with(this) { + testResponders: function(){ // check for internal responder - assertEqual(1, Ajax.Responders.responders.length); + this.assertEqual(1, Ajax.Responders.responders.length); var dummyResponder = { onComplete: function(req) { /* dummy */ } }; Ajax.Responders.register(dummyResponder); - assertEqual(2, Ajax.Responders.responders.length); + this.assertEqual(2, Ajax.Responders.responders.length); // don't add twice Ajax.Responders.register(dummyResponder); - assertEqual(2, Ajax.Responders.responders.length); + this.assertEqual(2, Ajax.Responders.responders.length); Ajax.Responders.unregister(dummyResponder); - assertEqual(1, Ajax.Responders.responders.length); + this.assertEqual(1, Ajax.Responders.responders.length); var responder = { onCreate: function(req){ responderCounter++ }, @@ -199,66 +199,66 @@ }; Ajax.Responders.register(responder); - assertEqual(0, responderCounter); - assertEqual(0, Ajax.activeRequestCount); + this.assertEqual(0, responderCounter); + this.assertEqual(0, Ajax.activeRequestCount); new Ajax.Request("fixtures/content.html", { method:'get', parameters:"pet=monkey" }); - assertEqual(1, responderCounter); - assertEqual(1, Ajax.activeRequestCount); + this.assertEqual(1, responderCounter); + this.assertEqual(1, Ajax.activeRequestCount); - wait(1000,function() { - assertEqual(3, responderCounter); - assertEqual(0, Ajax.activeRequestCount); + this.wait(1000,function() { + this.assertEqual(3, responderCounter); + this.assertEqual(0, Ajax.activeRequestCount); }); - }}, + }, - testEvalResponseShouldBeCalledBeforeOnComplete: function() {with(this) { - if (isRunningFromRake) { - assertEqual("", $("content").innerHTML); + testEvalResponseShouldBeCalledBeforeOnComplete: function() { + if (this.isRunningFromRake) { + this.assertEqual("", $("content").innerHTML); - assertEqual(0, Ajax.activeRequestCount); + this.assertEqual(0, Ajax.activeRequestCount); new Ajax.Request("fixtures/hello.js", extendDefault({ - onComplete: function(response) { assertNotEqual("", $("content").innerHTML) } + onComplete: function(response) { this.assertNotEqual("", $("content").innerHTML) }.bind(this) })); - assertEqual(0, Ajax.activeRequestCount); + this.assertEqual(0, Ajax.activeRequestCount); var h2 = $("content").firstChild; - assertEqual("Hello world!", h2.innerHTML); + this.assertEqual("Hello world!", h2.innerHTML); } else { - info(message); + this.info(message); } - }}, + }, - testContentTypeSetForSimulatedVerbs: function() {with(this) { - if (isRunningFromRake) { + testContentTypeSetForSimulatedVerbs: function() { + if (this.isRunningFromRake) { new Ajax.Request('/inspect', extendDefault({ method: 'put', contentType: 'application/bogus', onComplete: function(response) { - assertEqual('application/bogus; charset=UTF-8', response.responseJSON.headers['content-type']); - } + this.assertEqual('application/bogus; charset=UTF-8', response.responseJSON.headers['content-type']); + }.bind(this) })); } else { - info(message); + this.info(message); } - }}, + }, - testOnCreateCallback: function() {with(this) { + testOnCreateCallback: function() { new Ajax.Request("fixtures/content.html", extendDefault({ - onCreate: function(transport) { assertEqual(0, transport.readyState) }, - onComplete: function(transport) { assertNotEqual(0, transport.readyState) } + onCreate: function(transport) { this.assertEqual(0, transport.readyState) }.bind(this), + onComplete: function(transport) { this.assertNotEqual(0, transport.readyState) }.bind(this) })); - }}, + }, - testEvalJS: function() {with(this) { - if (isRunningFromRake) { + testEvalJS: function() { + if (this.isRunningFromRake) { $('content').update(); new Ajax.Request("/response", extendDefault({ parameters: Fixtures.js, onComplete: function(transport) { var h2 = $("content").firstChild; - assertEqual("Hello world!", h2.innerHTML); - } + this.assertEqual("Hello world!", h2.innerHTML); + }.bind(this) })); $('content').update(); @@ -266,11 +266,11 @@ evalJS: false, parameters: Fixtures.js, onComplete: function(transport) { - assertEqual("", $("content").innerHTML); - } + this.assertEqual("", $("content").innerHTML); + }.bind(this) })); } else { - info(message); + this.info(message); } $('content').update(); @@ -278,14 +278,14 @@ evalJS: 'force', onComplete: function(transport) { var h2 = $("content").firstChild; - assertEqual("Hello world!", h2.innerHTML); - } + this.assertEqual("Hello world!", h2.innerHTML); + }.bind(this) })); - }}, + }, - testCallbacks: function() {with(this) { + testCallbacks: function() { var options = extendDefault({ - onCreate: function(transport) { assertInstanceOf(Ajax.Response, transport) } + onCreate: function(transport) { this.assertInstanceOf(Ajax.Response, transport) }.bind(this) }); Ajax.Request.Events.each(function(state){ @@ -293,36 +293,36 @@ }); new Ajax.Request("fixtures/content.html", options); - }}, + }, - testResponseText: function() {with(this) { + testResponseText: function() { new Ajax.Request("fixtures/empty.html", extendDefault({ - onComplete: function(transport) { assertEqual('', transport.responseText) } + onComplete: function(transport) { this.assertEqual('', transport.responseText) }.bind(this) })); new Ajax.Request("fixtures/content.html", extendDefault({ - onComplete: function(transport) { assertEqual(sentence, transport.responseText.toLowerCase()) } + onComplete: function(transport) { this.assertEqual(sentence, transport.responseText.toLowerCase()) }.bind(this) })); - }}, + }, - testResponseXML: function() {with(this) { - if (isRunningFromRake) { + testResponseXML: function() { + if (this.isRunningFromRake) { new Ajax.Request("/response", extendDefault({ parameters: Fixtures.xml, onComplete: function(transport) { - assertEqual('foo', transport.responseXML.getElementsByTagName('name')[0].getAttribute('attr')) - } + this.assertEqual('foo', transport.responseXML.getElementsByTagName('name')[0].getAttribute('attr')) + }.bind(this) })); } else { - info(message); + this.info(message); } - }}, + }, - testResponseJSON: function() {with(this) { - if (isRunningFromRake) { + testResponseJSON: function() { + if (this.isRunningFromRake) { new Ajax.Request("/response", extendDefault({ parameters: Fixtures.json, - onComplete: function(transport) { assertEqual(123, transport.responseJSON.test) } + onComplete: function(transport) { this.assertEqual(123, transport.responseJSON.test) }.bind(this) })); new Ajax.Request("/response", extendDefault({ @@ -330,95 +330,95 @@ 'Content-Length': 0, 'Content-Type': 'application/json' }, - onComplete: function(transport) { assertNull(transport.responseJSON) } + onComplete: function(transport) { this.assertNull(transport.responseJSON) }.bind(this) })); new Ajax.Request("/response", extendDefault({ evalJSON: false, parameters: Fixtures.json, - onComplete: function(transport) { assertNull(transport.responseJSON) } + onComplete: function(transport) { this.assertNull(transport.responseJSON) }.bind(this) })); new Ajax.Request("/response", extendDefault({ parameters: Fixtures.jsonWithoutContentType, - onComplete: function(transport) { assertNull(transport.responseJSON) } + onComplete: function(transport) { this.assertNull(transport.responseJSON) }.bind(this) })); new Ajax.Request("/response", extendDefault({ sanitizeJSON: true, parameters: Fixtures.invalidJson, onException: function(request, error) { - assert(error.message.include('Badly formed JSON string')); - assertInstanceOf(Ajax.Request, request); - } + this.assert(error.message.include('Badly formed JSON string')); + this.assertInstanceOf(Ajax.Request, request); + }.bind(this) })); } else { - info(message); + this.info(message); } new Ajax.Request("fixtures/data.json", extendDefault({ evalJSON: 'force', - onComplete: function(transport) { assertEqual(123, transport.responseJSON.test) } + onComplete: function(transport) { this.assertEqual(123, transport.responseJSON.test) }.bind(this) })); - }}, + }, - testHeaderJSON: function() {with(this) { - if (isRunningFromRake) { + testHeaderJSON: function() { + if (this.isRunningFromRake) { new Ajax.Request("/response", extendDefault({ parameters: Fixtures.headerJson, onComplete: function(transport, json) { - assertEqual('hello #éà', transport.headerJSON.test); - assertEqual('hello #éà', json.test); - } + this.assertEqual('hello #éà', transport.headerJSON.test); + this.assertEqual('hello #éà', json.test); + }.bind(this) })); new Ajax.Request("/response", extendDefault({ onComplete: function(transport, json) { - assertNull(transport.headerJSON) - assertNull(json) - } + this.assertNull(transport.headerJSON) + this.assertNull(json) + }.bind(this) })); } else { - info(message); + this.info(message); } - }}, + }, - testGetHeader: function() {with(this) { - if (isRunningFromRake) { + testGetHeader: function() { + if (this.isRunningFromRake) { new Ajax.Request("/response", extendDefault({ parameters: { 'X-TEST': 'some value' }, onComplete: function(transport) { - assertEqual('some value', transport.getHeader('X-Test')); - assertNull(transport.getHeader('X-Inexistant')); - } + this.assertEqual('some value', transport.getHeader('X-Test')); + this.assertNull(transport.getHeader('X-Inexistant')); + }.bind(this) })); } else { - info(message); + this.info(message); } - }}, + }, - testParametersCanBeHash: function() {with(this) { - if (isRunningFromRake) { + testParametersCanBeHash: function() { + if (this.isRunningFromRake) { new Ajax.Request("/response", extendDefault({ parameters: $H({ "one": "two", "three": "four" }), onComplete: function(transport) { - assertEqual("two", transport.getHeader("one")); - assertEqual("four", transport.getHeader("three")); - assertNull(transport.getHeader("toObject")); - } + this.assertEqual("two", transport.getHeader("one")); + this.assertEqual("four", transport.getHeader("three")); + this.assertNull(transport.getHeader("toObject")); + }.bind(this) })); } else { - info(message); + this.info(message); } - }}, + }, - testIsSameOriginMethod: function() {with(this) { + testIsSameOriginMethod: function() { var isSameOrigin = Ajax.Request.prototype.isSameOrigin; - assert(isSameOrigin.call({ url: '/foo/bar.html' }), '/foo/bar.html'); - assert(isSameOrigin.call({ url: window.location.toString() }), window.location); - assert(!isSameOrigin.call({ url: 'http://example.com' }), 'http://example.com'); + this.assert(isSameOrigin.call({ url: '/foo/bar.html' }), '/foo/bar.html'); + this.assert(isSameOrigin.call({ url: window.location.toString() }), window.location); + this.assert(!isSameOrigin.call({ url: 'http://example.com' }), 'http://example.com'); - if (isRunningFromRake) { + if (this.isRunningFromRake) { Ajax.Request.prototype.isSameOrigin = function() { return false }; @@ -427,29 +427,29 @@ new Ajax.Request("/response", extendDefault({ parameters: Fixtures.js, onComplete: function(transport) { - assertEqual("same origin policy", $("content").innerHTML); - } + this.assertEqual("same origin policy", $("content").innerHTML); + }.bind(this) })); new Ajax.Request("/response", extendDefault({ parameters: Fixtures.invalidJson, onException: function(request, error) { - assert(error.message.include('Badly formed JSON string')); - } + this.assert(error.message.include('Badly formed JSON string')); + }.bind(this) })); new Ajax.Request("/response", extendDefault({ parameters: { 'X-JSON': '{});window.attacked = true;({}' }, onException: function(request, error) { - assert(error.message.include('Badly formed JSON string')); - } + this.assert(error.message.include('Badly formed JSON string')); + }.bind(this) })); Ajax.Request.prototype.isSameOrigin = isSameOrigin; } else { - info(message); + this.info(message); } - }} + } }); // ]]> diff --git a/test/unit/array.html b/test/unit/array.html index 288e6ad..db56c97 100644 --- a/test/unit/array.html +++ b/test/unit/array.html @@ -32,191 +32,191 @@ var globalArgsTest = 'nothing to see here'; new Test.Unit.Runner({ - test$A: function(){ with(this) { - assertEnumEqual([], $A({})); - }}, + test$A: function(){ + this.assertEnumEqual([], $A({})); + }, - testToArrayOnArguments: function(){ with(this) { + testToArrayOnArguments: function(){ function toArrayOnArguments(){ globalArgsTest = $A(arguments); } toArrayOnArguments(); - assertEnumEqual([], globalArgsTest); + this.assertEnumEqual([], globalArgsTest); toArrayOnArguments('foo'); - assertEnumEqual(['foo'], globalArgsTest); + this.assertEnumEqual(['foo'], globalArgsTest); toArrayOnArguments('foo','bar'); - assertEnumEqual(['foo','bar'], globalArgsTest); - }}, + this.assertEnumEqual(['foo','bar'], globalArgsTest); + }, - testToArrayOnNodeList: function(){ with(this) { + testToArrayOnNodeList: function(){ // direct HTML - assertEqual(3, $A($('test_node').childNodes).length); + this.assertEqual(3, $A($('test_node').childNodes).length); // DOM var element = document.createElement('div'); element.appendChild(document.createTextNode('22')); (2).times(function(){ element.appendChild(document.createElement('span')) }); - assertEqual(3, $A(element.childNodes).length); + this.assertEqual(3, $A(element.childNodes).length); // HTML String element = document.createElement('div'); $(element).update('22 diff --git a/test/unit/base.html b/test/unit/base.html index 51c8e95..d12863f 100644 --- a/test/unit/base.html +++ b/test/unit/base.html @@ -140,64 +140,64 @@ new Test.Unit.Runner({ - testFunctionArgumentNames: function() { with(this) { - assertEnumEqual([], (function() {}).argumentNames()); - assertEnumEqual(["one"], (function(one) {}).argumentNames()); - assertEnumEqual(["one", "two", "three"], (function(one, two, three) {}).argumentNames()); - assertEqual("$super", (function($super) {}).argumentNames().first()); + testFunctionArgumentNames: function() { + this.assertEnumEqual([], (function() {}).argumentNames()); + this.assertEnumEqual(["one"], (function(one) {}).argumentNames()); + this.assertEnumEqual(["one", "two", "three"], (function(one, two, three) {}).argumentNames()); + this.assertEqual("$super", (function($super) {}).argumentNames().first()); function named1() {}; - assertEnumEqual([], named1.argumentNames()); + this.assertEnumEqual([], named1.argumentNames()); function named2(one) {}; - assertEnumEqual(["one"], named2.argumentNames()); + this.assertEnumEqual(["one"], named2.argumentNames()); function named3(one, two, three) {}; - assertEnumEqual(["one", "two", "three"], named3.argumentNames()); - }}, + this.assertEnumEqual(["one", "two", "three"], named3.argumentNames()); + }, - testFunctionBind: function() { with(this) { + testFunctionBind: function() { function methodWithoutArguments() { return this.hi }; function methodWithArguments() { return this.hi + ',' + $A(arguments).join(',') }; var func = Prototype.emptyFunction; - assertIdentical(func, func.bind()); - assertIdentical(func, func.bind(undefined)); - assertNotIdentical(func, func.bind(null)); + this.assertIdentical(func, func.bind()); + this.assertIdentical(func, func.bind(undefined)); + this.assertNotIdentical(func, func.bind(null)); - assertEqual('without', methodWithoutArguments.bind({ hi: 'without' })()); - assertEqual('with,arg1,arg2', methodWithArguments.bind({ hi: 'with' })('arg1','arg2')); - assertEqual('withBindArgs,arg1,arg2', + this.assertEqual('without', methodWithoutArguments.bind({ hi: 'without' })()); + this.assertEqual('with,arg1,arg2', methodWithArguments.bind({ hi: 'with' })('arg1','arg2')); + this.assertEqual('withBindArgs,arg1,arg2', methodWithArguments.bind({ hi: 'withBindArgs' }, 'arg1', 'arg2')()); - assertEqual('withBindArgsAndArgs,arg1,arg2,arg3,arg4', + this.assertEqual('withBindArgsAndArgs,arg1,arg2,arg3,arg4', methodWithArguments.bind({ hi: 'withBindArgsAndArgs' }, 'arg1', 'arg2')('arg3', 'arg4')); - }}, + }, - testFunctionCurry: function() { with(this) { + testFunctionCurry: function() { var split = function(delimiter, string) { return string.split(delimiter); }; var splitOnColons = split.curry(":"); - assertNotIdentical(split, splitOnColons); - assertEnumEqual(split(":", "0:1:2:3:4:5"), splitOnColons("0:1:2:3:4:5")); - assertIdentical(split, split.curry()); - }}, + this.assertNotIdentical(split, splitOnColons); + this.assertEnumEqual(split(":", "0:1:2:3:4:5"), splitOnColons("0:1:2:3:4:5")); + this.assertIdentical(split, split.curry()); + }, - testFunctionDelay: function() { with(this) { + testFunctionDelay: function() { window.delayed = undefined; var delayedFunction = function() { window.delayed = true; }; var delayedFunctionWithArgs = function() { window.delayedWithArgs = $A(arguments).join(' '); }; delayedFunction.delay(0.8); delayedFunctionWithArgs.delay(0.8, 'hello', 'world'); - assertUndefined(window.delayed); - wait(1000, function() { - assert(window.delayed); - assertEqual('hello world', window.delayedWithArgs); + this.assertUndefined(window.delayed); + this.wait(1000, function() { + this.assert(window.delayed); + this.assertEqual('hello world', window.delayedWithArgs); }); - }}, + }, - testFunctionWrap: function() { with(this) { + testFunctionWrap: function() { function sayHello(){ return 'hello world'; }; - assertEqual('HELLO WORLD', sayHello.wrap(function(proceed) { + this.assertEqual('HELLO WORLD', sayHello.wrap(function(proceed) { return proceed().toUpperCase(); })()); @@ -208,198 +208,198 @@ }).join(' '); return proceed(); }); - assertEqual('Hello world', 'hello world'.capitalize()); - assertEqual('Hello World', 'hello world'.capitalize(true)); - assertEqual('Hello', 'hello'.capitalize()); + this.assertEqual('Hello world', 'hello world'.capitalize()); + this.assertEqual('Hello World', 'hello world'.capitalize(true)); + this.assertEqual('Hello', 'hello'.capitalize()); String.prototype.capitalize = temp; - }}, + }, - testFunctionDefer: function() { with(this) { + testFunctionDefer: function() { window.deferred = undefined; var deferredFunction = function() { window.deferred = true; }; deferredFunction.defer(); - assertUndefined(window.deferred); - wait(50, function() { - assert(window.deferred); + this.assertUndefined(window.deferred); + this.wait(50, function() { + this.assert(window.deferred); window.deferredValue = 0; var deferredFunction2 = function(arg) { window.deferredValue = arg; }; deferredFunction2.defer('test'); - wait(50, function() { - assertEqual('test', window.deferredValue); + this.wait(50, function() { + this.assertEqual('test', window.deferredValue); }); }); - }}, + }, - testFunctionMethodize: function() { with(this) { + testFunctionMethodize: function() { var Foo = { bar: function(baz) { return baz } }; var baz = { quux: Foo.bar.methodize() }; - assertEqual(Foo.bar.methodize(), baz.quux); - assertEqual(baz, Foo.bar(baz)); - assertEqual(baz, baz.quux()); - }}, + this.assertEqual(Foo.bar.methodize(), baz.quux); + this.assertEqual(baz, Foo.bar(baz)); + this.assertEqual(baz, baz.quux()); + }, - testObjectExtend: function() { with(this) { + testObjectExtend: function() { var object = {foo: 'foo', bar: [1, 2, 3]}; - assertIdentical(object, Object.extend(object)); - assertHashEqual({foo: 'foo', bar: [1, 2, 3]}, object); - assertIdentical(object, Object.extend(object, {bla: 123})); - assertHashEqual({foo: 'foo', bar: [1, 2, 3], bla: 123}, object); - assertHashEqual({foo: 'foo', bar: [1, 2, 3], bla: null}, + this.assertIdentical(object, Object.extend(object)); + this.assertHashEqual({foo: 'foo', bar: [1, 2, 3]}, object); + this.assertIdentical(object, Object.extend(object, {bla: 123})); + this.assertHashEqual({foo: 'foo', bar: [1, 2, 3], bla: 123}, object); + this.assertHashEqual({foo: 'foo', bar: [1, 2, 3], bla: null}, Object.extend(object, {bla: null})); - }}, + }, - testObjectToQueryString: function() { with(this) { - assertEqual('a=A&b=B&c=C&d=D%23', Object.toQueryString({a: 'A', b: 'B', c: 'C', d: 'D#'})); - }}, + testObjectToQueryString: function() { + this.assertEqual('a=A&b=B&c=C&d=D%23', Object.toQueryString({a: 'A', b: 'B', c: 'C', d: 'D#'})); + }, - testObjectClone: function() { with(this) { + testObjectClone: function() { var object = {foo: 'foo', bar: [1, 2, 3]}; - assertNotIdentical(object, Object.clone(object)); - assertHashEqual(object, Object.clone(object)); - assertHashEqual({}, Object.clone()); + this.assertNotIdentical(object, Object.clone(object)); + this.assertHashEqual(object, Object.clone(object)); + this.assertHashEqual({}, Object.clone()); var clone = Object.clone(object); delete clone.bar; - assertHashEqual({foo: 'foo'}, clone, + this.assertHashEqual({foo: 'foo'}, clone, "Optimizing Object.clone perf using prototyping doesn't allow properties to be deleted."); - }}, + }, - testObjectInspect: function() { with(this) { - assertEqual('undefined', Object.inspect()); - assertEqual('undefined', Object.inspect(undefined)); - assertEqual('null', Object.inspect(null)); - assertEqual("'foo\\\\b\\\'ar'", Object.inspect('foo\\b\'ar')); - assertEqual('[]', Object.inspect([])); - assertNothingRaised(function() { Object.inspect(window.Node) }); - }}, + testObjectInspect: function() { + this.assertEqual('undefined', Object.inspect()); + this.assertEqual('undefined', Object.inspect(undefined)); + this.assertEqual('null', Object.inspect(null)); + this.assertEqual("'foo\\\\b\\\'ar'", Object.inspect('foo\\b\'ar')); + this.assertEqual('[]', Object.inspect([])); + this.assertNothingRaised(function() { Object.inspect(window.Node) }); + }, - testObjectToJSON: function() { with(this) { - assertUndefined(Object.toJSON(undefined)); - assertUndefined(Object.toJSON(Prototype.K)); - assertEqual('\"\"', Object.toJSON('')); - assertEqual('[]', Object.toJSON([])); - assertEqual('[\"a\"]', Object.toJSON(['a'])); - assertEqual('[\"a\", 1]', Object.toJSON(['a', 1])); - assertEqual('[\"a\", {\"b\": null}]', Object.toJSON(['a', {'b': null}])); - assertEqual('{\"a\": \"hello!\"}', Object.toJSON({a: 'hello!'})); - assertEqual('{}', Object.toJSON({})); - assertEqual('{}', Object.toJSON({a: undefined, b: undefined, c: Prototype.K})); - assertEqual('{\"b\": [false, true], \"c\": {\"a\": \"hello!\"}}', + testObjectToJSON: function() { + this.assertUndefined(Object.toJSON(undefined)); + this.assertUndefined(Object.toJSON(Prototype.K)); + this.assertEqual('\"\"', Object.toJSON('')); + this.assertEqual('[]', Object.toJSON([])); + this.assertEqual('[\"a\"]', Object.toJSON(['a'])); + this.assertEqual('[\"a\", 1]', Object.toJSON(['a', 1])); + this.assertEqual('[\"a\", {\"b\": null}]', Object.toJSON(['a', {'b': null}])); + this.assertEqual('{\"a\": \"hello!\"}', Object.toJSON({a: 'hello!'})); + this.assertEqual('{}', Object.toJSON({})); + this.assertEqual('{}', Object.toJSON({a: undefined, b: undefined, c: Prototype.K})); + this.assertEqual('{\"b\": [false, true], \"c\": {\"a\": \"hello!\"}}', Object.toJSON({'b': [undefined, false, true, undefined], c: {a: 'hello!'}})); - assertEqual('{\"b\": [false, true], \"c\": {\"a\": \"hello!\"}}', + this.assertEqual('{\"b\": [false, true], \"c\": {\"a\": \"hello!\"}}', Object.toJSON($H({'b': [undefined, false, true, undefined], c: {a: 'hello!'}}))); - assertEqual('true', Object.toJSON(true)); - assertEqual('false', Object.toJSON(false)); - assertEqual('null', Object.toJSON(null)); + this.assertEqual('true', Object.toJSON(true)); + this.assertEqual('false', Object.toJSON(false)); + this.assertEqual('null', Object.toJSON(null)); var sam = new Person('sam'); - assertEqual('-sam', Object.toJSON(sam)); - assertEqual('-sam', sam.toJSON()); + this.assertEqual('-sam', Object.toJSON(sam)); + this.assertEqual('-sam', sam.toJSON()); var element = $('test'); - assertUndefined(Object.toJSON(element)); + this.assertUndefined(Object.toJSON(element)); element.toJSON = function(){return 'I\'m a div with id test'}; - assertEqual('I\'m a div with id test', Object.toJSON(element)); - }}, + this.assertEqual('I\'m a div with id test', Object.toJSON(element)); + }, - testObjectToHTML: function() { with(this) { - assertIdentical('', Object.toHTML()); - assertIdentical('', Object.toHTML('')); - assertIdentical('', Object.toHTML(null)); - assertIdentical('0', Object.toHTML(0)); - assertIdentical('123', Object.toHTML(123)); - assertEqual('hello world', Object.toHTML('hello world')); - assertEqual('hello world', Object.toHTML({toHTML: function() { return 'hello world' }})); - }}, + testObjectToHTML: function() { + this.assertIdentical('', Object.toHTML()); + this.assertIdentical('', Object.toHTML('')); + this.assertIdentical('', Object.toHTML(null)); + this.assertIdentical('0', Object.toHTML(0)); + this.assertIdentical('123', Object.toHTML(123)); + this.assertEqual('hello world', Object.toHTML('hello world')); + this.assertEqual('hello world', Object.toHTML({toHTML: function() { return 'hello world' }})); + }, - testObjectIsArray: function() { with(this) { - assert(Object.isArray([])); - assert(Object.isArray([0])); - assert(Object.isArray([0, 1])); - assert(!Object.isArray({})); - assert(!Object.isArray($('list').childNodes)); - assert(!Object.isArray()); - assert(!Object.isArray('')); - assert(!Object.isArray('foo')); - assert(!Object.isArray(0)); - assert(!Object.isArray(1)); - assert(!Object.isArray(null)); - assert(!Object.isArray(true)); - assert(!Object.isArray(false)); - assert(!Object.isArray(undefined)); - }}, + testObjectIsArray: function() { + this.assert(Object.isArray([])); + this.assert(Object.isArray([0])); + this.assert(Object.isArray([0, 1])); + this.assert(!Object.isArray({})); + this.assert(!Object.isArray($('list').childNodes)); + this.assert(!Object.isArray()); + this.assert(!Object.isArray('')); + this.assert(!Object.isArray('foo')); + this.assert(!Object.isArray(0)); + this.assert(!Object.isArray(1)); + this.assert(!Object.isArray(null)); + this.assert(!Object.isArray(true)); + this.assert(!Object.isArray(false)); + this.assert(!Object.isArray(undefined)); + }, - testObjectIsHash: function() { with(this) { - assert(Object.isHash($H())); - assert(Object.isHash(new Hash())); - assert(!Object.isHash({})); - }}, + testObjectIsHash: function() { + this.assert(Object.isHash($H())); + this.assert(Object.isHash(new Hash())); + this.assert(!Object.isHash({})); + }, - testObjectIsElement: function() { with(this) { - assert(Object.isElement(document.createElement('div'))); - assert(Object.isElement(new Element('div'))); - assert(Object.isElement($('testlog'))); - assert(!Object.isElement(document.createTextNode('bla'))); - }}, + testObjectIsElement: function() { + this.assert(Object.isElement(document.createElement('div'))); + this.assert(Object.isElement(new Element('div'))); + this.assert(Object.isElement($('testlog'))); + this.assert(!Object.isElement(document.createTextNode('bla'))); + }, - testObjectIsFunction: function() { with(this) { - assert(Object.isFunction(function() { })); - assert(Object.isFunction(Class.create())); - assert(!Object.isFunction("a string")); - assert(!Object.isFunction($("testlog"))); - assert(!Object.isFunction([])); - assert(!Object.isFunction({})); - assert(!Object.isFunction(0)); - assert(!Object.isFunction(false)); - assert(!Object.isFunction(undefined)); - }}, + testObjectIsFunction: function() { + this.assert(Object.isFunction(function() { })); + this.assert(Object.isFunction(Class.create())); + this.assert(!Object.isFunction("a string")); + this.assert(!Object.isFunction($("testlog"))); + this.assert(!Object.isFunction([])); + this.assert(!Object.isFunction({})); + this.assert(!Object.isFunction(0)); + this.assert(!Object.isFunction(false)); + this.assert(!Object.isFunction(undefined)); + }, - testObjectIsString: function() { with(this) { - assert(!Object.isString(function() { })); - assert(Object.isString("a string")); - assert(!Object.isString(0)); - assert(!Object.isString([])); - assert(!Object.isString({})); - assert(!Object.isString(false)); - assert(!Object.isString(undefined)); - }}, + testObjectIsString: function() { + this.assert(!Object.isString(function() { })); + this.assert(Object.isString("a string")); + this.assert(!Object.isString(0)); + this.assert(!Object.isString([])); + this.assert(!Object.isString({})); + this.assert(!Object.isString(false)); + this.assert(!Object.isString(undefined)); + }, - testObjectIsNumber: function() { with(this) { - assert(Object.isNumber(0)); - assert(Object.isNumber(1.0)); - assert(!Object.isNumber(function() { })); - assert(!Object.isNumber("a string")); - assert(!Object.isNumber([])); - assert(!Object.isNumber({})); - assert(!Object.isNumber(false)); - assert(!Object.isNumber(undefined)); - }}, + testObjectIsNumber: function() { + this.assert(Object.isNumber(0)); + this.assert(Object.isNumber(1.0)); + this.assert(!Object.isNumber(function() { })); + this.assert(!Object.isNumber("a string")); + this.assert(!Object.isNumber([])); + this.assert(!Object.isNumber({})); + this.assert(!Object.isNumber(false)); + this.assert(!Object.isNumber(undefined)); + }, - testObjectIsUndefined: function() { with(this) { - assert(Object.isUndefined(undefined)); - assert(!Object.isUndefined(null)); - assert(!Object.isUndefined(false)); - assert(!Object.isUndefined(0)); - assert(!Object.isUndefined("")); - assert(!Object.isUndefined(function() { })); - assert(!Object.isUndefined([])); - assert(!Object.isUndefined({})); - }}, + testObjectIsUndefined: function() { + this.assert(Object.isUndefined(undefined)); + this.assert(!Object.isUndefined(null)); + this.assert(!Object.isUndefined(false)); + this.assert(!Object.isUndefined(0)); + this.assert(!Object.isUndefined("")); + this.assert(!Object.isUndefined(function() { })); + this.assert(!Object.isUndefined([])); + this.assert(!Object.isUndefined({})); + }, // sanity check - testDoesntExtendObjectPrototype: function() {with(this) { + testDoesntExtendObjectPrototype: function() { // for-in is supported with objects var iterations = 0, obj = { a: 1, b: 2, c: 3 }; for(property in obj) iterations++; - assertEqual(3, iterations); + this.assertEqual(3, iterations); // for-in is not supported with arrays iterations = 0; var arr = [1,2,3]; for(property in arr) iterations++; - assert(iterations > 3); - }}, + this.assert(iterations > 3); + }, - testPeriodicalExecuterStop: function() {with(this) { + testPeriodicalExecuterStop: function() { var peEventCount = 0; function peEventFired(pe) { if (++peEventCount > 2) pe.stop(); @@ -408,10 +408,10 @@ // peEventFired will stop the PeriodicalExecuter after 3 callbacks new PeriodicalExecuter(peEventFired, 0.05); - wait(600, function() { - assertEqual(3, peEventCount); + this.wait(600, function() { + this.assertEqual(3, peEventCount); }); - }}, + }, testBindAsEventListener: function() { for( var i = 0; i < 10; ++i ){ @@ -429,52 +429,52 @@ } }, - testDateToJSON: function() {with(this) { - assertEqual('\"1970-01-01T00:00:00Z\"', new Date(Date.UTC(1970, 0, 1)).toJSON()); - }}, + testDateToJSON: function() { + this.assertEqual('\"1970-01-01T00:00:00Z\"', new Date(Date.UTC(1970, 0, 1)).toJSON()); + }, - testRegExpEscape: function() {with(this) { - assertEqual('word', RegExp.escape('word')); - assertEqual('\\/slashes\\/', RegExp.escape('/slashes/')); - assertEqual('\\\\backslashes\\\\', RegExp.escape('\\backslashes\\')); - assertEqual('\\\\border of word', RegExp.escape('\\border of word')); + testRegExpEscape: function() { + this.assertEqual('word', RegExp.escape('word')); + this.assertEqual('\\/slashes\\/', RegExp.escape('/slashes/')); + this.assertEqual('\\\\backslashes\\\\', RegExp.escape('\\backslashes\\')); + this.assertEqual('\\\\border of word', RegExp.escape('\\border of word')); - assertEqual('\\(\\?\\:non-capturing\\)', RegExp.escape('(?:non-capturing)')); - assertEqual('non-capturing', new RegExp(RegExp.escape('(?:') + '([^)]+)').exec('(?:non-capturing)')[1]); + this.assertEqual('\\(\\?\\:non-capturing\\)', RegExp.escape('(?:non-capturing)')); + this.assertEqual('non-capturing', new RegExp(RegExp.escape('(?:') + '([^)]+)').exec('(?:non-capturing)')[1]); - assertEqual('\\(\\?\\=positive-lookahead\\)', RegExp.escape('(?=positive-lookahead)')); - assertEqual('positive-lookahead', new RegExp(RegExp.escape('(?=') + '([^)]+)').exec('(?=positive-lookahead)')[1]); + this.assertEqual('\\(\\?\\=positive-lookahead\\)', RegExp.escape('(?=positive-lookahead)')); + this.assertEqual('positive-lookahead', new RegExp(RegExp.escape('(?=') + '([^)]+)').exec('(?=positive-lookahead)')[1]); - assertEqual('\\(\\?<\\=positive-lookbehind\\)', RegExp.escape('(?<=positive-lookbehind)')); - assertEqual('positive-lookbehind', new RegExp(RegExp.escape('(?<=') + '([^)]+)').exec('(?<=positive-lookbehind)')[1]); + this.assertEqual('\\(\\?<\\=positive-lookbehind\\)', RegExp.escape('(?<=positive-lookbehind)')); + this.assertEqual('positive-lookbehind', new RegExp(RegExp.escape('(?<=') + '([^)]+)').exec('(?<=positive-lookbehind)')[1]); - assertEqual('\\(\\?\\!negative-lookahead\\)', RegExp.escape('(?!negative-lookahead)')); - assertEqual('negative-lookahead', new RegExp(RegExp.escape('(?!') + '([^)]+)').exec('(?!negative-lookahead)')[1]); + this.assertEqual('\\(\\?\\!negative-lookahead\\)', RegExp.escape('(?!negative-lookahead)')); + this.assertEqual('negative-lookahead', new RegExp(RegExp.escape('(?!') + '([^)]+)').exec('(?!negative-lookahead)')[1]); - assertEqual('\\(\\?<\\!negative-lookbehind\\)', RegExp.escape('(?', new RegExp(RegExp.escape('
before text
more testing
'}); - assert(getInnerHTML('insertions-container').startsWith('before text
more testing
')); + this.assert(getInnerHTML('insertions-container').startsWith('before text
more testing
')); Element.insert('insertions-main', {after:'after text
more testing
'}); - assert(getInnerHTML('insertions-container').endsWith('after text
more testing
')); + this.assert(getInnerHTML('insertions-container').endsWith('after text
more testing
')); Element.insert('insertions-main', {top:'top text.
more testing
'}); - assert(getInnerHTML('insertions-main').startsWith('top text.
more testing
')); + this.assert(getInnerHTML('insertions-main').startsWith('top text.
more testing
')); Element.insert('insertions-main', {bottom:'bottom text.
more testing
'}); - assert(getInnerHTML('insertions-main').endsWith('bottom text.
more testing
')); - }}, + this.assert(getInnerHTML('insertions-main').endsWith('bottom text.
more testing
')); + }, - testElementInsertWithDOMNode: function() {with(this) { + testElementInsertWithDOMNode: function() { Element.insert('insertions-node-main', {before: createParagraph('node before')}); - assert(getInnerHTML('insertions-node-container').startsWith('node before
')); + this.assert(getInnerHTML('insertions-node-container').startsWith('node before
')); Element.insert('insertions-node-main', {after: createParagraph('node after')}); - assert(getInnerHTML('insertions-node-container').endsWith('node after
')); + this.assert(getInnerHTML('insertions-node-container').endsWith('node after
')); Element.insert('insertions-node-main', {top:createParagraph('node top')}); - assert(getInnerHTML('insertions-node-main').startsWith('node top
')); + this.assert(getInnerHTML('insertions-node-main').startsWith('node top
')); Element.insert('insertions-node-main', {bottom:createParagraph('node bottom')}); - assert(getInnerHTML('insertions-node-main').endsWith('node bottom
')); - assertEqual($('insertions-node-main'), $('insertions-node-main').insert(document.createElement('p'))); - }}, + this.assert(getInnerHTML('insertions-node-main').endsWith('node bottom
')); + this.assertEqual($('insertions-node-main'), $('insertions-node-main').insert(document.createElement('p'))); + }, - testElementInsertWithToElementMethod: function() {with(this) { + testElementInsertWithToElementMethod: function() { Element.insert('insertions-node-main', {toElement: createParagraph.curry('toElement') }); - assert(getInnerHTML('insertions-node-main').endsWith('toelement
')); + this.assert(getInnerHTML('insertions-node-main').endsWith('toelement
')); Element.insert('insertions-node-main', {bottom: {toElement: createParagraph.curry('bottom toElement') }}); - assert(getInnerHTML('insertions-node-main').endsWith('bottom toelement
')); - }}, + this.assert(getInnerHTML('insertions-node-main').endsWith('bottom toelement
')); + }, - testElementInsertWithToHTMLMethod: function() {with(this) { + testElementInsertWithToHTMLMethod: function() { Element.insert('insertions-node-main', {toHTML: function() { return 'toHTML
'} }); - assert(getInnerHTML('insertions-node-main').endsWith('tohtml
')); + this.assert(getInnerHTML('insertions-node-main').endsWith('tohtml
')); Element.insert('insertions-node-main', {bottom: {toHTML: function() { return 'bottom toHTML
'} }}); - assert(getInnerHTML('insertions-node-main').endsWith('bottom tohtml
')); - }}, + this.assert(getInnerHTML('insertions-node-main').endsWith('bottom tohtml
')); + }, - testElementInsertWithNonString: function() {with(this) { + testElementInsertWithNonString: function() { Element.insert('insertions-main', {bottom:3}); - assert(getInnerHTML('insertions-main').endsWith('3')); - }}, + this.assert(getInnerHTML('insertions-main').endsWith('3')); + }, - testElementInsertInTables: function() {with(this) { + testElementInsertInTables: function() { Element.insert('second_row', {after:'3
')); - assert(getInnerHTML('element-insertions-multiple-container').endsWith('4')); + this.assert(getInnerHTML('element-insertions-multiple-main').startsWith('1')); + this.assert(getInnerHTML('element-insertions-multiple-main').endsWith('2')); + this.assert(getInnerHTML('element-insertions-multiple-container').startsWith('3
')); + this.assert(getInnerHTML('element-insertions-multiple-container').endsWith('4')); $('element-insertions-main').update('test'); $('element-insertions-main').insert(null); $('element-insertions-main').insert({bottom:null}); - assertEqual('test', getInnerHTML('element-insertions-main')); + this.assertEqual('test', getInnerHTML('element-insertions-main')); $('element-insertions-main').insert(1337); - assertEqual('test1337', getInnerHTML('element-insertions-main')); - }}, + this.assertEqual('test1337', getInnerHTML('element-insertions-main')); + }, - testNewElementInsert: function() {with(this) { + testNewElementInsert: function() { var container = new Element('div'); element = new Element('div'); container.insert(element); element.insert({ before: 'a paragraph
' }); - assertEqual('a paragraph
', getInnerHTML(container)); + this.assertEqual('a paragraph
', getInnerHTML(container)); element.insert({ after: 'some text' }); - assertEqual('a paragraph
some text', getInnerHTML(container)); + this.assertEqual('a paragraph
some text', getInnerHTML(container)); element.insert({ top: 'a paragraph
' }); - assertEqual('a paragraph
', getInnerHTML(element)); + this.assertEqual('a paragraph
', getInnerHTML(element)); element.insert('some text'); - assertEqual('a paragraph
some text', getInnerHTML(element)); - }}, + this.assertEqual('a paragraph
some text', getInnerHTML(element)); + }, - testInsertionBackwardsCompatibility: function() {with(this) { + testInsertionBackwardsCompatibility: function() { new Insertion.Before('element-insertions-main', 'some backward-compatibility testing before'); - assert(getInnerHTML('element-insertions-container').include('some backward-compatibility testing before')); + this.assert(getInnerHTML('element-insertions-container').include('some backward-compatibility testing before')); new Insertion.After('element-insertions-main', 'some backward-compatibility testing after'); - assert(getInnerHTML('element-insertions-container').include('some backward-compatibility testing after')); + this.assert(getInnerHTML('element-insertions-container').include('some backward-compatibility testing after')); new Insertion.Top('element-insertions-main', 'some backward-compatibility testing top'); - assert(getInnerHTML('element-insertions-main').startsWith('some backward-compatibility testing top')); + this.assert(getInnerHTML('element-insertions-main').startsWith('some backward-compatibility testing top')); new Insertion.Bottom('element-insertions-main', 'some backward-compatibility testing bottom'); - assert(getInnerHTML('element-insertions-main').endsWith('some backward-compatibility testing bottom')); - }}, + this.assert(getInnerHTML('element-insertions-main').endsWith('some backward-compatibility testing bottom')); + }, - testElementWrap: function() {with(this) { + testElementWrap: function() { var element = $('wrap'), parent = document.createElement('div'); element.wrap(); - assert(getInnerHTML('wrap-container').startsWith('\ntestVar="hello!";\n'+'script>');
- assertEqual('hello from div!',$('testdiv').innerHTML);
- wait(100,function(){
- assertEqual('hello!',testVar);
+ this.assertEqual('hello from div!',$('testdiv').innerHTML);
+ this.wait(100,function(){
+ this.assertEqual('hello!',testVar);
Element.update('testdiv','another hello from div!\n
diff --git a/test/unit/enumerable.html b/test/unit/enumerable.html
index c2e29e4..71e88af 100644
--- a/test/unit/enumerable.html
+++ b/test/unit/enumerable.html
@@ -66,261 +66,261 @@
}
new Test.Unit.Runner({
- testEachBreak: function() {with(this) {
+ testEachBreak: function() {
var result = 0;
Fixtures.Basic.each(function(value) {
if ((result = value) == 2) throw $break;
});
- assertEqual(2, result);
- }},
+ this.assertEqual(2, result);
+ },
- testEachReturnActsAsContinue: function() {with(this) {
+ testEachReturnActsAsContinue: function() {
var results = [];
Fixtures.Basic.each(function(value) {
if (value == 2) return;
results.push(value);
});
- assertEqual('1, 3', results.join(', '));
- }},
+ this.assertEqual('1, 3', results.join(', '));
+ },
- testEachChaining: function() {with(this) {
- assertEqual(Fixtures.Primes, Fixtures.Primes.each(Prototype.emptyFunction));
- assertEqual(3, Fixtures.Basic.each(Prototype.emptyFunction).length);
- }},
+ testEachChaining: function() {
+ this.assertEqual(Fixtures.Primes, Fixtures.Primes.each(Prototype.emptyFunction));
+ this.assertEqual(3, Fixtures.Basic.each(Prototype.emptyFunction).length);
+ },
- testEnumContext: function() {with(this) {
+ testEnumContext: function() {
var results = [];
Fixtures.Basic.each(function(value) {
results.push(value * this.i);
}, { i: 2 });
- assertEqual('2 4 6', results.join(' '));
+ this.assertEqual('2 4 6', results.join(' '));
- assert(Fixtures.Basic.all(function(value){
+ this.assert(Fixtures.Basic.all(function(value){
return value >= this.min && value <= this.max;
}, { min: 1, max: 3 }));
- assert(!Fixtures.Basic.all(function(value){
+ this.assert(!Fixtures.Basic.all(function(value){
return value >= this.min && value <= this.max;
}));
- assert(Fixtures.Basic.any(function(value){
+ this.assert(Fixtures.Basic.any(function(value){
return value == this.target_value;
}, { target_value: 2 }));
- }},
+ },
- testAny: function() {with(this) {
- assert(!([].any()));
+ testAny: function() {
+ this.assert(!([].any()));
- assert([true, true, true].any());
- assert([true, false, false].any());
- assert(![false, false, false].any());
+ this.assert([true, true, true].any());
+ this.assert([true, false, false].any());
+ this.assert(![false, false, false].any());
- assert(Fixtures.Basic.any(function(value) {
+ this.assert(Fixtures.Basic.any(function(value) {
return value > 2;
}));
- assert(!Fixtures.Basic.any(function(value) {
+ this.assert(!Fixtures.Basic.any(function(value) {
return value > 5;
}));
- }},
+ },
- testAll: function() {with(this) {
- assert([].all());
+ testAll: function() {
+ this.assert([].all());
- assert([true, true, true].all());
- assert(![true, false, false].all());
- assert(![false, false, false].all());
+ this.assert([true, true, true].all());
+ this.assert(![true, false, false].all());
+ this.assert(![false, false, false].all());
- assert(Fixtures.Basic.all(function(value) {
+ this.assert(Fixtures.Basic.all(function(value) {
return value > 0;
}));
- assert(!Fixtures.Basic.all(function(value) {
+ this.assert(!Fixtures.Basic.all(function(value) {
return value > 1;
}));
- }},
+ },
- testCollect: function() {with(this) {
- assertEqual(Fixtures.Nicknames.join(', '),
+ testCollect: function() {
+ this.assertEqual(Fixtures.Nicknames.join(', '),
Fixtures.People.collect(function(person) {
return person.nickname;
}).join(", "));
- assertEqual(26, Fixtures.Primes.map().length);
- }},
+ this.assertEqual(26, Fixtures.Primes.map().length);
+ },
- testDetect: function() {with(this) {
- assertEqual('Marcel Molina Jr.',
+ testDetect: function() {
+ this.assertEqual('Marcel Molina Jr.',
Fixtures.People.detect(function(person) {
return person.nickname.match(/no/);
}).name);
- }},
+ },
- testEachSlice: function() {with(this) {
- assertEnumEqual([], [].eachSlice(2));
- assertEqual(1, [1].eachSlice(1).length);
- assertEnumEqual([1], [1].eachSlice(1)[0]);
- assertEqual(2, Fixtures.Basic.eachSlice(2).length);
- assertEnumEqual(
+ testEachSlice: function() {
+ this.assertEnumEqual([], [].eachSlice(2));
+ this.assertEqual(1, [1].eachSlice(1).length);
+ this.assertEnumEqual([1], [1].eachSlice(1)[0]);
+ this.assertEqual(2, Fixtures.Basic.eachSlice(2).length);
+ this.assertEnumEqual(
[3, 2, 1, 11, 7, 5, 19, 17, 13, 31, 29, 23, 43, 41, 37, 59, 53, 47, 71, 67, 61, 83, 79, 73, 97, 89],
Fixtures.Primes.eachSlice( 3, function(slice){ return slice.reverse() }).flatten()
);
- assertEnumEqual(Fixtures.Basic, Fixtures.Basic.eachSlice(-10));
- assertEnumEqual(Fixtures.Basic, Fixtures.Basic.eachSlice(0));
- assertNotIdentical(Fixtures.Basic, Fixtures.Basic.eachSlice(0));
- }},
+ this.assertEnumEqual(Fixtures.Basic, Fixtures.Basic.eachSlice(-10));
+ this.assertEnumEqual(Fixtures.Basic, Fixtures.Basic.eachSlice(0));
+ this.assertNotIdentical(Fixtures.Basic, Fixtures.Basic.eachSlice(0));
+ },
- testEachWithIndex: function() {with(this) {
+ testEachWithIndex: function() {
var nicknames = [], indexes = [];
Fixtures.People.each(function(person, index) {
nicknames.push(person.nickname);
indexes.push(index);
});
- assertEqual(Fixtures.Nicknames.join(', '),
+ this.assertEqual(Fixtures.Nicknames.join(', '),
nicknames.join(', '));
- assertEqual('0, 1, 2, 3', indexes.join(', '));
- }},
+ this.assertEqual('0, 1, 2, 3', indexes.join(', '));
+ },
- testFindAll: function() {with(this) {
- assertEqual(Fixtures.Primes.join(', '),
+ testFindAll: function() {
+ this.assertEqual(Fixtures.Primes.join(', '),
Fixtures.Z.findAll(prime).join(', '));
- }},
+ },
- testGrep: function() {with(this) {
- assertEqual('noradio, htonl',
+ testGrep: function() {
+ this.assertEqual('noradio, htonl',
Fixtures.Nicknames.grep(/o/).join(", "));
- assertEqual('NORADIO, HTONL',
+ this.assertEqual('NORADIO, HTONL',
Fixtures.Nicknames.grep(/o/, function(nickname) {
return nickname.toUpperCase();
}).join(", "))
- assertEnumEqual($('grepHeader', 'grepCell'),
+ this.assertEnumEqual($('grepHeader', 'grepCell'),
$('grepTable', 'grepTBody', 'grepRow', 'grepHeader', 'grepCell').grep(new Selector('.cell')));
- }},
+ },
- testInclude: function() {with(this) {
- assert(Fixtures.Nicknames.include('sam-'));
- assert(Fixtures.Nicknames.include('noradio'));
- assert(!Fixtures.Nicknames.include('gmosx'));
- assert(Fixtures.Basic.include(2));
- assert(Fixtures.Basic.include('2'));
- assert(!Fixtures.Basic.include('4'));
- }},
+ testInclude: function() {
+ this.assert(Fixtures.Nicknames.include('sam-'));
+ this.assert(Fixtures.Nicknames.include('noradio'));
+ this.assert(!Fixtures.Nicknames.include('gmosx'));
+ this.assert(Fixtures.Basic.include(2));
+ this.assert(Fixtures.Basic.include('2'));
+ this.assert(!Fixtures.Basic.include('4'));
+ },
- testInGroupsOf: function() { with(this) {
- assertEnumEqual([], [].inGroupsOf(3));
+ testInGroupsOf: function() {
+ this.assertEnumEqual([], [].inGroupsOf(3));
var arr = [1, 2, 3, 4, 5, 6].inGroupsOf(3);
- assertEqual(2, arr.length);
- assertEnumEqual([1, 2, 3], arr[0]);
- assertEnumEqual([4, 5, 6], arr[1]);
+ this.assertEqual(2, arr.length);
+ this.assertEnumEqual([1, 2, 3], arr[0]);
+ this.assertEnumEqual([4, 5, 6], arr[1]);
arr = [1, 2, 3, 4, 5, 6].inGroupsOf(4);
- assertEqual(2, arr.length);
- assertEnumEqual([1, 2, 3, 4], arr[0]);
- assertEnumEqual([5, 6, null, null], arr[1]);
+ this.assertEqual(2, arr.length);
+ this.assertEnumEqual([1, 2, 3, 4], arr[0]);
+ this.assertEnumEqual([5, 6, null, null], arr[1]);
var basic = Fixtures.Basic
arr = basic.inGroupsOf(4,'x');
- assertEqual(1, arr.length);
- assertEnumEqual([1, 2, 3, 'x'], arr[0]);
+ this.assertEqual(1, arr.length);
+ this.assertEnumEqual([1, 2, 3, 'x'], arr[0]);
- assertEnumEqual([1,2,3,'a'], basic.inGroupsOf(2, 'a').flatten());
+ this.assertEnumEqual([1,2,3,'a'], basic.inGroupsOf(2, 'a').flatten());
arr = basic.inGroupsOf(5, '');
- assertEqual(1, arr.length);
- assertEnumEqual([1, 2, 3, '', ''], arr[0]);
+ this.assertEqual(1, arr.length);
+ this.assertEnumEqual([1, 2, 3, '', ''], arr[0]);
- assertEnumEqual([1,2,3,0], basic.inGroupsOf(2, 0).flatten());
- assertEnumEqual([1,2,3,false], basic.inGroupsOf(2, false).flatten());
- }},
+ this.assertEnumEqual([1,2,3,0], basic.inGroupsOf(2, 0).flatten());
+ this.assertEnumEqual([1,2,3,false], basic.inGroupsOf(2, false).flatten());
+ },
- testInject: function() {with(this) {
- assertEqual(1061,
+ testInject: function() {
+ this.assertEqual(1061,
Fixtures.Primes.inject(0, function(sum, value) {
return sum + value;
}));
- }},
+ },
- testInvoke: function() {with(this) {
+ testInvoke: function() {
var result = [[2, 1, 3], [6, 5, 4]].invoke('sort');
- assertEqual(2, result.length);
- assertEqual('1, 2, 3', result[0].join(', '));
- assertEqual('4, 5, 6', result[1].join(', '));
+ this.assertEqual(2, result.length);
+ this.assertEqual('1, 2, 3', result[0].join(', '));
+ this.assertEqual('4, 5, 6', result[1].join(', '));
result = result.invoke('invoke', 'toString', 2);
- assertEqual('1, 10, 11', result[0].join(', '));
- assertEqual('100, 101, 110', result[1].join(', '));
- }},
+ this.assertEqual('1, 10, 11', result[0].join(', '));
+ this.assertEqual('100, 101, 110', result[1].join(', '));
+ },
- testMax: function() {with(this) {
- assertEqual(100, Fixtures.Z.max());
- assertEqual(97, Fixtures.Primes.max());
- assertEqual(2, [ -9, -8, -7, -6, -4, -3, -2, 0, -1, 2 ].max());
- assertEqual('sam-', Fixtures.Nicknames.max()); // ?s > ?U
- }},
+ testMax: function() {
+ this.assertEqual(100, Fixtures.Z.max());
+ this.assertEqual(97, Fixtures.Primes.max());
+ this.assertEqual(2, [ -9, -8, -7, -6, -4, -3, -2, 0, -1, 2 ].max());
+ this.assertEqual('sam-', Fixtures.Nicknames.max()); // ?s > ?U
+ },
- testMin: function() {with(this) {
- assertEqual(1, Fixtures.Z.min());
- assertEqual(0, [ 1, 2, 3, 4, 5, 6, 7, 8, 0, 9 ].min());
- assertEqual('Ulysses', Fixtures.Nicknames.min()); // ?U < ?h
- }},
+ testMin: function() {
+ this.assertEqual(1, Fixtures.Z.min());
+ this.assertEqual(0, [ 1, 2, 3, 4, 5, 6, 7, 8, 0, 9 ].min());
+ this.assertEqual('Ulysses', Fixtures.Nicknames.min()); // ?U < ?h
+ },
- testPartition: function() {with(this) {
+ testPartition: function() {
var result = Fixtures.People.partition(function(person) {
return person.name.length < 15;
}).invoke('pluck', 'nickname');
- assertEqual(2, result.length);
- assertEqual('sam-, htonl', result[0].join(', '));
- assertEqual('noradio, Ulysses', result[1].join(', '));
- }},
+ this.assertEqual(2, result.length);
+ this.assertEqual('sam-, htonl', result[0].join(', '));
+ this.assertEqual('noradio, Ulysses', result[1].join(', '));
+ },
- testPluck: function() {with(this) {
- assertEqual(Fixtures.Nicknames.join(', '),
+ testPluck: function() {
+ this.assertEqual(Fixtures.Nicknames.join(', '),
Fixtures.People.pluck('nickname').join(', '));
- }},
+ },
- testReject: function() {with(this) {
- assertEqual(0,
+ testReject: function() {
+ this.assertEqual(0,
Fixtures.Nicknames.reject(Prototype.K).length);
- assertEqual('sam-, noradio, htonl',
+ this.assertEqual('sam-, noradio, htonl',
Fixtures.Nicknames.reject(function(nickname) {
return nickname != nickname.toLowerCase();
}).join(', '));
- }},
+ },
- testSortBy: function() {with(this) {
- assertEqual('htonl, noradio, sam-, Ulysses',
+ testSortBy: function() {
+ this.assertEqual('htonl, noradio, sam-, Ulysses',
Fixtures.People.sortBy(function(value) {
return value.nickname.toLowerCase();
}).pluck('nickname').join(', '));
- }},
+ },
- testToArray: function() {with(this) {
+ testToArray: function() {
var result = Fixtures.People.toArray();
- assert(result != Fixtures.People); // they're different objects...
- assertEqual(Fixtures.Nicknames.join(', '),
+ this.assert(result != Fixtures.People); // they're different objects...
+ this.assertEqual(Fixtures.Nicknames.join(', '),
result.pluck('nickname').join(', ')); // but the values are the same
- }},
+ },
- testZip: function() {with(this) {
+ testZip: function() {
var result = [1, 2, 3].zip([4, 5, 6], [7, 8, 9]);
- assertEqual('[[1, 4, 7], [2, 5, 8], [3, 6, 9]]', result.inspect());
+ this.assertEqual('[[1, 4, 7], [2, 5, 8], [3, 6, 9]]', result.inspect());
result = [1, 2, 3].zip([4, 5, 6], [7, 8, 9], function(array) { return array.reverse() });
- assertEqual('[[7, 4, 1], [8, 5, 2], [9, 6, 3]]', result.inspect());
- }},
+ this.assertEqual('[[7, 4, 1], [8, 5, 2], [9, 6, 3]]', result.inspect());
+ },
- testSize: function() {with(this) {
- assertEqual(4, Fixtures.People.size());
- assertEqual(4, Fixtures.Nicknames.size());
- assertEqual(26, Fixtures.Primes.size());
- assertEqual(0, [].size());
- }}
+ testSize: function() {
+ this.assertEqual(4, Fixtures.People.size());
+ this.assertEqual(4, Fixtures.Nicknames.size());
+ this.assertEqual(26, Fixtures.Primes.size());
+ this.assertEqual(0, [].size());
+ }
});
// ]]>
diff --git a/test/unit/event.html b/test/unit/event.html
index 7d4f15a..17552f9 100644
--- a/test/unit/event.html
+++ b/test/unit/event.html
@@ -37,47 +37,47 @@
new Test.Unit.Runner({
// test firing an event and observing it on the element it's fired from
- testCustomEventFiring: function() { with(this) {
+ testCustomEventFiring: function() {
var span = $("span"), fired = false, observer = function(event) {
- assertEqual(span, event.element());
- assertEqual(1, event.memo.index);
+ this.assertEqual(span, event.element());
+ this.assertEqual(1, event.memo.index);
fired = true;
- }
+ }.bind(this);
span.observe("test:somethingHappened", observer);
span.fire("test:somethingHappened", { index: 1 });
- assert(fired);
+ this.assert(fired);
fired = false;
span.fire("test:somethingElseHappened");
- assert(!fired);
+ this.assert(!fired);
span.stopObserving("test:somethingHappened", observer);
span.fire("test:somethingHappened");
- assert(!fired);
- }},
+ this.assert(!fired);
+ },
// test firing an event and observing it on a containing element
- testCustomEventBubbling: function() { with(this) {
+ testCustomEventBubbling: function() {
var span = $("span"), outer = $("outer"), fired = false, observer = function(event) {
- assertEqual(span, event.element());
+ this.assertEqual(span, event.element());
fired = true;
- };
+ }.bind(this);
outer.observe("test:somethingHappened", observer);
span.fire("test:somethingHappened");
- assert(fired);
+ this.assert(fired);
fired = false;
span.fire("test:somethingElseHappened");
- assert(!fired);
+ this.assert(!fired);
outer.stopObserving("test:somethingHappened", observer);
span.fire("test:somethingHappened");
- assert(!fired);
- }},
+ this.assert(!fired);
+ },
- testCustomEventCanceling: function() { with(this) {
+ testCustomEventCanceling: function() {
var span = $("span"), outer = $("outer"), inner = $("inner");
var fired = false, stopped = false;
@@ -93,161 +93,161 @@
inner.observe("test:somethingHappened", innerObserver);
outer.observe("test:somethingHappened", outerObserver);
span.fire("test:somethingHappened");
- assert(stopped);
- assert(!fired);
+ this.assert(stopped);
+ this.assert(!fired);
fired = stopped = false;
inner.stopObserving("test:somethingHappened", innerObserver);
span.fire("test:somethingHappened");
- assert(!stopped);
- assert(fired);
+ this.assert(!stopped);
+ this.assert(fired);
outer.stopObserving("test:somethingHappened", outerObserver);
- }},
+ },
- testEventObjectIsExtended: function() { with(this) {
+ testEventObjectIsExtended: function() {
var span = $("span"), event, observedEvent, observer = function(e) { observedEvent = e };
span.observe("test:somethingHappened", observer);
event = span.fire("test:somethingHappened");
- assertEqual(event, observedEvent);
- assertEqual(Event.Methods.stop.methodize(), event.stop);
+ this.assertEqual(event, observedEvent);
+ this.assertEqual(Event.Methods.stop.methodize(), event.stop);
span.stopObserving("test:somethingHappened", observer);
event = span.fire("test:somethingHappenedButNoOneIsListening");
- assertEqual(Event.Methods.stop.methodize(), event.stop);
- }},
+ this.assertEqual(Event.Methods.stop.methodize(), event.stop);
+ },
- testEventObserversAreBoundToTheObservedElement: function() { with(this) {
+ testEventObserversAreBoundToTheObservedElement: function() {
var span = $("span"), target, observer = function() { target = this };
span.observe("test:somethingHappened", observer);
span.fire("test:somethingHappened");
span.stopObserving("test:somethingHappened", observer);
- assertEqual(span, target);
+ this.assertEqual(span, target);
target = null;
var outer = $("outer");
outer.observe("test:somethingHappened", observer);
span.fire("test:somethingHappened");
outer.stopObserving("test:somethingHappened", observer);
- assertEqual(outer, target);
- }},
+ this.assertEqual(outer, target);
+ },
- testMultipleCustomEventObserversWithTheSameHandler: function() { with(this) {
+ testMultipleCustomEventObserversWithTheSameHandler: function() {
var span = $("span"), count = 0, observer = function() { count++ };
span.observe("test:somethingHappened", observer);
span.observe("test:somethingElseHappened", observer);
span.fire("test:somethingHappened");
- assertEqual(1, count);
+ this.assertEqual(1, count);
span.fire("test:somethingElseHappened");
- assertEqual(2, count);
- }},
+ this.assertEqual(2, count);
+ },
- testStopObservingWithoutArguments: function() { with(this) {
+ testStopObservingWithoutArguments: function() {
var span = $("span"), count = 0, observer = function() { count++ };
span.observe("test:somethingHappened", observer);
span.observe("test:somethingElseHappened", observer);
span.stopObserving();
span.fire("test:somethingHappened");
- assertEqual(0, count);
+ this.assertEqual(0, count);
span.fire("test:somethingElseHappened");
- assertEqual(0, count);
- }},
+ this.assertEqual(0, count);
+ },
- testStopObservingWithoutHandlerArgument: function() { with(this) {
+ testStopObservingWithoutHandlerArgument: function() {
var span = $("span"), count = 0, observer = function() { count++ };
span.observe("test:somethingHappened", observer);
span.observe("test:somethingElseHappened", observer);
span.stopObserving("test:somethingHappened");
span.fire("test:somethingHappened");
- assertEqual(0, count);
+ this.assertEqual(0, count);
span.fire("test:somethingElseHappened");
- assertEqual(1, count);
+ this.assertEqual(1, count);
span.stopObserving("test:somethingElseHappened");
span.fire("test:somethingElseHappened");
- assertEqual(1, count);
- }},
+ this.assertEqual(1, count);
+ },
- testStopObservingRemovesHandlerFromCache: function() { with(this) {
+ testStopObservingRemovesHandlerFromCache: function() {
var span = $("span"), observer = function() { }, eventID;
span.observe("test:somethingHappened", observer);
eventID = span._prototypeEventID;
- assert(Event.cache[eventID]);
- assert(Object.isArray(Event.cache[eventID]["test:somethingHappened"]));
- assertEqual(1, Event.cache[eventID]["test:somethingHappened"].length);
+ this.assert(Event.cache[eventID]);
+ this.assert(Object.isArray(Event.cache[eventID]["test:somethingHappened"]));
+ this.assertEqual(1, Event.cache[eventID]["test:somethingHappened"].length);
span.stopObserving("test:somethingHappened", observer);
- assert(Event.cache[eventID]);
- assert(Object.isArray(Event.cache[eventID]["test:somethingHappened"]));
- assertEqual(0, Event.cache[eventID]["test:somethingHappened"].length);
- }},
+ this.assert(Event.cache[eventID]);
+ this.assert(Object.isArray(Event.cache[eventID]["test:somethingHappened"]));
+ this.assertEqual(0, Event.cache[eventID]["test:somethingHappened"].length);
+ },
- testObserveAndStopObservingAreChainable: function() { with(this) {
+ testObserveAndStopObservingAreChainable: function() {
var span = $("span"), observer = function() { };
- assertEqual(span, span.observe("test:somethingHappened", observer));
- assertEqual(span, span.stopObserving("test:somethingHappened", observer));
+ this.assertEqual(span, span.observe("test:somethingHappened", observer));
+ this.assertEqual(span, span.stopObserving("test:somethingHappened", observer));
span.observe("test:somethingHappened", observer);
- assertEqual(span, span.stopObserving("test:somethingHappened"));
+ this.assertEqual(span, span.stopObserving("test:somethingHappened"));
span.observe("test:somethingHappened", observer);
- assertEqual(span, span.stopObserving());
- assertEqual(span, span.stopObserving()); // assert it again, after there are no observers
+ this.assertEqual(span, span.stopObserving());
+ this.assertEqual(span, span.stopObserving()); // assert it again, after there are no observers
span.observe("test:somethingHappened", observer);
- assertEqual(span, span.observe("test:somethingHappened", observer)); // try to reuse the same observer
+ this.assertEqual(span, span.observe("test:somethingHappened", observer)); // try to reuse the same observer
span.stopObserving();
- }},
+ },
- testDocumentLoaded: function() { with(this) {
- assert(!documentLoaded);
- assert(document.loaded);
- }},
+ testDocumentLoaded: function() {
+ this.assert(!documentLoaded);
+ this.assert(document.loaded);
+ },
- testDocumentContentLoadedEventFiresBeforeWindowLoad: function() { with(this) {
- assert(eventResults.contentLoaded, "contentLoaded");
- assert(eventResults.contentLoaded.endOfDocument, "contentLoaded.endOfDocument");
- assert(!eventResults.contentLoaded.windowLoad, "!contentLoaded.windowLoad");
- assert(eventResults.windowLoad, "windowLoad");
- assert(eventResults.windowLoad.endOfDocument, "windowLoad.endOfDocument");
- assert(eventResults.windowLoad.contentLoaded, "windowLoad.contentLoaded");
- }},
+ testDocumentContentLoadedEventFiresBeforeWindowLoad: function() {
+ this.assert(eventResults.contentLoaded, "contentLoaded");
+ this.assert(eventResults.contentLoaded.endOfDocument, "contentLoaded.endOfDocument");
+ this.assert(!eventResults.contentLoaded.windowLoad, "!contentLoaded.windowLoad");
+ this.assert(eventResults.windowLoad, "windowLoad");
+ this.assert(eventResults.windowLoad.endOfDocument, "windowLoad.endOfDocument");
+ this.assert(eventResults.windowLoad.contentLoaded, "windowLoad.contentLoaded");
+ },
- testEventStopped: function() { with(this) {
+ testEventStopped: function() {
var span = $("span"), event;
span.observe("test:somethingHappened", function() { });
event = span.fire("test:somethingHappened");
- assert(!event.stopped, "event.stopped should be false with an empty observer");
+ this.assert(!event.stopped, "event.stopped should be false with an empty observer");
span.stopObserving("test:somethingHappened");
span.observe("test:somethingHappened", function(e) { e.stop() });
event = span.fire("test:somethingHappened");
- assert(event.stopped, "event.stopped should be true for an observer that calls stop");
+ this.assert(event.stopped, "event.stopped should be true for an observer that calls stop");
span.stopObserving("test:somethingHappened");
- }},
+ },
- testEventFindElement: function() { with(this) {
+ testEventFindElement: function() {
var span = $("span"), event;
event = span.fire("test:somethingHappened");
- assertElementMatches(event.findElement(), 'span#span');
- assertElementMatches(event.findElement('span'), 'span#span');
- assertElementMatches(event.findElement('p'), 'p#inner');
- assertEqual(null, event.findElement('div.does_not_exist'));
- assertElementMatches(event.findElement('.does_not_exist, span'), 'span#span');
- }},
+ this.assertElementMatches(event.findElement(), 'span#span');
+ this.assertElementMatches(event.findElement('span'), 'span#span');
+ this.assertElementMatches(event.findElement('p'), 'p#inner');
+ this.assertEqual(null, event.findElement('div.does_not_exist'));
+ this.assertElementMatches(event.findElement('.does_not_exist, span'), 'span#span');
+ },
- testEventIDDuplication: function() { with(this) {
+ testEventIDDuplication: function() {
$('container').down().observe("test:somethingHappened", Prototype.emptyFunction);
$('container').innerHTML += $('container').innerHTML;
- assertUndefined($('container').down(1)._prototypeEventID);
- }}
+ this.assertUndefined($('container').down(1)._prototypeEventID);
+ }
});
document.observe("dom:loaded", function(event) {
diff --git a/test/unit/form.html b/test/unit/form.html
index 81c1deb..1204775 100644
--- a/test/unit/form.html
+++ b/test/unit/form.html
@@ -149,29 +149,29 @@
// Make sure to set defaults in the test forms, as some browsers override this
// with previously entered values on page reload
- setup: function(){ with(this) {
+ setup: function(){
$$('form').each(function(f){ f.reset() });
// hidden value does not reset (for some reason)
$('bigform')['tf_hidden'].value = '';
- }},
+ },
- testDollarF: function(){ with(this) {
- assertEqual("4", $F("input_enabled"));
- }},
+ testDollarF: function(){
+ this.assertEqual("4", $F("input_enabled"));
+ },
- testFormElementEventObserver: function(){ with(this) {
+ testFormElementEventObserver: function(){
var callbackCounter = 0;
var observer = new Form.Element.EventObserver('input_enabled', function(){
callbackCounter++;
});
- assertEqual(0, callbackCounter);
+ this.assertEqual(0, callbackCounter);
$('input_enabled').value = 'boo!';
observer.onElementEvent(); // can't test the event directly, simulating
- assertEqual(1, callbackCounter);
- }},
+ this.assertEqual(1, callbackCounter);
+ },
- testFormElementObserver: function(){ with(this) {
+ testFormElementObserver: function(){
var timedCounter = 0;
// First part: regular field
var observer = new Form.Element.Observer('input_enabled', 0.5, function() {
@@ -179,18 +179,18 @@
});
// Test it's unchanged yet
- assertEqual(0, timedCounter);
+ this.assertEqual(0, timedCounter);
// Test it doesn't change on first check
- wait(550, function() {
- assertEqual(0, timedCounter);
+ this.wait(550, function() {
+ this.assertEqual(0, timedCounter);
// Change, test it doesn't immediately change
$('input_enabled').value = 'yowza!';
- assertEqual(0, timedCounter);
+ this.assertEqual(0, timedCounter);
// Test it changes on next check, but not again on the next
- wait(550, function() {
- assertEqual(1, timedCounter);
- wait(550, function() {
- assertEqual(1, timedCounter);
+ this.wait(550, function() {
+ this.assertEqual(1, timedCounter);
+ this.wait(550, function() {
+ this.assertEqual(1, timedCounter);
observer.stop();
});
});
@@ -206,27 +206,27 @@
});
// Test it's unchanged yet
- assertEqual(0, timedCounter);
+ this.assertEqual(0, timedCounter);
// Test it doesn't change on first check
- wait(550, function() {
- assertEqual(0, timedCounter);
+ this.wait(550, function() {
+ this.assertEqual(0, timedCounter);
// Change, test it doesn't immediately change
// NOTE: it is important that the 3rd be re-selected, for the
// serialize form to obtain the expected value :-)
$('multiSel1_opt3').selected = true;
- assertEqual(0, timedCounter);
+ this.assertEqual(0, timedCounter);
// Test it changes on next check, but not again on the next
- wait(550, function() {
- assertEqual(1, timedCounter);
- wait(550, function() {
- assertEqual(1, timedCounter);
+ this.wait(550, function() {
+ this.assertEqual(1, timedCounter);
+ this.wait(550, function() {
+ this.assertEqual(1, timedCounter);
observer.stop();
});
});
});
- }},
+ },
- testFormObserver: function(){ with(this) {
+ testFormObserver: function(){
var timedCounter = 0;
// should work the same way was Form.Element.Observer
var observer = new Form.Observer('form', 0.5, function(form, value) {
@@ -234,69 +234,69 @@
});
// Test it's unchanged yet
- assertEqual(0, timedCounter);
+ this.assertEqual(0, timedCounter);
// Test it doesn't change on first check
- wait(550, function() {
- assertEqual(0, timedCounter);
+ this.wait(550, function() {
+ this.assertEqual(0, timedCounter);
// Change, test it doesn't immediately change
$('input_enabled').value = 'yowza!';
- assertEqual(0, timedCounter);
+ this.assertEqual(0, timedCounter);
// Test it changes on next check, but not again on the next
- wait(550, function() {
- assertEqual(1, timedCounter);
- wait(550, function() {
- assertEqual(1, timedCounter);
+ this.wait(550, function() {
+ this.assertEqual(1, timedCounter);
+ this.wait(550, function() {
+ this.assertEqual(1, timedCounter);
observer.stop();
});
});
});
- }},
+ },
- testFormEnabling: function(){ with(this) {
+ testFormEnabling: function(){
var form = $('bigform')
var input1 = $('dummy_disabled');
var input2 = $('focus_text');
- assertDisabled(input1);
- assertEnabled(input2);
+ this.assertDisabled(input1);
+ this.assertEnabled(input2);
form.disable();
- assertDisabled(input1, input2);
+ this.assertDisabled(input1, input2);
form.enable();
- assertEnabled(input1, input2);
+ this.assertEnabled(input1, input2);
input1.disable();
- assertDisabled(input1);
+ this.assertDisabled(input1);
// non-form elements:
var fieldset = $('selects_fieldset');
var fields = fieldset.immediateDescendants();
- fields.each(function(select) { assertEnabled(select) });
+ fields.each(function(select) { this.assertEnabled(select) }, this);
Form.disable(fieldset)
- fields.each(function(select) { assertDisabled(select) });
+ fields.each(function(select) { this.assertDisabled(select) }, this);
Form.enable(fieldset)
- fields.each(function(select) { assertEnabled(select) });
- }},
+ fields.each(function(select) { this.assertEnabled(select) }, this);
+ },
- testFormElementEnabling: function(){ with(this) {
+ testFormElementEnabling: function(){
var field = $('input_disabled');
field.enable();
- assertEnabled(field);
+ this.assertEnabled(field);
field.disable();
- assertDisabled(field);
+ this.assertDisabled(field);
var field = $('input_enabled');
- assertEnabled(field);
+ this.assertEnabled(field);
field.disable();
- assertDisabled(field);
+ this.assertDisabled(field);
field.enable();
- assertEnabled(field);
- }},
+ this.assertEnabled(field);
+ },
// due to the lack of a DOM hasFocus() API method,
// we're simulating things here a little bit
- testFormActivating: function(){ with(this) {
+ testFormActivating: function(){
// Firefox, IE, and Safari 2+
function getSelection(element){
try {
@@ -311,52 +311,52 @@
// Form.focusFirstElement shouldn't focus disabled elements
var element = Form.findFirstElement('bigform');
- assertEqual('submit', element.id);
+ this.assertEqual('submit', element.id);
// Test IE doesn't select text on buttons
Form.focusFirstElement('bigform');
- if(document.selection) assertEqual('', getSelection(element));
+ if(document.selection) this.assertEqual('', getSelection(element));
// Form.Element.activate shouldn't select text on buttons
element = $('focus_text');
- assertEqual('', getSelection(element));
+ this.assertEqual('', getSelection(element));
// Form.Element.activate should select text on text input elements
element.activate();
- assertEqual('Hello', getSelection(element));
+ this.assertEqual('Hello', getSelection(element));
// Form.Element.activate shouldn't raise an exception when the form or field is hidden
- assertNothingRaised(function() {
+ this.assertNothingRaised(function() {
$('form_focus_hidden').focusFirstElement();
});
- }},
+ },
- testFormGetElements: function() {with(this) {
+ testFormGetElements: function() {
var elements = Form.getElements('various'),
names = $w('tf_selectOne tf_textarea tf_checkbox tf_selectMany tf_text tf_radio tf_hidden tf_password');
- assertEnumEqual(names, elements.pluck('name'))
- }},
+ this.assertEnumEqual(names, elements.pluck('name'))
+ },
- testFormGetInputs: function() {with(this){
+ testFormGetInputs: function() {
var form = $('form');
[form.getInputs(), Form.getInputs(form)].each(function(inputs){
- assertEqual(inputs.length, 5);
- assert(inputs instanceof Array);
- assert(inputs.all(function(input) { return (input.tagName == "INPUT"); }));
- });
- }},
+ this.assertEqual(inputs.length, 5);
+ this.assert(inputs instanceof Array);
+ this.assert(inputs.all(function(input) { return (input.tagName == "INPUT"); }));
+ }, this);
+ },
- testFormFindFirstElement: function() {with(this) {
- assertEqual($('ffe_checkbox'), $('ffe').findFirstElement());
- assertEqual($('ffe_ti_submit'), $('ffe_ti').findFirstElement());
- assertEqual($('ffe_ti2_checkbox'), $('ffe_ti2').findFirstElement());
- }},
+ testFormFindFirstElement: function() {
+ this.assertEqual($('ffe_checkbox'), $('ffe').findFirstElement());
+ this.assertEqual($('ffe_ti_submit'), $('ffe_ti').findFirstElement());
+ this.assertEqual($('ffe_ti2_checkbox'), $('ffe_ti2').findFirstElement());
+ },
- testFormSerialize: function() {with(this){
+ testFormSerialize: function() {
// form is initially empty
var form = $('bigform');
var expected = { tf_selectOne:'', tf_textarea:'', tf_text:'', tf_hidden:'', tf_password:'' };
- assertHashEqual(expected, Form.serialize('various', true));
+ this.assertHashEqual(expected, Form.serialize('various', true));
// set up some stuff
form['tf_selectOne'].selectedIndex = 1;
@@ -370,48 +370,48 @@
tf_hidden:"moo%hoo&test", tf_password:'sekrit code', tf_checkbox:'on', tf_radio:'on' }
// return params
- assertHashEqual(expected, Form.serialize('various', true));
+ this.assertHashEqual(expected, Form.serialize('various', true));
// return string
- assertEnumEqual(Object.toQueryString(expected).split('&').sort(),
+ this.assertEnumEqual(Object.toQueryString(expected).split('&').sort(),
Form.serialize('various').split('&').sort());
- assertEqual('string', typeof $('form').serialize({ hash:false }));
+ this.assertEqual('string', typeof $('form').serialize({ hash:false }));
// Checks that disabled element is not included in serialized form.
$('input_enabled').enable();
- assertHashEqual({ val1:4, action:'blah', first_submit:'Commit it!' },
+ this.assertHashEqual({ val1:4, action:'blah', first_submit:'Commit it!' },
$('form').serialize(true));
// should not eat empty values for duplicate names
$('checkbox_hack').checked = false;
var data = Form.serialize('value_checks', true);
- assertEnumEqual(['', 'siamese'], data['twin']);
- assertEqual('0', data['checky']);
+ this.assertEnumEqual(['', 'siamese'], data['twin']);
+ this.assertEqual('0', data['checky']);
$('checkbox_hack').checked = true;
- assertEnumEqual($w('1 0'), Form.serialize('value_checks', true)['checky']);
+ this.assertEnumEqual($w('1 0'), Form.serialize('value_checks', true)['checky']);
// all kinds of SELECT controls
var params = Form.serialize('selects_fieldset', true);
var expected = { 'nvm[]':['One', 'Three'], evu:'', 'evm[]':['', 'Three'] };
- assertHashEqual(expected, params);
+ this.assertHashEqual(expected, params);
params = Form.serialize('selects_wrapper', true);
- assertHashEqual(Object.extend(expected, { vu:1, 'vm[]':[1, 3], nvu:'One' }), params);
+ this.assertHashEqual(Object.extend(expected, { vu:1, 'vm[]':[1, 3], nvu:'One' }), params);
// explicit submit button
- assertHashEqual({ val1:4, action:'blah', second_submit:'Delete it!' },
+ this.assertHashEqual({ val1:4, action:'blah', second_submit:'Delete it!' },
$('form').serialize({ submit: 'second_submit' }));
- assertHashEqual({ val1:4, action:'blah' },
+ this.assertHashEqual({ val1:4, action:'blah' },
$('form').serialize({ submit: false }));
- assertHashEqual({ val1:4, action:'blah' },
+ this.assertHashEqual({ val1:4, action:'blah' },
$('form').serialize({ submit: 'inexistent' }));
- }},
+ },
- testFormMethodsOnExtendedElements: function() {with(this) {
+ testFormMethodsOnExtendedElements: function() {
var form = $('form');
- assertEqual(Form.serialize('form'), form.serialize());
- assertEqual(Form.Element.serialize('input_enabled'), $('input_enabled').serialize());
- assertNotEqual(form.serialize, $('input_enabled').serialize);
+ this.assertEqual(Form.serialize('form'), form.serialize());
+ this.assertEqual(Form.Element.serialize('input_enabled'), $('input_enabled').serialize());
+ this.assertNotEqual(form.serialize, $('input_enabled').serialize);
Element.addMethods('INPUT', { anInputMethod: function(input) { return 'input' } });
Element.addMethods('SELECT', { aSelectMethod: function(select) { return 'select' } });
@@ -420,74 +420,73 @@
var input = form['tf_text'], select = form['tf_selectOne'];
input._extendedByPrototype = select._extendedByPrototype = false;
- assert($(input).anInputMethod);
- assert(!input.aSelectMethod);
- assertEqual('input', input.anInputMethod());
+ this.assert($(input).anInputMethod);
+ this.assert(!input.aSelectMethod);
+ this.assertEqual('input', input.anInputMethod());
- assert($(select).aSelectMethod);
- assert(!select.anInputMethod);
- assertEqual('select', select.aSelectMethod());
- }},
+ this.assert($(select).aSelectMethod);
+ this.assert(!select.anInputMethod);
+ this.assertEqual('select', select.aSelectMethod());
+ },
- testFormRequest: function() {with(this) {
+ testFormRequest: function() {
request = $("form").request();
- assert($("form").hasAttribute("method"));
- assert(request.url.include("fixtures/empty.js?val1=4"));
- assertEqual("get", request.method);
+ this.assert($("form").hasAttribute("method"));
+ this.assert(request.url.include("fixtures/empty.js?val1=4"));
+ this.assertEqual("get", request.method);
request = $("form").request({ method: "put", parameters: {val2: "hello"} });
- assert(request.url.endsWith("fixtures/empty.js"));
- assertEqual(4, request.options.parameters['val1']);
- assertEqual('hello', request.options.parameters['val2']);
- assertEqual("post", request.method);
- assertEqual("put", request.parameters['_method']);
+ this.assert(request.url.endsWith("fixtures/empty.js"));
+ this.assertEqual(4, request.options.parameters['val1']);
+ this.assertEqual('hello', request.options.parameters['val2']);
+ this.assertEqual("post", request.method);
+ this.assertEqual("put", request.parameters['_method']);
// with empty action attribute
request = $("ffe").request({ method: 'post' });
- assert(request.url.include("unit/form.html"),
+ this.assert(request.url.include("unit/form.html"),
'wrong default action for form element with empty action attribute');
- }},
+ },
- testFormElementMethodsChaining: function(){ with(this) {
+ testFormElementMethodsChaining: function(){
var methods = $w('clear activate disable enable'),
formElements = $('form').getElements();
methods.each(function(method){
formElements.each(function(element){
var returned = element[method]();
- assertIdentical(element, returned);
- });
- });
- }},
+ this.assertIdentical(element, returned);
+ }, this);
+ }, this);
+ },
- testSetValue: function(){ with(this) {
+ testSetValue: function(){
// text input
var input = $('input_enabled'), oldValue = input.getValue();
- assertEqual(input, input.setValue('foo'), 'setValue chaining is broken');
- assertEqual('foo', input.getValue(), 'value improperly set');
+ this.assertEqual(input, input.setValue('foo'), 'setValue chaining is broken');
+ this.assertEqual('foo', input.getValue(), 'value improperly set');
input.setValue(oldValue);
- assertEqual(oldValue, input.getValue(), 'value improperly restored to original');
+ this.assertEqual(oldValue, input.getValue(), 'value improperly restored to original');
// checkbox
input = $('checkbox_hack');
input.setValue(false);
- assertEqual(null, input.getValue(), 'checkbox should be unchecked');
+ this.assertEqual(null, input.getValue(), 'checkbox should be unchecked');
input.setValue(true);
- assertEqual("1", input.getValue(), 'checkbox should be checked');
+ this.assertEqual("1", input.getValue(), 'checkbox should be checked');
// selectbox
input = $('bigform')['vu'];
input.setValue('3');
- assertEqual('3', input.getValue(), 'single select option improperly set');
+ this.assertEqual('3', input.getValue(), 'single select option improperly set');
input.setValue('1');
- assertEqual('1', input.getValue());
+ this.assertEqual('1', input.getValue());
// multiple select
input = $('bigform')['vm[]'];
input.setValue(['2', '3']);
- assertEnumEqual(['2', '3'], input.getValue(),
+ this.assertEnumEqual(['2', '3'], input.getValue(),
'multiple select options improperly set');
input.setValue(['1', '3']);
- assertEnumEqual(['1', '3'], input.getValue());
- }}
-
+ this.assertEnumEqual(['1', '3'], input.getValue());
+ }
});
// ]]>
diff --git a/test/unit/hash.html b/test/unit/hash.html
index 3bcbec4..60c96ba 100644
--- a/test/unit/hash.html
+++ b/test/unit/hash.html
@@ -54,177 +54,177 @@
};
new Test.Unit.Runner({
- testSet: function(){ with(this) {
+ testSet: function() {
var h = $H({a: 'A'})
- assertEqual('B', h.set('b', 'B'));
- assertHashEqual({a: 'A', b: 'B'}, h);
+ this.assertEqual('B', h.set('b', 'B'));
+ this.assertHashEqual({a: 'A', b: 'B'}, h);
- assertUndefined(h.set('c'));
- assertHashEqual({a: 'A', b: 'B', c: undefined}, h);
- }},
+ this.assertUndefined(h.set('c'));
+ this.assertHashEqual({a: 'A', b: 'B', c: undefined}, h);
+ },
- testGet: function(){ with(this) {
+ testGet: function() {
var h = $H({a: 'A'});
- assertEqual('A', h.get('a'));
- assertUndefined(h.a);
- assertUndefined($H({}).get('a'));
- }},
+ this.assertEqual('A', h.get('a'));
+ this.assertUndefined(h.a);
+ this.assertUndefined($H({}).get('a'));
+ },
- testUnset: function(){ with(this) {
+ testUnset: function() {
var hash = $H(Fixtures.many);
- assertEqual('B', hash.unset('b'));
- assertHashEqual({a:'A', c: 'C', d:'D#'}, hash);
- assertUndefined(hash.unset('z'));
- assertHashEqual({a:'A', c: 'C', d:'D#'}, hash);
+ this.assertEqual('B', hash.unset('b'));
+ this.assertHashEqual({a:'A', c: 'C', d:'D#'}, hash);
+ this.assertUndefined(hash.unset('z'));
+ this.assertHashEqual({a:'A', c: 'C', d:'D#'}, hash);
// not equivalent to Hash#remove
- assertEqual('A', hash.unset('a', 'c'));
- assertHashEqual({c: 'C', d:'D#'}, hash);
- }},
+ this.assertEqual('A', hash.unset('a', 'c'));
+ this.assertHashEqual({c: 'C', d:'D#'}, hash);
+ },
- testToObject: function(){ with(this) {
+ testToObject: function() {
var hash = $H(Fixtures.many), object = hash.toObject();
- assertInstanceOf(Object, object);
- assertHashEqual(Fixtures.many, object);
- assertNotIdentical(Fixtures.many, object);
+ this.assertInstanceOf(Object, object);
+ this.assertHashEqual(Fixtures.many, object);
+ this.assertNotIdentical(Fixtures.many, object);
hash.set('foo', 'bar');
- assertHashNotEqual(object, hash.toObject());
- }},
+ this.assertHashNotEqual(object, hash.toObject());
+ },
- testConstruct: function(){ with(this) {
+ testConstruct: function() {
var object = Object.clone(Fixtures.one);
var h = new Hash(object), h2 = $H(object);
- assertInstanceOf(Hash, h);
- assertInstanceOf(Hash, h2);
+ this.assertInstanceOf(Hash, h);
+ this.assertInstanceOf(Hash, h2);
- assertHashEqual({}, new Hash());
- assertHashEqual(object, h);
- assertHashEqual(object, h2);
+ this.assertHashEqual({}, new Hash());
+ this.assertHashEqual(object, h);
+ this.assertHashEqual(object, h2);
h.set('foo', 'bar');
- assertHashNotEqual(object, h);
+ this.assertHashNotEqual(object, h);
var clone = $H(h);
- assertInstanceOf(Hash, clone);
- assertHashEqual(h, clone);
+ this.assertInstanceOf(Hash, clone);
+ this.assertHashEqual(h, clone);
h.set('foo', 'foo');
- assertHashNotEqual(h, clone);
- assertIdentical($H, Hash.from);
- }},
+ this.assertHashNotEqual(h, clone);
+ this.assertIdentical($H, Hash.from);
+ },
- testKeys: function(){ with(this) {
- assertEnumEqual([], $H({}).keys());
- assertEnumEqual(['a'], $H(Fixtures.one).keys());
- assertEnumEqual($w('a b c d'), $H(Fixtures.many).keys().sort());
- assertEnumEqual($w('plus quad'), $H(Fixtures.functions).keys().sort());
- }},
+ testKeys: function() {
+ this.assertEnumEqual([], $H({}).keys());
+ this.assertEnumEqual(['a'], $H(Fixtures.one).keys());
+ this.assertEnumEqual($w('a b c d'), $H(Fixtures.many).keys().sort());
+ this.assertEnumEqual($w('plus quad'), $H(Fixtures.functions).keys().sort());
+ },
- testValues: function(){ with(this) {
- assertEnumEqual([], $H({}).values());
- assertEnumEqual(['A#'], $H(Fixtures.one).values());
- assertEnumEqual($w('A B C D#'), $H(Fixtures.many).values().sort());
- assertEnumEqual($w('function function'),
+ testValues: function() {
+ this.assertEnumEqual([], $H({}).values());
+ this.assertEnumEqual(['A#'], $H(Fixtures.one).values());
+ this.assertEnumEqual($w('A B C D#'), $H(Fixtures.many).values().sort());
+ this.assertEnumEqual($w('function function'),
$H(Fixtures.functions).values().map(function(i){ return typeof i }));
- assertEqual(9, $H(Fixtures.functions).get('quad')(3));
- assertEqual(6, $H(Fixtures.functions).get('plus')(3));
- }},
+ this.assertEqual(9, $H(Fixtures.functions).get('quad')(3));
+ this.assertEqual(6, $H(Fixtures.functions).get('plus')(3));
+ },
- testIndex: function(){ with(this) {
- assertUndefined($H().index('foo'));
+ testIndex: function() {
+ this.assertUndefined($H().index('foo'));
- assert('a', $H(Fixtures.one).index('A#'));
- assert('a', $H(Fixtures.many).index('A'));
- assertUndefined($H(Fixtures.many).index('Z'))
+ this.assert('a', $H(Fixtures.one).index('A#'));
+ this.assert('a', $H(Fixtures.many).index('A'));
+ this.assertUndefined($H(Fixtures.many).index('Z'))
var hash = $H({a:1,b:'2',c:1});
- assert(['a','c'].include(hash.index(1)));
- assertUndefined(hash.index('1'));
- }},
+ this.assert(['a','c'].include(hash.index(1)));
+ this.assertUndefined(hash.index('1'));
+ },
- testMerge: function(){ with(this) {
+ testMerge: function() {
var h = $H(Fixtures.many);
- assertNotIdentical(h, h.merge());
- assertNotIdentical(h, h.merge({}));
- assertInstanceOf(Hash, h.merge());
- assertInstanceOf(Hash, h.merge({}));
- assertHashEqual(h, h.merge());
- assertHashEqual(h, h.merge({}));
- assertHashEqual(h, h.merge($H()));
- assertHashEqual({a:'A', b:'B', c:'C', d:'D#', aaa:'AAA' }, h.merge({aaa: 'AAA'}));
- assertHashEqual({a:'A#', b:'B', c:'C', d:'D#' }, h.merge(Fixtures.one));
- }},
+ this.assertNotIdentical(h, h.merge());
+ this.assertNotIdentical(h, h.merge({}));
+ this.assertInstanceOf(Hash, h.merge());
+ this.assertInstanceOf(Hash, h.merge({}));
+ this.assertHashEqual(h, h.merge());
+ this.assertHashEqual(h, h.merge({}));
+ this.assertHashEqual(h, h.merge($H()));
+ this.assertHashEqual({a:'A', b:'B', c:'C', d:'D#', aaa:'AAA' }, h.merge({aaa: 'AAA'}));
+ this.assertHashEqual({a:'A#', b:'B', c:'C', d:'D#' }, h.merge(Fixtures.one));
+ },
- testUpdate: function(){ with(this) {
+ testUpdate: function() {
var h = $H(Fixtures.many);
- assertIdentical(h, h.update());
- assertIdentical(h, h.update({}));
- assertHashEqual(h, h.update());
- assertHashEqual(h, h.update({}));
- assertHashEqual(h, h.update($H()));
- assertHashEqual({a:'A', b:'B', c:'C', d:'D#', aaa:'AAA' }, h.update({aaa: 'AAA'}));
- assertHashEqual({a:'A#', b:'B', c:'C', d:'D#', aaa:'AAA' }, h.update(Fixtures.one));
- }},
+ this.assertIdentical(h, h.update());
+ this.assertIdentical(h, h.update({}));
+ this.assertHashEqual(h, h.update());
+ this.assertHashEqual(h, h.update({}));
+ this.assertHashEqual(h, h.update($H()));
+ this.assertHashEqual({a:'A', b:'B', c:'C', d:'D#', aaa:'AAA' }, h.update({aaa: 'AAA'}));
+ this.assertHashEqual({a:'A#', b:'B', c:'C', d:'D#', aaa:'AAA' }, h.update(Fixtures.one));
+ },
- testToQueryString: function(){ with(this) {
- assertEqual('', $H({}).toQueryString());
- assertEqual('a%23=A', $H({'a#': 'A'}).toQueryString());
- assertEqual('a=A%23', $H(Fixtures.one).toQueryString());
- assertEqual('a=A&b=B&c=C&d=D%23', $H(Fixtures.many).toQueryString());
- assertEqual("a=b&c", $H(Fixtures.value_undefined).toQueryString());
- assertEqual("a=b&c", $H("a=b&c".toQueryParams()).toQueryString());
- assertEqual("a=b&c=", $H(Fixtures.value_null).toQueryString());
- assertEqual("a=b&c=0", $H(Fixtures.value_zero).toQueryString());
- assertEqual("color=r&color=g&color=b", $H(Fixtures.multiple).toQueryString());
- assertEqual("color=r&color=&color=g&color&color=0", $H(Fixtures.multiple_nil).toQueryString());
- assertEqual("color=&color", $H(Fixtures.multiple_all_nil).toQueryString());
- assertEqual("", $H(Fixtures.multiple_empty).toQueryString());
- assertEqual("stuff%5B%5D=%24&stuff%5B%5D=a&stuff%5B%5D=%3B", $H(Fixtures.multiple_special).toQueryString());
- assertHashEqual(Fixtures.multiple_special, $H(Fixtures.multiple_special).toQueryString().toQueryParams());
- assertIdentical(Object.toQueryString, Hash.toQueryString);
- }},
+ testToQueryString: function() {
+ this.assertEqual('', $H({}).toQueryString());
+ this.assertEqual('a%23=A', $H({'a#': 'A'}).toQueryString());
+ this.assertEqual('a=A%23', $H(Fixtures.one).toQueryString());
+ this.assertEqual('a=A&b=B&c=C&d=D%23', $H(Fixtures.many).toQueryString());
+ this.assertEqual("a=b&c", $H(Fixtures.value_undefined).toQueryString());
+ this.assertEqual("a=b&c", $H("a=b&c".toQueryParams()).toQueryString());
+ this.assertEqual("a=b&c=", $H(Fixtures.value_null).toQueryString());
+ this.assertEqual("a=b&c=0", $H(Fixtures.value_zero).toQueryString());
+ this.assertEqual("color=r&color=g&color=b", $H(Fixtures.multiple).toQueryString());
+ this.assertEqual("color=r&color=&color=g&color&color=0", $H(Fixtures.multiple_nil).toQueryString());
+ this.assertEqual("color=&color", $H(Fixtures.multiple_all_nil).toQueryString());
+ this.assertEqual("", $H(Fixtures.multiple_empty).toQueryString());
+ this.assertEqual("stuff%5B%5D=%24&stuff%5B%5D=a&stuff%5B%5D=%3B", $H(Fixtures.multiple_special).toQueryString());
+ this.assertHashEqual(Fixtures.multiple_special, $H(Fixtures.multiple_special).toQueryString().toQueryParams());
+ this.assertIdentical(Object.toQueryString, Hash.toQueryString);
+ },
- testInspect: function(){ with(this) {
- assertEqual('#
クルーズコレクション',
+ this.assertEqual('ウィメンズ2007
クルーズコレクション',
'ウィメンズ2007\nクルーズコレクション'.gsub(/\n/,'
'));
- assertEqual('ウィメンズ2007
クルーズコレクション',
+ this.assertEqual('ウィメンズ2007
クルーズコレクション',
'ウィメンズ2007\nクルーズコレクション'.gsub('\n','
'));
- }},
+ },
- testGsubWithReplacementTemplateString: function() {with(this) {
+ testGsubWithReplacementTemplateString: function() {
var source = 'foo boo boz';
- assertEqual('-oo-#{1}- -oo-#{1}- -o-#{1}-z',
+ this.assertEqual('-oo-#{1}- -oo-#{1}- -o-#{1}-z',
source.gsub(/(.)(o+)/, '-#{2}-\\#{1}-'));
- assertEqual('-foo-f- -boo-b- -bo-b-z',
+ this.assertEqual('-foo-f- -boo-b- -bo-b-z',
source.gsub(/(.)(o+)/, '-#{0}-#{1}-'));
- assertEqual('-oo-f- -oo-b- -o-b-z',
+ this.assertEqual('-oo-f- -oo-b- -o-b-z',
source.gsub(/(.)(o+)/, '-#{2}-#{1}-'));
- assertEqual(' z',
+ this.assertEqual(' z',
source.gsub(/(.)(o+)/, '#{3}'));
- }},
+ },
- testSubWithReplacementFunction: function() {with(this) {
+ testSubWithReplacementFunction: function() {
var source = 'foo boo boz';
- assertEqual('Foo boo boz',
+ this.assertEqual('Foo boo boz',
source.sub(/[^o]+/, function(match) {
return match[0].toUpperCase()
}), 1);
- assertEqual('Foo Boo boz',
+ this.assertEqual('Foo Boo boz',
source.sub(/[^o]+/, function(match) {
return match[0].toUpperCase()
}, 2), 2);
- assertEqual(source,
+ this.assertEqual(source,
source.sub(/[^o]+/, function(match) {
return match[0].toUpperCase()
}, 0), 0);
- assertEqual(source,
+ this.assertEqual(source,
source.sub(/[^o]+/, function(match) {
return match[0].toUpperCase()
}, -1), -1);
- }},
+ },
- testSubWithReplacementString: function() {with(this) {
+ testSubWithReplacementString: function() {
var source = 'foo boo boz';
- assertEqual('oo boo boz',
+ this.assertEqual('oo boo boz',
source.sub(/[^o]+/, ''));
- assertEqual('oooo boz',
+ this.assertEqual('oooo boz',
source.sub(/[^o]+/, '', 2));
- assertEqual('-f-oo boo boz',
+ this.assertEqual('-f-oo boo boz',
source.sub(/[^o]+/, '-#{0}-'));
- assertEqual('-f-oo- b-oo boz',
+ this.assertEqual('-f-oo- b-oo boz',
source.sub(/[^o]+/, '-#{0}-', 2));
- }},
+ },
- testScan: function() {with(this) {
+ testScan: function() {
var source = 'foo boo boz', results = [];
var str = source.scan(/[o]+/, function(match) {
results.push(match[0].length);
});
- assertEnumEqual([2, 2, 1], results);
- assertEqual(source, source.scan(/x/, fail));
- assert(typeof str == 'string');
- }},
+ this.assertEnumEqual([2, 2, 1], results);
+ this.assertEqual(source, source.scan(/x/, this.fail));
+ this.assert(typeof str == 'string');
+ },
- testToArray: function() {with(this) {
- assertEnumEqual([],''.toArray());
- assertEnumEqual(['a'],'a'.toArray());
- assertEnumEqual(['a','b'],'ab'.toArray());
- assertEnumEqual(['f','o','o'],'foo'.toArray());
- }},
+ testToArray: function() {
+ this.assertEnumEqual([],''.toArray());
+ this.assertEnumEqual(['a'],'a'.toArray());
+ this.assertEnumEqual(['a','b'],'ab'.toArray());
+ this.assertEnumEqual(['f','o','o'],'foo'.toArray());
+ },
/*
Note that camelize() differs from its Rails counterpart,
@@ -154,217 +154,213 @@
- Looks for dashes, not underscores
- CamelCases first word if there is a front dash
*/
- testCamelize: function() {with(this) {
- assertEqual('', ''.camelize());
- assertEqual('', '-'.camelize());
- assertEqual('foo', 'foo'.camelize());
- assertEqual('foo_bar', 'foo_bar'.camelize());
- assertEqual('FooBar', '-foo-bar'.camelize());
- assertEqual('FooBar', 'FooBar'.camelize());
+ testCamelize: function() {
+ this.assertEqual('', ''.camelize());
+ this.assertEqual('', '-'.camelize());
+ this.assertEqual('foo', 'foo'.camelize());
+ this.assertEqual('foo_bar', 'foo_bar'.camelize());
+ this.assertEqual('FooBar', '-foo-bar'.camelize());
+ this.assertEqual('FooBar', 'FooBar'.camelize());
- assertEqual('fooBar', 'foo-bar'.camelize());
- assertEqual('borderBottomWidth', 'border-bottom-width'.camelize());
+ this.assertEqual('fooBar', 'foo-bar'.camelize());
+ this.assertEqual('borderBottomWidth', 'border-bottom-width'.camelize());
- assertEqual('classNameTest','class-name-test'.camelize());
- assertEqual('classNameTest','className-test'.camelize());
- assertEqual('classNameTest','class-nameTest'.camelize());
+ this.assertEqual('classNameTest','class-name-test'.camelize());
+ this.assertEqual('classNameTest','className-test'.camelize());
+ this.assertEqual('classNameTest','class-nameTest'.camelize());
- /* benchmark(function(){
+ /* this.benchmark(function(){
'class-name-test'.camelize();
},10000); */
- }},
+ },
- testCapitalize: function() {with(this) {
- assertEqual('',''.capitalize());
- assertEqual('Ä','ä'.capitalize());
- assertEqual('A','A'.capitalize());
- assertEqual('Hello','hello'.capitalize());
- assertEqual('Hello','HELLO'.capitalize());
- assertEqual('Hello','Hello'.capitalize());
- assertEqual('Hello world','hello WORLD'.capitalize());
- }},
+ testCapitalize: function() {
+ this.assertEqual('',''.capitalize());
+ this.assertEqual('Ä','ä'.capitalize());
+ this.assertEqual('A','A'.capitalize());
+ this.assertEqual('Hello','hello'.capitalize());
+ this.assertEqual('Hello','HELLO'.capitalize());
+ this.assertEqual('Hello','Hello'.capitalize());
+ this.assertEqual('Hello world','hello WORLD'.capitalize());
+ },
- testUnderscore: function() {with(this) {
- assertEqual('', ''.underscore());
- assertEqual('_', '-'.underscore());
- assertEqual('foo', 'foo'.underscore());
- assertEqual('foo', 'Foo'.underscore());
- assertEqual('foo_bar', 'foo_bar'.underscore());
- assertEqual('border_bottom', 'borderBottom'.underscore());
- assertEqual('border_bottom_width', 'borderBottomWidth'.underscore());
- assertEqual('border_bottom_width', 'border-Bottom-Width'.underscore());
- }},
+ testUnderscore: function() {
+ this.assertEqual('', ''.underscore());
+ this.assertEqual('_', '-'.underscore());
+ this.assertEqual('foo', 'foo'.underscore());
+ this.assertEqual('foo', 'Foo'.underscore());
+ this.assertEqual('foo_bar', 'foo_bar'.underscore());
+ this.assertEqual('border_bottom', 'borderBottom'.underscore());
+ this.assertEqual('border_bottom_width', 'borderBottomWidth'.underscore());
+ this.assertEqual('border_bottom_width', 'border-Bottom-Width'.underscore());
+ },
- testDasherize: function() {with(this) {
- assertEqual('', ''.dasherize());
- assertEqual('foo', 'foo'.dasherize());
- assertEqual('Foo', 'Foo'.dasherize());
- assertEqual('foo-bar', 'foo-bar'.dasherize());
- assertEqual('border-bottom-width', 'border_bottom_width'.dasherize());
- }},
+ testDasherize: function() {
+ this.assertEqual('', ''.dasherize());
+ this.assertEqual('foo', 'foo'.dasherize());
+ this.assertEqual('Foo', 'Foo'.dasherize());
+ this.assertEqual('foo-bar', 'foo-bar'.dasherize());
+ this.assertEqual('border-bottom-width', 'border_bottom_width'.dasherize());
+ },
- testTruncate: function() {with(this) {
+ testTruncate: function() {
var source = 'foo boo boz foo boo boz foo boo boz foo boo boz';
- assertEqual(source, source.truncate(source.length));
- assertEqual('foo boo boz foo boo boz foo...', source.truncate(0));
- assertEqual('fo...', source.truncate(5));
- assertEqual('foo b', source.truncate(5, ''));
+ this.assertEqual(source, source.truncate(source.length));
+ this.assertEqual('foo boo boz foo boo boz foo...', source.truncate(0));
+ this.assertEqual('fo...', source.truncate(5));
+ this.assertEqual('foo b', source.truncate(5, ''));
- assert(typeof 'foo'.truncate(5) == 'string');
- assert(typeof 'foo bar baz'.truncate(5) == 'string');
- }},
+ this.assert(typeof 'foo'.truncate(5) == 'string');
+ this.assert(typeof 'foo bar baz'.truncate(5) == 'string');
+ },
- testStrip: function() {with(this) {
- assertEqual('hello world', ' hello world '.strip());
- assertEqual('hello world', 'hello world'.strip());
- assertEqual('hello \n world', ' hello \n world '.strip());
- assertEqual('', ' '.strip());
- }},
+ testStrip: function() {
+ this.assertEqual('hello world', ' hello world '.strip());
+ this.assertEqual('hello world', 'hello world'.strip());
+ this.assertEqual('hello \n world', ' hello \n world '.strip());
+ this.assertEqual('', ' '.strip());
+ },
- testStripTags: function() {with(this) {
- assertEqual('hello world', 'hello world'.stripTags());
- assertEqual('hello world', 'hello world'.stripTags());
- assertEqual('hello world', 'hello world'.stripTags());
- assertEqual('hello world', 'hello world'.stripTags());
- assertEqual('1\n2', '1\n2'.stripTags());
- }},
+ testStripTags: function() {
+ this.assertEqual('hello world', 'hello world'.stripTags());
+ this.assertEqual('hello world', 'hello world'.stripTags());
+ this.assertEqual('hello world', 'hello world'.stripTags());
+ this.assertEqual('hello world', 'hello world'.stripTags());
+ this.assertEqual('1\n2', '1\n2'.stripTags());
+ },
- testStripScripts: function() {with(this) {
- assertEqual('foo bar', 'foo bar'.stripScripts());
- assertEqual('foo bar', ('foo
diff --git a/test/unit/unit_tests.html b/test/unit/unit_tests.html
index 998ed0a..8975afb 100644
--- a/test/unit/unit_tests.html
+++ b/test/unit/unit_tests.html
@@ -56,144 +56,142 @@
new Test.Unit.Runner({
- testIsRunningFromRake: function() { with(this) {
+ testIsRunningFromRake: function() {
if (window.location.toString().startsWith('http')) {
- assert(isRunningFromRake);
- info('These tests are running from rake.')
+ this.assert(this.isRunningFromRake);
+ this.info('These tests are running from rake.')
} else {
- assert(!isRunningFromRake);
- info('These tests are *not* running from rake.')
+ this.assert(!this.isRunningFromRake);
+ this.info('These tests are *not* running from rake.')
}
- }},
+ },
testBuildMessage: function() {
this.assertEqual("'foo' 'bar'", this.buildMessage('', '? ?', 'foo', 'bar'))
},
- testAssertEqual: function() { with(this) {
- assertEqual(0, 0);
- assertEqual(0, 0, "test");
+ testAssertEqual: function() {
+ this.assertEqual(0, 0);
+ this.assertEqual(0, 0, "test");
- assertEqual(0,'0');
- assertEqual(65.0, 65);
+ this.assertEqual(0,'0');
+ this.assertEqual(65.0, 65);
- assertEqual("a", "a");
- assertEqual("a", "a", "test");
+ this.assertEqual("a", "a");
+ this.assertEqual("a", "a", "test");
- assertNotEqual(0, 1);
- assertNotEqual("a","b");
- assertNotEqual({},{});
- assertNotEqual([],[]);
- assertNotEqual([],{});
- }},
+ this.assertNotEqual(0, 1);
+ this.assertNotEqual("a","b");
+ this.assertNotEqual({},{});
+ this.assertNotEqual([],[]);
+ this.assertNotEqual([],{});
+ },
- testAssertEnumEqual: function() { with(this) {
- assertEnumEqual([], []);
- assertEnumEqual(['a', 'b'], ['a', 'b']);
- assertEnumEqual(['1', '2'], [1, 2]);
- assertEnumNotEqual(['1', '2'], [1, 2, 3]);
- }},
+ testAssertEnumEqual: function() {
+ this.assertEnumEqual([], []);
+ this.assertEnumEqual(['a', 'b'], ['a', 'b']);
+ this.assertEnumEqual(['1', '2'], [1, 2]);
+ this.assertEnumNotEqual(['1', '2'], [1, 2, 3]);
+ },
- testAssertHashEqual: function() { with(this) {
- assertHashEqual({}, {});
- assertHashEqual({a:'b'}, {a:'b'});
- assertHashEqual({a:'b', c:'d'}, {c:'d', a:'b'});
- assertHashNotEqual({a:'b', c:'d'}, {c:'d', a:'boo!'});
- }},
+ testAssertHashEqual: function() {
+ this.assertHashEqual({}, {});
+ this.assertHashEqual({a:'b'}, {a:'b'});
+ this.assertHashEqual({a:'b', c:'d'}, {c:'d', a:'b'});
+ this.assertHashNotEqual({a:'b', c:'d'}, {c:'d', a:'boo!'});
+ },
- testAssertRespondsTo: function() { with(this) {
- assertRespondsTo('isNice', testObj);
- assertRespondsTo('isBroken', testObj);
- }},
+ testAssertRespondsTo: function() {
+ this.assertRespondsTo('isNice', testObj);
+ this.assertRespondsTo('isBroken', testObj);
+ },
- testAssertIdentical: function() { with(this) {
- assertIdentical(0, 0);
- assertIdentical(0, 0, "test");
- assertIdentical(1, 1);
- assertIdentical('a', 'a');
- assertIdentical('a', 'a', "test");
- assertIdentical('', '');
- assertIdentical(undefined, undefined);
- assertIdentical(null, null);
- assertIdentical(true, true);
- assertIdentical(false, false);
+ testAssertIdentical: function() {
+ this.assertIdentical(0, 0);
+ this.assertIdentical(0, 0, "test");
+ this.assertIdentical(1, 1);
+ this.assertIdentical('a', 'a');
+ this.assertIdentical('a', 'a', "test");
+ this.assertIdentical('', '');
+ this.assertIdentical(undefined, undefined);
+ this.assertIdentical(null, null);
+ this.assertIdentical(true, true);
+ this.assertIdentical(false, false);
var obj = {a:'b'};
- assertIdentical(obj, obj);
+ this.assertIdentical(obj, obj);
- assertNotIdentical({1:2,3:4},{1:2,3:4});
+ this.assertNotIdentical({1:2,3:4},{1:2,3:4});
- assertIdentical(1, 1.0); // both are typeof == 'number'
+ this.assertIdentical(1, 1.0); // both are typeof == 'number'
- assertNotIdentical(1, '1');
- assertNotIdentical(1, '1.0');
- }},
+ this.assertNotIdentical(1, '1');
+ this.assertNotIdentical(1, '1.0');
+ },
- testAssertNullAndAssertUndefined: function() { with(this) {
- assertNull(null);
- assertNotNull(undefined);
- assertNotNull(0);
- assertNotNull('');
- assertNotUndefined(null);
- assertUndefined(undefined);
- assertNotUndefined(0);
- assertNotUndefined('');
- assertNullOrUndefined(null);
- assertNullOrUndefined(undefined);
- assertNotNullOrUndefined(0);
- assertNotNullOrUndefined('');
- }},
+ testAssertNullAndAssertUndefined: function() {
+ this.assertNull(null);
+ this.assertNotNull(undefined);
+ this.assertNotNull(0);
+ this.assertNotNull('');
+ this.assertNotUndefined(null);
+ this.assertUndefined(undefined);
+ this.assertNotUndefined(0);
+ this.assertNotUndefined('');
+ this.assertNullOrUndefined(null);
+ this.assertNullOrUndefined(undefined);
+ this.assertNotNullOrUndefined(0);
+ this.assertNotNullOrUndefined('');
+ },
- testAssertMatch: function() { with(this) {
- assertMatch(/knowmad.jpg$/, 'http://script.aculo.us/images/knowmad.jpg');
- assertMatch(/Fuc/, 'Thomas Fuchs');
- assertMatch(/^\$(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$/, '$19.95');
- assertMatch(/(\d{3}\) ?)|(\d{3}[- \.])?\d{3}[- \.]\d{4}(\s(x\d+)?){0,1}$/, '704-343-9330');
- assertMatch(/^(?:(?:(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(\/|-|\.)(?:0?2\1(?:29)))|(?:(?:(?:1[6-9]|[2-9]\d)?\d{2})(\/|-|\.)(?:(?:(?:0?[13578]|1[02])\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\2(?:0?[1-9]|1\d|2[0-8]))))$/, '2001-06-16');
- assertMatch(/^((0?[123456789])|(1[012]))\s*:\s*([012345]\d)(\s*:\s*([012345]\d))?\s*[ap]m\s*-\s*((0?[123456789])|(1[012]))\s*:\s*([012345]\d)(\s*:\s*([012345]\d))?\s*[ap]m$/i, '2:00PM-2:15PM');
- assertNoMatch(/zubar/, 'foo bar');
- }},
+ testAssertMatch: function() {
+ this.assertMatch(/knowmad.jpg$/, 'http://script.aculo.us/images/knowmad.jpg');
+ this.assertMatch(/Fuc/, 'Thomas Fuchs');
+ this.assertMatch(/^\$(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$/, '$19.95');
+ this.assertMatch(/(\d{3}\) ?)|(\d{3}[- \.])?\d{3}[- \.]\d{4}(\s(x\d+)?){0,1}$/, '704-343-9330');
+ this.assertMatch(/^(?:(?:(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(\/|-|\.)(?:0?2\1(?:29)))|(?:(?:(?:1[6-9]|[2-9]\d)?\d{2})(\/|-|\.)(?:(?:(?:0?[13578]|1[02])\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\2(?:0?[1-9]|1\d|2[0-8]))))$/, '2001-06-16');
+ this.assertMatch(/^((0?[123456789])|(1[012]))\s*:\s*([012345]\d)(\s*:\s*([012345]\d))?\s*[ap]m\s*-\s*((0?[123456789])|(1[012]))\s*:\s*([012345]\d)(\s*:\s*([012345]\d))?\s*[ap]m$/i, '2:00PM-2:15PM');
+ this.assertNoMatch(/zubar/, 'foo bar');
+ },
- testAssertInstanceOf: function() { with(this) {
- assertInstanceOf(String, new String);
- assertInstanceOf(RegExp, /foo/);
- assertNotInstanceOf(String, {});
- }},
+ testAssertInstanceOf: function() {
+ this.assertInstanceOf(String, new String);
+ this.assertInstanceOf(RegExp, /foo/);
+ this.assertNotInstanceOf(String, {});
+ },
- testAssertVisible: function() { with(this) {
- assertVisible('testcss1');
- assertNotVisible('testcss1_span');
- //assertNotVisible('testcss2', "Due to a Safari bug, this test fails in Safari.");
+ testAssertVisible: function() {
+ this.assertVisible('testcss1');
+ this.assertNotVisible('testcss1_span');
+ //this.assertNotVisible('testcss2', "Due to a Safari bug, this test fails in Safari.");
Element.hide('testcss1');
- assertNotVisible('testcss1');
- assertNotVisible('testcss1_span');
+ this.assertNotVisible('testcss1');
+ this.assertNotVisible('testcss1_span');
Element.show('testcss1');
- assertVisible('testcss1');
- assertNotVisible('testcss1_span');
+ this.assertVisible('testcss1');
+ this.assertNotVisible('testcss1_span');
Element.show('testcss1_span');
- assertVisible('testcss1_span');
+ this.assertVisible('testcss1_span');
Element.hide('testcss1');
- assertNotVisible('testcss1_span'); // hidden by parent
- }},
+ this.assertNotVisible('testcss1_span'); // hidden by parent
+ },
- testAssertElementsMatch: function() { with(this) {
- assertElementsMatch($$('#tlist'), '#tlist');
- assertElementMatches($('tlist'), '#tlist');
- }}
-
+ testAssertElementsMatch: function() {
+ this.assertElementsMatch($$('#tlist'), '#tlist');
+ this.assertElementMatches($('tlist'), '#tlist');
+ }
});
new Test.Unit.Runner({
- testDummy: function() { with(this) {
- assert(true);
- }},
+ testDummy: function() {
+ this.assert(true);
+ },
- testMultipleTestRunner: function() { with(this) {
- assertEqual('passed', $('testlog_2').down('td', 1).innerHTML);
- }}
-
+ testMultipleTestRunner: function() {
+ this.assertEqual('passed', $('testlog_2').down('td', 1).innerHTML);
+ }
}, {testLog: 'testlog_2'});
// ]]>