Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 9036

Show
Ignore:
Timestamp:
03/16/08 18:53:51 (7 months ago)
Author:
tobie
Message:

prototype: Remove usage of the statement from unit tests.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • spinoffs/prototype/trunk/CHANGELOG

    r9026 r9036  
     1* Remove usage of the `with` statement from unit tests. [Tobie Langel] 
     2 
    13* Complete rewrite of the deprecation helper, now renamed UpdateHelper and useable by third-party libs. [Tobie Langel] 
    24 
  • spinoffs/prototype/trunk/ext/update_helper/prototype_update_helper.html

    r9026 r9036  
    7777   
    7878  new Test.Unit.Runner({ 
    79     testGetStack: function(){ with(this)
    80       assertMatch(/prototype_update_helper\.html:\d+\n$/, prototypeUpdateHelper.getStack()); 
    81     }}
    82  
    83     testDisplay: function(){ with(this)
     79    testGetStack: function()
     80      this.assertMatch(/prototype_update_helper\.html:\d+\n$/, prototypeUpdateHelper.getStack()); 
     81    }
     82 
     83    testDisplay: function()
    8484      Toggle.display('foo'); 
    85       assertInfoNotified('Toggle.display has been deprecated, please use Element.toggle instead.'); 
     85      this.assertInfoNotified('Toggle.display has been deprecated, please use Element.toggle instead.'); 
    8686         
    8787      Element.show('foo', 'bar', 'bla'); 
    88       assertErrorNotified('Passing an arbitrary number of elements to Element.show is no longer supported.\n' + 
     88      this.assertErrorNotified('Passing an arbitrary number of elements to Element.show is no longer supported.\n' + 
    8989        'Use [id_1, id_2, ...].each(Element.show) or $(id_1, id_2, ...).invoke("show") instead.'); 
    9090       
    9191      $('foo', 'bar', 'bla').each(Element.hide); 
    92       assertNotNotified(); 
     92      this.assertNotNotified(); 
    9393       
    9494      Element.show('foo'); 
    95       assertNotNotified(); 
     95      this.assertNotNotified(); 
    9696       
    9797      Element.hide('foo', 'bar', 'bla'); 
    98       assertErrorNotified('Passing an arbitrary number of elements to Element.hide is no longer supported.\n' + 
     98      this.assertErrorNotified('Passing an arbitrary number of elements to Element.hide is no longer supported.\n' + 
    9999        'Use [id_1, id_2, ...].each(Element.hide) or $(id_1, id_2, ...).invoke("hide") instead.'); 
    100100       
    101101      Element.toggle('foo', 'bar', 'bla'); 
    102       assertErrorNotified('Passing an arbitrary number of elements to Element.toggle is no longer supported.\n' + 
     102      this.assertErrorNotified('Passing an arbitrary number of elements to Element.toggle is no longer supported.\n' + 
    103103        'Use [id_1, id_2, ...].each(Element.toggle) or $(id_1, id_2, ...).invoke("toggle") instead.'); 
    104     }}
    105      
    106     testElementStyle: function(){ with(this)
     104    }
     105     
     106    testElementStyle: function()
    107107      Element.setStyle('foo', { 'fontSize': '18px' }); 
    108       assertNotNotified(); 
     108      this.assertNotNotified(); 
    109109       
    110110      Element.setStyle('foo', { 'font-size': '18px' }); 
    111       assertErrorNotified('Use of uncamelized style-property names is no longer supported.\n' +  
     111      this.assertErrorNotified('Use of uncamelized style-property names is no longer supported.\n' +  
    112112        'Use either camelized style-property names or a regular CSS string instead (see online documentation).') 
    113113       
    114114      Element.setStyle('foo', 'font-size: 18px;'); 
    115       assertNotNotified(); 
     115      this.assertNotNotified(); 
    116116       
    117117      $('foo').setStyle({ 'font-size': '18px' }); 
    118       assertErrorNotified('Use of uncamelized style-property names is no longer supported.\n' +  
     118      this.assertErrorNotified('Use of uncamelized style-property names is no longer supported.\n' +  
    119119        'Use either camelized style-property names or a regular CSS string instead (see online documentation).') 
    120     }}
    121  
    122     testClassNames: function(){ with(this)
     120    }
     121 
     122    testClassNames: function()
    123123      new Element.ClassNames('foo'); 
    124       assertInfoNotified('Element.ClassNames has been deprecated.') 
     124      this.assertInfoNotified('Element.ClassNames has been deprecated.') 
    125125       
    126126      $('foo').classNames(); 
    127       assertInfoNotified('Element#classNames has been deprecated.\n' + 
     127      this.assertInfoNotified('Element#classNames has been deprecated.\n' + 
    128128        'If you need to access CSS class names as an array, try: $w(element.classname).') 
    129129 
    130130      Element.getElementsByClassName('foo', 'className'); 
    131       assertInfoNotified('Element#getElementsByClassName has been deprecated, please use Element#select instead.') 
     131      this.assertInfoNotified('Element#getElementsByClassName has been deprecated, please use Element#select instead.') 
    132132       
    133133      document.getElementsByClassName('className'); 
    134       assertInfoNotified('document.getElementsByClassName has been deprecated, please use $$ instead.') 
    135     }}
    136      
    137     testDomSelectors: function(){ with(this)
     134      this.assertInfoNotified('document.getElementsByClassName has been deprecated, please use $$ instead.') 
     135    }
     136     
     137    testDomSelectors: function()
    138138      Element.childOf('foo', 'bar'); 
    139       assertInfoNotified('Element#childOf has been deprecated, please use Element#descendantOf instead.'); 
     139      this.assertInfoNotified('Element#childOf has been deprecated, please use Element#descendantOf instead.'); 
    140140 
    141141      $('foo').immediateDescendants(); 
    142       assertInfoNotified('Element#immediateDescendants has been deprecated, please use Element#childElements instead.'); 
     142      this.assertInfoNotified('Element#immediateDescendants has been deprecated, please use Element#childElements instead.'); 
    143143       
    144144      $('foo').getElementsBySelector('a'); 
    145       assertInfoNotified('Element#getElementsBySelector has been deprecated, please use Element#select instead.'); 
     145      this.assertInfoNotified('Element#getElementsBySelector has been deprecated, please use Element#select instead.'); 
    146146 
    147147      $('foo').select('a'); 
    148       assertNotNotified(); 
    149     }}
    150      
    151     testField: function(){ with(this)
     148      this.assertNotNotified(); 
     149    }
     150     
     151    testField: function()
    152152      Field.clear('foo', 'bar', 'bla'); 
    153       assertErrorNotified('Passing an arbitrary number of elements to Field.clear is no longer supported.\n' + 
     153      this.assertErrorNotified('Passing an arbitrary number of elements to Field.clear is no longer supported.\n' + 
    154154        'Use [id_1, id_2, ...].each(Form.Element.clear) or $(id_1, id_2, ...).invoke("clear") instead.'); 
    155155         
    156156      Field.present('foo', 'bar', 'bla'); 
    157       assertErrorNotified('Passing an arbitrary number of elements to Field.present is no longer supported.\n' + 
     157      this.assertErrorNotified('Passing an arbitrary number of elements to Field.present is no longer supported.\n' + 
    158158        'Use [id_1, id_2, ...].each(Form.Element.present) or $(id_1, id_2, ...).invoke("present") instead.'); 
    159     }}
    160      
    161     testInsertion: function(){ with(this)
     159    }
     160     
     161    testInsertion: function()
    162162      Insertion.Before('foo', 'text'); 
    163       assertInfoNotified('Insertion.Before has been deprecated, please use Element#insert instead.'); 
     163      this.assertInfoNotified('Insertion.Before has been deprecated, please use Element#insert instead.'); 
    164164 
    165165      Insertion.Top('foo', 'text'); 
    166       assertInfoNotified('Insertion.Top has been deprecated, please use Element#insert instead.'); 
     166      this.assertInfoNotified('Insertion.Top has been deprecated, please use Element#insert instead.'); 
    167167 
    168168      Insertion.Bottom('foo', 'text'); 
    169       assertInfoNotified('Insertion.Bottom has been deprecated, please use Element#insert instead.'); 
     169      this.assertInfoNotified('Insertion.Bottom has been deprecated, please use Element#insert instead.'); 
    170170 
    171171      Insertion.After('foo', 'text'); 
    172       assertInfoNotified('Insertion.After has been deprecated, please use Element#insert instead.'); 
    173     }}
    174      
    175     testPosition: function(){ with(this)
     172      this.assertInfoNotified('Insertion.After has been deprecated, please use Element#insert instead.'); 
     173    }
     174     
     175    testPosition: function()
    176176      Position.prepare('foo'); 
    177       assertInfoNotified('Position.prepare has been deprecated.'); 
     177      this.assertInfoNotified('Position.prepare has been deprecated.'); 
    178178 
    179179      Position.within('foo'); 
    180       assertInfoNotified('Position.within has been deprecated.'); 
     180      this.assertInfoNotified('Position.within has been deprecated.'); 
    181181 
    182182      Position.withinIncludingScrolloffsets('foo'); 
    183       assertInfoNotified('Position.withinIncludingScrolloffsets has been deprecated.'); 
     183      this.assertInfoNotified('Position.withinIncludingScrolloffsets has been deprecated.'); 
    184184 
    185185      Position.overlap('foo'); 
    186       assertInfoNotified('Position.overlap has been deprecated.'); 
     186      this.assertInfoNotified('Position.overlap has been deprecated.'); 
    187187 
    188188      Position.cumulativeOffset('foo'); 
    189       assertInfoNotified('Position.cumulativeOffset has been deprecated, please use Element#cumulativeOffset instead.'); 
     189      this.assertInfoNotified('Position.cumulativeOffset has been deprecated, please use Element#cumulativeOffset instead.'); 
    190190 
    191191      Position.positionedOffset('foo'); 
    192       assertInfoNotified('Position.positionedOffset has been deprecated, please use Element#positionedOffset instead.'); 
     192      this.assertInfoNotified('Position.positionedOffset has been deprecated, please use Element#positionedOffset instead.'); 
    193193 
    194194      Position.absolutize('foo'); 
    195       assertInfoNotified('Position.absolutize has been deprecated, please use Element#absolutize instead.'); 
     195      this.assertInfoNotified('Position.absolutize has been deprecated, please use Element#absolutize instead.'); 
    196196 
    197197      Position.relativize('foo'); 
    198       assertInfoNotified('Position.relativize has been deprecated, please use Element#relativize instead.'); 
     198      this.assertInfoNotified('Position.relativize has been deprecated, please use Element#relativize instead.'); 
    199199 
    200200      Position.realOffset('foo'); 
    201       assertInfoNotified('Position.realOffset has been deprecated, please use Element#cumulativeScrollOffset instead.'); 
     201      this.assertInfoNotified('Position.realOffset has been deprecated, please use Element#cumulativeScrollOffset instead.'); 
    202202 
    203203      Position.offsetParent('foo'); 
    204       assertInfoNotified('Position.offsetParent has been deprecated, please use Element#getOffsetParent instead.'); 
     204      this.assertInfoNotified('Position.offsetParent has been deprecated, please use Element#getOffsetParent instead.'); 
    205205 
    206206      Position.page('foo'); 
    207       assertInfoNotified('Position.page has been deprecated, please use Element#viewportOffset instead.'); 
     207      this.assertInfoNotified('Position.page has been deprecated, please use Element#viewportOffset instead.'); 
    208208 
    209209      Position.clone('foo', 'bar'); 
    210       assertInfoNotified('Position.clone has been deprecated, please use Element#clonePosition instead.'); 
    211     }}
    212  
    213     testEvent: function(){ with(this)
     210      this.assertInfoNotified('Position.clone has been deprecated, please use Element#clonePosition instead.'); 
     211    }
     212 
     213    testEvent: function()
    214214      Event.unloadCache(); 
    215       assertErrorNotified('Event.unloadCache has been deprecated.') 
    216     }}
    217      
    218     testHash: function(){ with(this)
     215      this.assertErrorNotified('Event.unloadCache has been deprecated.') 
     216    }
     217     
     218    testHash: function()
    219219      Hash.toQueryString({}); 
    220       assertInfoNotified('Hash.toQueryString has been deprecated.\n' +  
     220      this.assertInfoNotified('Hash.toQueryString has been deprecated.\n' +  
    221221        'Use the instance method Hash#toQueryString or Object.toQueryString instead.'); 
    222222 
    223223     Hash.toJSON({}); 
    224       assertErrorNotified('Hash.toJSON has been removed.\n' +  
     224      this.assertErrorNotified('Hash.toJSON has been removed.\n' +  
    225225        'Use the instance method Hash#toJSON or Object.toJSON instead.'); 
    226226       
     
    228228       
    229229      h.remove('foo'); 
    230       assertErrorNotified('Hash#remove is no longer supported, use Hash#unset instead.\n' +  
     230      this.assertErrorNotified('Hash#remove is no longer supported, use Hash#unset instead.\n' +  
    231231        'Please note that Hash#unset only accepts one argument.'); 
    232232       
    233233      h.merge('foo'); 
    234         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.'); 
     234        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.'); 
    235235       
    236236      h['foo']; 
    237       assertErrorNotified('Directly accessing a property of an instance of Hash is no longer supported.\n' +  
     237      this.assertErrorNotified('Directly accessing a property of an instance of Hash is no longer supported.\n' +  
    238238        'Please use Hash#get(\'foo\') instead.') 
    239239       
    240240      h.foo = 3; 
    241       assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +  
     241      this.assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +  
    242242        'Please use Hash#set(\'foo\', 3) instead.') 
    243243         
    244244      h.bar = 'bar'; 
    245245      h.toJSON(); 
    246       assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +  
     246      this.assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +  
    247247        'Please use Hash#set(\'bar\', \'bar\') instead.') 
    248248         
    249249      h.bar; 
    250       assertErrorNotified('Directly accessing a property of an instance of Hash is no longer supported.\n' +  
     250      this.assertErrorNotified('Directly accessing a property of an instance of Hash is no longer supported.\n' +  
    251251        'Please use Hash#get(\'bar\') instead.') 
    252252         
    253253      h.baz = 'baz'; 
    254254      h.bar; 
    255       assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +  
     255      this.assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +  
    256256        'Please use Hash#set(\'baz\', \'baz\') instead.') 
    257257       
    258258      h.set('toJSON', 'arg'); // make sure hash methods are not overwritten 
    259       assertRespondsTo('toJSON', h) 
    260     }}
    261  
    262     testClass: function(){ with(this)
     259      this.assertRespondsTo('toJSON', h) 
     260    }
     261 
     262    testClass: function()
    263263      Class.create(); 
    264       assertInfoNotified('The class API has been fully revised and now allows for mixins and inheritance.\n' +  
     264      this.assertInfoNotified('The class API has been fully revised and now allows for mixins and inheritance.\n' +  
    265265        'You can find more about it here: http://prototypejs.org/learn/class-inheritance'); 
    266266      Class.create({}); 
    267       assertNotNotified(); 
    268     }}
    269      
    270     testLogDeprecationOption: function(){ with(this)
     267      this.assertNotNotified(); 
     268    }
     269     
     270    testLogDeprecationOption: function()
    271271      prototypeUpdateHelper.logLevel = UpdateHelper.Warn; 
    272272      var h = $H({ foo: 2 }); 
    273273       
    274274      h.merge({ foo: 3 }); 
    275       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.'); 
     275      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.'); 
    276276       
    277277      h.remove('foo'); 
    278       assertErrorNotified('Hash#remove is no longer supported, use Hash#unset instead.\n' +  
     278      this.assertErrorNotified('Hash#remove is no longer supported, use Hash#unset instead.\n' +  
    279279        'Please note that Hash#unset only accepts one argument.'); 
    280280       
    281281      document.getElementsByClassName('className'); 
    282       assertNotNotified(); 
     282      this.assertNotNotified(); 
    283283      prototypeUpdateHelper.logLevel = UpdateHelper.Info; 
    284     }} 
     284    } 
    285285  }); 
    286286   
  • spinoffs/prototype/trunk/test/unit/ajax.html

    r8693 r9036  
    8282   
    8383  new Test.Unit.Runner({ 
    84     setup: function()
     84    setup: function()
    8585      $('content').update(''); 
    8686      $('content2').update(''); 
    8787    }, 
    8888     
    89     teardown: function()
     89    teardown: function()
    9090      // hack to cleanup responders 
    9191      Ajax.Responders.responders = [Ajax.Responders.responders[0]]; 
    9292    }, 
    9393     
    94     testSynchronousRequest: function() {with(this) { 
    95       assertEqual("", $("content").innerHTML); 
    96        
    97       assertEqual(0, Ajax.activeRequestCount); 
     94    testSynchronousRequest: function() { 
     95      this.assertEqual("", $("content").innerHTML); 
     96       
     97      this.assertEqual(0, Ajax.activeRequestCount); 
    9898      new Ajax.Request("fixtures/hello.js", { 
    9999        asynchronous: false, 
     
    101101        evalJS: 'force' 
    102102      }); 
    103       assertEqual(0, Ajax.activeRequestCount); 
     103      this.assertEqual(0, Ajax.activeRequestCount); 
    104104       
    105105      var h2 = $("content").firstChild; 
    106       assertEqual("Hello world!", h2.innerHTML); 
    107     }}
    108      
    109     testAsynchronousRequest: function() {with(this) { 
    110       assertEqual("", $("content").innerHTML); 
     106      this.assertEqual("Hello world!", h2.innerHTML); 
     107    }
     108     
     109    testAsynchronousRequest: function() { 
     110      this.assertEqual("", $("content").innerHTML); 
    111111       
    112112      new Ajax.Request("fixtures/hello.js", { 
     
    115115        evalJS: 'force' 
    116116      }); 
    117       wait(1000, function() { 
     117      this.wait(1000, function() { 
    118118        var h2 = $("content").firstChild; 
    119         assertEqual("Hello world!", h2.innerHTML); 
    120       }); 
    121     }}
    122      
    123     testUpdater: function() {with(this) { 
    124       assertEqual("", $("content").innerHTML); 
     119        this.assertEqual("Hello world!", h2.innerHTML); 
     120      }); 
     121    }
     122     
     123    testUpdater: function() { 
     124      this.assertEqual("", $("content").innerHTML); 
    125125       
    126126      new Ajax.Updater("content", "fixtures/content.html", { method:'get' }); 
    127127       
    128       wait(1000, function() { 
    129         assertEqual(sentence, $("content").innerHTML.strip().toLowerCase()); 
     128      this.wait(1000, function() { 
     129        this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase()); 
    130130         
    131131        $('content').update(''); 
    132         assertEqual("", $("content").innerHTML); 
     132        this.assertEqual("", $("content").innerHTML); 
    133133          
    134134        new Ajax.Updater({ success:"content", failure:"content2" }, 
     
    137137        new Ajax.Updater("", "fixtures/content.html", { method:'get', parameters:"pet=monkey" }); 
    138138         
    139         wait(1000, function() { 
    140           assertEqual(sentence, $("content").innerHTML.strip().toLowerCase()); 
    141           assertEqual("", $("content2").innerHTML); 
     139        this.wait(1000, function() { 
     140          this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase()); 
     141          this.assertEqual("", $("content2").innerHTML); 
    142142        }); 
    143143      });  
    144     }}
    145      
    146     testUpdaterWithInsertion: function() {with(this) { 
     144    }
     145     
     146    testUpdaterWithInsertion: function() { 
    147147      $('content').update(); 
    148148      new Ajax.Updater("content", "fixtures/content.html", { method:'get', insertion: Insertion.Top }); 
    149       wait(1000, function() { 
    150         assertEqual(sentence, $("content").innerHTML.strip().toLowerCase()); 
     149      this.wait(1000, function() { 
     150        this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase()); 
    151151        $('content').update(); 
    152152        new Ajax.Updater("content", "fixtures/content.html", { method:'get', insertion: 'bottom' });       
    153         wait(1000, function() { 
    154           assertEqual(sentence, $("content").innerHTML.strip().toLowerCase()); 
     153        this.wait(1000, function() { 
     154          this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase()); 
    155155           
    156156          $('content').update(); 
    157157          new Ajax.Updater("content", "fixtures/content.html", { method:'get', insertion: 'after' });       
    158           wait(1000, function() { 
    159             assertEqual('five dozen', $("content").next().innerHTML.strip().toLowerCase()); 
     158          this.wait(1000, function() { 
     159            this.assertEqual('five dozen', $("content").next().innerHTML.strip().toLowerCase()); 
    160160          }); 
    161161        }); 
    162162      }); 
    163     }}
    164      
    165     testUpdaterOptions: function() {with(this) { 
     163    }
     164     
     165    testUpdaterOptions: function() { 
    166166      var options = { 
    167167        method: 'get', 
     
    172172      var request = new Ajax.Updater("content", "fixtures/hello.js", options); 
    173173      request.options.onComplete = function() {}; 
    174       assertIdentical(Prototype.emptyFunction, options.onComplete); 
    175     }}
    176      
    177     testResponders: function(){with(this) { 
     174      this.assertIdentical(Prototype.emptyFunction, options.onComplete); 
     175    }
     176     
     177    testResponders: function(){ 
    178178      // check for internal responder 
    179       assertEqual(1, Ajax.Responders.responders.length); 
     179      this.assertEqual(1, Ajax.Responders.responders.length); 
    180180       
    181181      var dummyResponder = { 
     
    184184       
    185185      Ajax.Responders.register(dummyResponder); 
    186       assertEqual(2, Ajax.Responders.responders.length); 
     186      this.assertEqual(2, Ajax.Responders.responders.length); 
    187187       
    188188      // don't add twice 
    189189      Ajax.Responders.register(dummyResponder); 
    190       assertEqual(2, Ajax.Responders.responders.length); 
     190      this.assertEqual(2, Ajax.Responders.responders.length); 
    191191       
    192192      Ajax.Responders.unregister(dummyResponder); 
    193       assertEqual(1, Ajax.Responders.responders.length); 
     193      this.assertEqual(1, Ajax.Responders.responders.length); 
    194194       
    195195      var responder = { 
     
    200200      Ajax.Responders.register(responder); 
    201201       
    202       assertEqual(0, responderCounter); 
    203       assertEqual(0, Ajax.activeRequestCount); 
     202      this.assertEqual(0, responderCounter); 
     203      this.assertEqual(0, Ajax.activeRequestCount); 
    204204      new Ajax.Request("fixtures/content.html", { method:'get', parameters:"pet=monkey" }); 
    205       assertEqual(1, responderCounter); 
    206       assertEqual(1, Ajax.activeRequestCount); 
    207        
    208       wait(1000,function() { 
    209         assertEqual(3, responderCounter); 
    210         assertEqual(0, Ajax.activeRequestCount); 
    211       }); 
    212     }}
    213      
    214     testEvalResponseShouldBeCalledBeforeOnComplete: function() {with(this) { 
    215       if (isRunningFromRake) { 
    216         assertEqual("", $("content").innerHTML); 
    217        
    218         assertEqual(0, Ajax.activeRequestCount); 
     205      this.assertEqual(1, responderCounter); 
     206      this.assertEqual(1, Ajax.activeRequestCount); 
     207       
     208      this.wait(1000,function() { 
     209        this.assertEqual(3, responderCounter); 
     210        this.assertEqual(0, Ajax.activeRequestCount); 
     211      }); 
     212    }
     213     
     214    testEvalResponseShouldBeCalledBeforeOnComplete: function() { 
     215      if (this.isRunningFromRake) { 
     216        this.assertEqual("", $("content").innerHTML); 
     217       
     218        this.assertEqual(0, Ajax.activeRequestCount); 
    219219        new Ajax.Request("fixtures/hello.js", extendDefault({ 
    220           onComplete: function(response) { assertNotEqual("", $("content").innerHTML) } 
    221         })); 
    222         assertEqual(0, Ajax.activeRequestCount); 
     220          onComplete: function(response) { this.assertNotEqual("", $("content").innerHTML) }.bind(this) 
     221        })); 
     222        this.assertEqual(0, Ajax.activeRequestCount); 
    223223       
    224224        var h2 = $("content").firstChild; 
    225         assertEqual("Hello world!", h2.innerHTML); 
    226       } else { 
    227         info(message); 
    228       } 
    229     }}
    230      
    231     testContentTypeSetForSimulatedVerbs: function() {with(this) { 
    232       if (isRunningFromRake) { 
     225        this.assertEqual("Hello world!", h2.innerHTML); 
     226      } else { 
     227        this.info(message); 
     228      } 
     229    }
     230     
     231    testContentTypeSetForSimulatedVerbs: function() { 
     232      if (this.isRunningFromRake) { 
    233233        new Ajax.Request('/inspect', extendDefault({ 
    234234          method: 'put', 
    235235          contentType: 'application/bogus', 
    236236          onComplete: function(response) { 
    237             assertEqual('application/bogus; charset=UTF-8', response.responseJSON.headers['content-type']); 
    238           } 
    239         })); 
    240       } else { 
    241         info(message); 
    242       } 
    243     }}
    244      
    245     testOnCreateCallback: function() {with(this) { 
     237            this.assertEqual('application/bogus; charset=UTF-8', response.responseJSON.headers['content-type']); 
     238          }.bind(this) 
     239        })); 
     240      } else { 
     241        this.info(message); 
     242      } 
     243    }
     244     
     245    testOnCreateCallback: function() { 
    246246      new Ajax.Request("fixtures/content.html", extendDefault({ 
    247         onCreate: function(transport) { assertEqual(0, transport.readyState) }
    248         onComplete: function(transport) { assertNotEqual(0, transport.readyState) } 
     247        onCreate: function(transport) { this.assertEqual(0, transport.readyState) }.bind(this)
     248        onComplete: function(transport) { this.assertNotEqual(0, transport.readyState) }.bind(this) 
    249249      })); 
    250     }}
    251      
    252     testEvalJS: function() {with(this) { 
    253       if (isRunningFromRake) { 
     250    }
     251     
     252    testEvalJS: function() { 
     253      if (this.isRunningFromRake) { 
    254254         
    255255        $('content').update(); 
     
    258258          onComplete: function(transport) {  
    259259            var h2 = $("content").firstChild; 
    260             assertEqual("Hello world!", h2.innerHTML); 
    261           } 
     260            this.assertEqual("Hello world!", h2.innerHTML); 
     261          }.bind(this) 
    262262        })); 
    263263         
     
    267267          parameters: Fixtures.js, 
    268268          onComplete: function(transport) {  
    269             assertEqual("", $("content").innerHTML); 
    270           } 
    271         })); 
    272       } else { 
    273         info(message); 
     269            this.assertEqual("", $("content").innerHTML); 
     270          }.bind(this) 
     271        })); 
     272      } else { 
     273        this.info(message); 
    274274      } 
    275275       
     
    279279        onComplete: function(transport) {  
    280280          var h2 = $("content").firstChild; 
    281           assertEqual("Hello world!", h2.innerHTML); 
    282         } 
     281          this.assertEqual("Hello world!", h2.innerHTML); 
     282        }.bind(this) 
    283283      })); 
    284     }}
    285  
    286     testCallbacks: function() {with(this) { 
     284    }
     285 
     286    testCallbacks: function() { 
    287287      var options = extendDefault({ 
    288         onCreate: function(transport) { assertInstanceOf(Ajax.Response, transport) } 
     288        onCreate: function(transport) { this.assertInstanceOf(Ajax.Response, transport) }.bind(this) 
    289289      }); 
    290290       
     
    294294 
    295295      new Ajax.Request("fixtures/content.html", options); 
    296     }}
    297  
    298     testResponseText: function() {with(this) { 
     296    }
     297 
     298    testResponseText: function() { 
    299299      new Ajax.Request("fixtures/empty.html", extendDefault({ 
    300         onComplete: function(transport) { assertEqual('', transport.responseText) } 
     300        onComplete: function(transport) { this.assertEqual('', transport.responseText) }.bind(this) 
    301301      })); 
    302302       
    303303      new Ajax.Request("fixtures/content.html", extendDefault({ 
    304         onComplete: function(transport) { assertEqual(sentence, transport.responseText.toLowerCase()) } 
     304        onComplete: function(transport) { this.assertEqual(sentence, transport.responseText.toLowerCase()) }.bind(this) 
    305305      })); 
    306     }}
    307      
    308     testResponseXML: function() {with(this) { 
    309       if (isRunningFromRake) { 
     306    }
     307     
     308    testResponseXML: function() { 
     309      if (this.isRunningFromRake) { 
    310310        new Ajax.Request("/response", extendDefault({ 
    311311          parameters: Fixtures.xml, 
    312312          onComplete: function(transport) {  
    313             assertEqual('foo', transport.responseXML.getElementsByTagName('name')[0].getAttribute('attr')) 
    314           } 
    315         })); 
    316       } else { 
    317         info(message); 
    318       } 
    319     }}
    320          
    321     testResponseJSON: function() {with(this) { 
    322       if (isRunningFromRake) { 
     313            this.assertEqual('foo', transport.responseXML.getElementsByTagName('name')[0].getAttribute('attr')) 
     314          }.bind(this) 
     315        })); 
     316      } else { 
     317        this.info(message); 
     318      } 
     319    }
     320         
     321    testResponseJSON: function() { 
     322      if (this.isRunningFromRake) { 
    323323        new Ajax.Request("/response", extendDefault({ 
    324324          parameters: Fixtures.json, 
    325           onComplete: function(transport) { assertEqual(123, transport.responseJSON.test) } 
     325          onComplete: function(transport) { this.assertEqual(123, transport.responseJSON.test) }.bind(this) 
    326326        })); 
    327327         
     
    331331            'Content-Type': 'application/json' 
    332332          }, 
    333           onComplete: function(transport) { assertNull(transport.responseJSON) } 
     333          onComplete: function(transport) { this.assertNull(transport.responseJSON) }.bind(this) 
    334334        })); 
    335335         
     
    337337          evalJSON: false, 
    338338          parameters: Fixtures.json, 
    339           onComplete: function(transport) { assertNull(transport.responseJSON) } 
     339          onComplete: function(transport) { this.assertNull(transport.responseJSON) }.bind(this) 
    340340        })); 
    341341       
    342342        new Ajax.Request("/response", extendDefault({ 
    343343          parameters: Fixtures.jsonWithoutContentType, 
    344           onComplete: function(transport) { assertNull(transport.responseJSON) } 
     344          onComplete: function(transport) { this.assertNull(transport.responseJSON) }.bind(this) 
    345345        })); 
    346346       
     
    349349          parameters: Fixtures.invalidJson, 
    350350          onException: function(request, error) { 
    351             assert(error.message.include('Badly formed JSON string')); 
    352             assertInstanceOf(Ajax.Request, request); 
    353           } 
    354         })); 
    355       } else { 
    356         info(message); 
     351            this.assert(error.message.include('Badly formed JSON string')); 
     352            this.assertInstanceOf(Ajax.Request, request); 
     353          }.bind(this) 
     354        })); 
     355      } else { 
     356        this.info(message); 
    357357      } 
    358358       
    359359      new Ajax.Request("fixtures/data.json", extendDefault({ 
    360360        evalJSON: 'force', 
    361         onComplete: function(transport) { assertEqual(123, transport.responseJSON.test) } 
     361        onComplete: function(transport) { this.assertEqual(123, transport.responseJSON.test) }.bind(this) 
    362362      })); 
    363     }}
    364      
    365     testHeaderJSON: function() {with(this) { 
    366       if (isRunningFromRake) { 
     363    }
     364     
     365    testHeaderJSON: function() { 
     366      if (this.isRunningFromRake) { 
    367367        new Ajax.Request("/response", extendDefault({ 
    368368          parameters: Fixtures.headerJson, 
    369369          onComplete: function(transport, json) { 
    370             assertEqual('hello #éà', transport.headerJSON.test); 
    371             assertEqual('hello #éà', json.test); 
    372           } 
     370            this.assertEqual('hello #éà', transport.headerJSON.test); 
     371            this.assertEqual('hello #éà', json.test); 
     372          }.bind(this) 
    373373        })); 
    374374       
    375375        new Ajax.Request("/response", extendDefault({ 
    376376          onComplete: function(transport, json) {  
    377             assertNull(transport.headerJSON) 
    378             assertNull(json) 
    379           } 
    380         })); 
    381       } else { 
    382         info(message); 
    383       } 
    384     }}
    385      
    386     testGetHeader: function() {with(this) { 
    387       if (isRunningFromRake) { 
     377            this.assertNull(transport.headerJSON) 
     378            this.assertNull(json) 
     379          }.bind(this) 
     380        })); 
     381      } else { 
     382        this.info(message); 
     383      } 
     384    }
     385     
     386    testGetHeader: function() { 
     387      if (this.isRunningFromRake) { 
    388388       new Ajax.Request("/response", extendDefault({ 
    389389          parameters: { 'X-TEST': 'some value' }, 
    390390          onComplete: function(transport) { 
    391             assertEqual('some value', transport.getHeader('X-Test')); 
    392             assertNull(transport.getHeader('X-Inexistant')); 
    393           } 
    394         })); 
    395       } else { 
    396         info(message); 
    397       } 
    398     }}
    399      
    400     testParametersCanBeHash: function() {with(this) { 
    401       if (isRunningFromRake) { 
     391            this.assertEqual('some value', transport.getHeader('X-Test')); 
     392            this.assertNull(transport.getHeader('X-Inexistant')); 
     393          }.bind(this) 
     394        })); 
     395      } else { 
     396        this.info(message); 
     397      } 
     398    }
     399     
     400    testParametersCanBeHash: function() { 
     401      if (this.isRunningFromRake) { 
    402402        new Ajax.Request("/response", extendDefault({ 
    403403          parameters: $H({ "one": "two", "three": "four" }), 
    404404          onComplete: function(transport) { 
    405             assertEqual("two", transport.getHeader("one")); 
    406             assertEqual("four", transport.getHeader("three")); 
    407             assertNull(transport.getHeader("toObject")); 
    408           } 
    409         })); 
    410       } else { 
    411         info(message); 
    412       } 
    413     }}
    414      
    415     testIsSameOriginMethod: function() {with(this) { 
     405            this.assertEqual("two", transport.getHeader("one")); 
     406            this.assertEqual("four", transport.getHeader("three")); 
     407            this.assertNull(transport.getHeader("toObject")); 
     408          }.bind(this) 
     409        })); 
     410      } else { 
     411        this.info(message); 
     412      } 
     413    }
     414     
     415    testIsSameOriginMethod: function() { 
    416416      var isSameOrigin = Ajax.Request.prototype.isSameOrigin; 
    417       assert(isSameOrigin.call({ url: '/foo/bar.html' }), '/foo/bar.html'); 
    418       assert(isSameOrigin.call({ url: window.location.toString() }), window.location); 
    419       assert(!isSameOrigin.call({ url: 'http://example.com' }), 'http://example.com'); 
    420  
    421       if (isRunningFromRake) { 
     417      this.assert(isSameOrigin.call({ url: '/foo/bar.html' }), '/foo/bar.html'); 
     418      this.assert(isSameOrigin.call({ url: window.location.toString() }), window.location); 
     419      this.assert(!isSameOrigin.call({ url: 'http://example.com' }), 'http://example.com'); 
     420 
     421      if (this.isRunningFromRake) { 
    422422        Ajax.Request.prototype.isSameOrigin = function() { 
    423423          return false 
     
    428428          parameters: Fixtures.js, 
    429429          onComplete: function(transport) {  
    430             assertEqual("same origin policy", $("content").innerHTML); 
    431           } 
     430            this.assertEqual("same origin policy", $("content").innerHTML); 
     431          }.bind(this) 
    432432        })); 
    433433 
     
    435435          parameters: Fixtures.invalidJson, 
    436436          onException: function(request, error) { 
    437             assert(error.message.include('Badly formed JSON string')); 
    438           } 
     437            this.assert(error.message.include('Badly formed JSON string')); 
     438          }.bind(this) 
    439439        })); 
    440440 
     
    442442          parameters: { 'X-JSON': '{});window.attacked = true;({}' }, 
    443443          onException: function(request, error) { 
    444             assert(error.message.include('Badly formed JSON string')); 
    445           } 
     444            this.assert(error.message.include('Badly formed JSON string')); 
     445          }.bind(this) 
    446446        })); 
    447447 
    448448        Ajax.Request.prototype.isSameOrigin = isSameOrigin; 
    449449      } else { 
    450         info(message); 
    451       } 
    452     }} 
     450        this.info(message); 
     451      } 
     452    } 
    453453  }); 
    454454// ]]> 
  • spinoffs/prototype/trunk/test/unit/array.html

    r8572 r9036  
    3333 
    3434  new Test.Unit.Runner({ 
    35     test$A: function(){ with(this) { 
    36       assertEnumEqual([], $A({})); 
    37     }}
    38      
    39     testToArrayOnArguments: function(){ with(this) { 
     35    test$A: function(){ 
     36      this.assertEnumEqual([], $A({})); 
     37    }
     38     
     39    testToArrayOnArguments: function(){ 
    4040      function toArrayOnArguments(){ 
    4141        globalArgsTest = $A(arguments); 
    4242      } 
    4343      toArrayOnArguments(); 
    44       assertEnumEqual([], globalArgsTest); 
     44      this.assertEnumEqual([], globalArgsTest); 
    4545      toArrayOnArguments('foo'); 
    46       assertEnumEqual(['foo'], globalArgsTest); 
     46      this.assertEnumEqual(['foo'], globalArgsTest); 
    4747      toArrayOnArguments('foo','bar'); 
    48       assertEnumEqual(['foo','bar'], globalArgsTest); 
    49     }}
    50      
    51     testToArrayOnNodeList: function(){ with(this) { 
     48      this.assertEnumEqual(['foo','bar'], globalArgsTest);