 
 
     it "should get the access token from login.vk.com", ( done ) ->
-      vk.request = ( method, url, params, callback ) ->
+      vk.request = ({ method, url, params, callback }) ->
         method.should.equal "GET"
         url.should.equal "https://login.vk.com/"
         params.should.deep.equal



    it "should reject promise when data.error exists", ( done ) ->
      vk.request = ( method, url, params, callback ) ->
        callback response: "foo", error: "exists"

      vk.method fakeMethod, foo: "bar"



    it "should make a get xhr and call back with parsed json", ( done ) ->
      vk.request
        method: "GET"
        url: fakeUrl
        params: fakeParams
        callback: ( data ) ->
          data.should.deep.equal fakeData

          done()

      fakeXhr.requests.length.should.equal 1
      expect( fakeXhr.requests[ 0 ].method ).to.equal "GET"
      expect( fakeXhr.requests[ 0 ].withCredentials ).to.equal false
      expect( fakeXhr.requests[ 0 ].url ).to.equal fakeUrl + "?foo=foo%202&bar=bar%2F2"

      fakeXhr.requests[ 0 ].respond 200, {}, JSON.stringify fakeData


    it "should make a post xhr and call back with parsed json", ( done ) ->
      vk.request
        method: "POST"
        url: fakeUrl
        params: fakeParams
        callback: ( data ) ->
          data.should.deep.equal fakeData

          done()

      fakeXhr.requests.length.should.equal 1
      expect( fakeXhr.requests[ 0 ].method ).to.equal "POST"
      expect( fakeXhr.requests[ 0 ].withCredentials ).to.equal false
      expect( fakeXhr.requests[ 0 ].url ).to.equal fakeUrl
      expect( fakeXhr.requests[ 0 ].requestHeaders ).to.have.property "Content-Type"
      expect( fakeXhr.requests[ 0 ].requestHeaders[ "Content-Type"] ).to.contain "application/x-www-form-urlencoded"
      expect( fakeXhr.requests[ 0 ].requestBody ).to.equal "foo=foo%202&bar=bar%2F2"

      fakeXhr.requests[ 0 ].respond 200, {}, JSON.stringify fakeData


    it "should use credentials when specified", ( done ) ->
      vk.request
        method: "GET"
        url: fakeUrl
        withCredentials: true
        params: fakeParams
        callback: ( data ) ->
          data.should.deep.equal fakeData

          done()

      fakeXhr.requests.length.should.equal 1
      expect( fakeXhr.requests[ 0 ].method ).to.equal "GET"
