(function(){
/*
   Tests that calling .doGet(), .doPost(), .doPut(), .doDelete() pass through to streamingXhr
   correctly. streamingXhr is a stub so no actual calls are made. 
 */

var streamingStub;

function streamingXhrShouldHaveBeenGiven(/* arguments */) {

   var expected = Array.prototype.slice.apply(arguments);

   function alwaysCalledWith( expectedArgs ){
   
      return streamingStub.alwaysCalledWithMatch.apply( streamingStub, expectedArgs );    
   }

   if( !alwaysCalledWith(expected) ) {
   
      fail( 'arguments given to streamingXhr not as expected. Wanted:',
            JSON.stringify( expected ),
            'but have calls:',
            JSON.stringify(streamingStub.args)
      );
   }   
}

TestCase("browserApiTest", {

   setUp: function() {
      streamingStub = sinon.stub(window, 'streamingXhr');      
   },
   
   tearDown: function() {
      streamingStub.restore();   
   },
              
   // GET
   testGetViaShortcut:function(){   
      var doneCallback = sinon.stub();
   
      oboe.doGet('http://example.com/oboez', doneCallback);
      
      streamingXhrShouldHaveBeenGiven(
         'GET',
         'http://example.com/oboez',
         undefined,
         sinon.match.func,
         sinon.match.func
      );   
   },
      
   testGetViaOptionsObject:function(){   
      var doneCallback = sinon.stub();
   
      oboe.doGet({url: 'http://example.com/oboez', success: doneCallback});
      
      streamingXhrShouldHaveBeenGiven(
         'GET',
         'http://example.com/oboez',
         undefined,
         sinon.match.func,
         sinon.match.func
      );   
   },   
   
   // DELETE
   testDelete:function(){
      var doneCallback = sinon.stub();
   
      oboe.doDelete('http://example.com/oboez', doneCallback);
    
      streamingXhrShouldHaveBeenGiven(
         'DELETE',
         'http://example.com/oboez',
         undefined,
         sinon.match.func,
         sinon.match.func
      );
   },
     
         
   // POST
   testPost:function(){
      var doneCallback = sinon.stub();
   
      oboe.doPost('http://example.com/oboez', 'my_data', doneCallback);
      
      streamingXhrShouldHaveBeenGiven(
         'POST',
         'http://example.com/oboez',
         'my_data',
         sinon.match.func,
         sinon.match.func
      );   
   },
   
   testCanPostAnObject:function(){
      var doneCallback = sinon.stub();
   
      oboe.doPost('http://example.com/oboez', [1,2,3,4,5], doneCallback);
      
      streamingXhrShouldHaveBeenGiven( 
         'POST',
         'http://example.com/oboez',
         [1,2,3,4,5],
         sinon.match.func,
         sinon.match.func
      );   
   },   
   
   testPostViaOptionsObject:function(){   
      var doneCallback = sinon.stub();
   
      oboe.doPost({url: 'http://example.com/oboez', body:'my_data', success: doneCallback});
      
      streamingXhrShouldHaveBeenGiven( 
         'POST',
         'http://example.com/oboez',
         'my_data',
         sinon.match.func,
         sinon.match.func
      );   
   },   
   
   // PUT
   
   testPut:function(){
      var doneCallback = sinon.stub();
   
      oboe.doPut('http://example.com/oboez', 'my_data', doneCallback);
      
      streamingXhrShouldHaveBeenGiven( 
         'PUT',
         'http://example.com/oboez',
         'my_data',
         sinon.match.func,
         sinon.match.func
      );   
   }
            
      
});


})();

@@ -460,16 +460,854 @@
    %0A   %7D
+%0A   %0A   function anyToString(thing)%7B%0A      %0A      if( thing === null ) %7B%0A         return 'null';%0A      %7D%0A      %0A      if( thing === undefined ) %7B%0A         return 'undefined';%0A      %7D%0A%0A      if( typeof thing == 'string' ) %7B%0A         return '(string)' + thing;%0A      %7D%0A      %0A      if( thing.constructor == Array ) %7B%0A         return '%5B' + thing.map(anyToString).join(', ') + '%5D';%0A      %7D      %0A%0A      if( typeof thing == 'function' ) %7B%0A         return thing.name? 'function ' + thing.name : 'anon function'; %0A      %7D%0A      %0A      if( typeof thing == 'object' ) %7B%0A            %0A         return (%0A                  thing.constructor == Object? %0A                     '' %0A                  :  '(' + (thing.constructor.name) + ')'%0A                ) %0A                + JSON.stringify(thing);%0A      %7D%0A      %0A      return JSON.stringify(thing);%0A   %7D
 %0A%0A   if(
@@ -1431,32 +1431,28 @@
     
-JSON.stringify( 
+anyToString(
 expected
  ),%0A
@@ -1447,17 +1447,16 @@
 expected
- 
 ),%0A     
@@ -1471,22 +1471,38 @@
 but have
+ (first recorded)
  call
-s
 :',%0A    
@@ -1509,30 +1509,27 @@
         
-JSON.s
+anyToS
 tring
-ify
 (streami
@@ -1539,16 +1539,19 @@
 tub.args
+%5B0%5D
 )%0A      

Make failure message more lucid