Updated rspec to v3 and replaced rcov with simplecov.
Also used transpec to convert from "should" syntax to preferred "expect" syntax.
This commit is contained in:
		
							parent
							
								
									bfa5225766
								
							
						
					
					
						commit
						78ff182905
					
				
							
								
								
									
										7
									
								
								Gemfile
								
								
								
								
							
							
						
						
									
										7
									
								
								Gemfile
								
								
								
								
							| 
						 | 
				
			
			@ -33,9 +33,8 @@ end
 | 
			
		|||
group :test, :development do
 | 
			
		||||
  gem 'json', '~> 1.7.7'
 | 
			
		||||
  gem 'rake', '>= 0.9.0'
 | 
			
		||||
  gem 'rspec', '>= 2.11.0'
 | 
			
		||||
  gem 'rcov', '>= 0.9.9', :platform => :mri_18
 | 
			
		||||
  gem 'rspec', '~> 3.0'
 | 
			
		||||
  gem 'simplecov', :platforms => [:ruby_19, :ruby_20], :require => false
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
gem 'idn', :platform => :mri_18
 | 
			
		||||
gem 'idn', :platforms => :mri_18
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -28,9 +28,9 @@ describe Google::APIClient::BatchRequest do
 | 
			
		|||
  it 'should raise an error if making an empty batch request' do
 | 
			
		||||
    batch = Google::APIClient::BatchRequest.new
 | 
			
		||||
 | 
			
		||||
    (lambda do
 | 
			
		||||
    expect(lambda do
 | 
			
		||||
      CLIENT.execute(batch)
 | 
			
		||||
    end).should raise_error(Google::APIClient::BatchError)
 | 
			
		||||
    end).to raise_error(Google::APIClient::BatchError)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it 'should allow query parameters in batch requests' do
 | 
			
		||||
| 
						 | 
				
			
			@ -39,7 +39,7 @@ describe Google::APIClient::BatchRequest do
 | 
			
		|||
      'a' => '12345'
 | 
			
		||||
    })
 | 
			
		||||
    method, uri, headers, body = batch.to_http_request
 | 
			
		||||
    body.read.should include("/?a=12345")
 | 
			
		||||
    expect(body.read).to include("/?a=12345")
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe 'with the discovery API' do
 | 
			
		||||
| 
						 | 
				
			
			@ -73,8 +73,8 @@ describe Google::APIClient::BatchRequest do
 | 
			
		|||
        expected_ids = ids.clone
 | 
			
		||||
        batch = Google::APIClient::BatchRequest.new do |result|
 | 
			
		||||
          block_called += 1
 | 
			
		||||
          result.status.should == 200
 | 
			
		||||
          expected_ids.should include(result.response.call_id)
 | 
			
		||||
          expect(result.status).to eq(200)
 | 
			
		||||
          expect(expected_ids).to include(result.response.call_id)
 | 
			
		||||
          expected_ids.delete(result.response.call_id)
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -82,7 +82,7 @@ describe Google::APIClient::BatchRequest do
 | 
			
		|||
        batch.add(@call2, ids[1])
 | 
			
		||||
 | 
			
		||||
        CLIENT.execute(batch)
 | 
			
		||||
        block_called.should == 2
 | 
			
		||||
        expect(block_called).to eq(2)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should execute both when using individual callbacks' do
 | 
			
		||||
| 
						 | 
				
			
			@ -91,25 +91,25 @@ describe Google::APIClient::BatchRequest do
 | 
			
		|||
        call1_returned, call2_returned = false, false
 | 
			
		||||
        batch.add(@call1) do |result|
 | 
			
		||||
          call1_returned = true
 | 
			
		||||
          result.status.should == 200
 | 
			
		||||
          expect(result.status).to eq(200)
 | 
			
		||||
        end
 | 
			
		||||
        batch.add(@call2) do |result|
 | 
			
		||||
          call2_returned = true
 | 
			
		||||
          result.status.should == 200
 | 
			
		||||
          expect(result.status).to eq(200)
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        CLIENT.execute(batch)
 | 
			
		||||
        call1_returned.should == true
 | 
			
		||||
        call2_returned.should == true
 | 
			
		||||
        expect(call1_returned).to be_truthy
 | 
			
		||||
        expect(call2_returned).to be_truthy
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should raise an error if using the same call ID more than once' do
 | 
			
		||||
        batch = Google::APIClient::BatchRequest.new
 | 
			
		||||
 | 
			
		||||
        (lambda do
 | 
			
		||||
        expect(lambda do
 | 
			
		||||
          batch.add(@call1, 'my_id')
 | 
			
		||||
          batch.add(@call2, 'my_id')
 | 
			
		||||
        end).should raise_error(Google::APIClient::BatchError)
 | 
			
		||||
        end).to raise_error(Google::APIClient::BatchError)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -138,13 +138,13 @@ describe Google::APIClient::BatchRequest do
 | 
			
		|||
        expected_ids = ids.clone
 | 
			
		||||
        batch = Google::APIClient::BatchRequest.new do |result|
 | 
			
		||||
          block_called += 1
 | 
			
		||||
          expected_ids.should include(result.response.call_id)
 | 
			
		||||
          expect(expected_ids).to include(result.response.call_id)
 | 
			
		||||
          expected_ids.delete(result.response.call_id)
 | 
			
		||||
          if result.response.call_id == ids[0]
 | 
			
		||||
            result.status.should == 200
 | 
			
		||||
            expect(result.status).to eq(200)
 | 
			
		||||
          else
 | 
			
		||||
            result.status.should >= 400
 | 
			
		||||
            result.status.should < 500
 | 
			
		||||
            expect(result.status).to be >= 400
 | 
			
		||||
            expect(result.status).to be < 500
 | 
			
		||||
          end
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -152,7 +152,7 @@ describe Google::APIClient::BatchRequest do
 | 
			
		|||
        batch.add(@call2, ids[1])
 | 
			
		||||
 | 
			
		||||
        CLIENT.execute(batch)
 | 
			
		||||
        block_called.should == 2
 | 
			
		||||
        expect(block_called).to eq(2)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should execute both when using individual callbacks' do
 | 
			
		||||
| 
						 | 
				
			
			@ -161,17 +161,17 @@ describe Google::APIClient::BatchRequest do
 | 
			
		|||
        call1_returned, call2_returned = false, false
 | 
			
		||||
        batch.add(@call1) do |result|
 | 
			
		||||
          call1_returned = true
 | 
			
		||||
          result.status.should == 200
 | 
			
		||||
          expect(result.status).to eq(200)
 | 
			
		||||
        end
 | 
			
		||||
        batch.add(@call2) do |result|
 | 
			
		||||
          call2_returned = true
 | 
			
		||||
          result.status.should >= 400
 | 
			
		||||
          result.status.should < 500
 | 
			
		||||
          expect(result.status).to be >= 400
 | 
			
		||||
          expect(result.status).to be < 500
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        CLIENT.execute(batch)
 | 
			
		||||
        call1_returned.should == true
 | 
			
		||||
        call2_returned.should == true
 | 
			
		||||
        expect(call1_returned).to be_truthy
 | 
			
		||||
        expect(call2_returned).to be_truthy
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
| 
						 | 
				
			
			@ -236,12 +236,12 @@ describe Google::APIClient::BatchRequest do
 | 
			
		|||
        batch.add(@call1, '1').add(@call2, '2')
 | 
			
		||||
        request = batch.to_env(CLIENT.connection)
 | 
			
		||||
        boundary = Google::APIClient::BatchRequest::BATCH_BOUNDARY
 | 
			
		||||
        request[:method].to_s.downcase.should == 'post'
 | 
			
		||||
        request[:url].to_s.should == 'https://www.googleapis.com/batch'
 | 
			
		||||
        request[:request_headers]['Content-Type'].should == "multipart/mixed;boundary=#{boundary}"
 | 
			
		||||
        # TODO - Fix headers
 | 
			
		||||
        #expected_body = /--#{Regexp.escape(boundary)}\nContent-Type: +application\/http\nContent-ID: +<[\w-]+\+1>\n\nPOST +https:\/\/www.googleapis.com\/calendar\/v3\/calendars\/myemail@mydomain.tld\/events +HTTP\/1.1\nContent-Type: +application\/json\n\n#{Regexp.escape(@call1[:body])}\n\n--#{boundary}\nContent-Type: +application\/http\nContent-ID: +<[\w-]+\+2>\n\nPOST +https:\/\/www.googleapis.com\/calendar\/v3\/calendars\/myemail@mydomain.tld\/events HTTP\/1.1\nContent-Type: +application\/json\n\n#{Regexp.escape(@call2[:body])}\n\n--#{Regexp.escape(boundary)}--/
 | 
			
		||||
        #request[:body].read.gsub("\r", "").should =~ expected_body
 | 
			
		||||
        expect(request[:method].to_s.downcase).to eq('post')
 | 
			
		||||
        expect(request[:url].to_s).to eq('https://www.googleapis.com/batch')
 | 
			
		||||
        expect(request[:request_headers]['Content-Type']).to eq("multipart/mixed;boundary=#{boundary}")
 | 
			
		||||
        body = request[:body].read
 | 
			
		||||
        expect(body).to include(@call1[:body])
 | 
			
		||||
        expect(body).to include(@call2[:body])
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -35,40 +35,40 @@ describe Google::APIClient do
 | 
			
		|||
  end
 | 
			
		||||
 | 
			
		||||
  it 'should raise a type error for bogus authorization' do
 | 
			
		||||
    (lambda do
 | 
			
		||||
    expect(lambda do
 | 
			
		||||
      Google::APIClient.new(:application_name => 'API Client Tests', :authorization => 42)
 | 
			
		||||
    end).should raise_error(TypeError)
 | 
			
		||||
    end).to raise_error(TypeError)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it 'should not be able to retrieve the discovery document for a bogus API' do
 | 
			
		||||
    (lambda do
 | 
			
		||||
    expect(lambda do
 | 
			
		||||
      CLIENT.discovery_document('bogus')
 | 
			
		||||
    end).should raise_error(Google::APIClient::TransmissionError)
 | 
			
		||||
    (lambda do
 | 
			
		||||
    end).to raise_error(Google::APIClient::TransmissionError)
 | 
			
		||||
    expect(lambda do
 | 
			
		||||
      CLIENT.discovered_api('bogus')
 | 
			
		||||
    end).should raise_error(Google::APIClient::TransmissionError)
 | 
			
		||||
    end).to raise_error(Google::APIClient::TransmissionError)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it 'should raise an error for bogus services' do
 | 
			
		||||
    (lambda do
 | 
			
		||||
    expect(lambda do
 | 
			
		||||
      CLIENT.discovered_api(42)
 | 
			
		||||
    end).should raise_error(TypeError)
 | 
			
		||||
    end).to raise_error(TypeError)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it 'should raise an error for bogus services' do
 | 
			
		||||
    (lambda do
 | 
			
		||||
    expect(lambda do
 | 
			
		||||
      CLIENT.preferred_version(42)
 | 
			
		||||
    end).should raise_error(TypeError)
 | 
			
		||||
    end).to raise_error(TypeError)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it 'should raise an error for bogus methods' do
 | 
			
		||||
    (lambda do
 | 
			
		||||
    expect(lambda do
 | 
			
		||||
      CLIENT.execute(42)
 | 
			
		||||
    end).should raise_error(TypeError)
 | 
			
		||||
    end).to raise_error(TypeError)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it 'should not return a preferred version for bogus service names' do
 | 
			
		||||
    CLIENT.preferred_version('bogus').should == nil
 | 
			
		||||
    expect(CLIENT.preferred_version('bogus')).to eq(nil)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe 'with the prediction API' do
 | 
			
		||||
| 
						 | 
				
			
			@ -80,7 +80,7 @@ describe Google::APIClient do
 | 
			
		|||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should correctly determine the discovery URI' do
 | 
			
		||||
      CLIENT.discovery_uri('prediction').should ===
 | 
			
		||||
      expect(CLIENT.discovery_uri('prediction')).to be ===
 | 
			
		||||
        'https://www.googleapis.com/discovery/v1/apis/prediction/v1/rest'
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -135,61 +135,61 @@ describe Google::APIClient do
 | 
			
		|||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should correctly generate API objects' do
 | 
			
		||||
      CLIENT.discovered_api('prediction', 'v1.2').name.should == 'prediction'
 | 
			
		||||
      CLIENT.discovered_api('prediction', 'v1.2').version.should == 'v1.2'
 | 
			
		||||
      CLIENT.discovered_api(:prediction, 'v1.2').name.should == 'prediction'
 | 
			
		||||
      CLIENT.discovered_api(:prediction, 'v1.2').version.should == 'v1.2'
 | 
			
		||||
      expect(CLIENT.discovered_api('prediction', 'v1.2').name).to eq('prediction')
 | 
			
		||||
      expect(CLIENT.discovered_api('prediction', 'v1.2').version).to eq('v1.2')
 | 
			
		||||
      expect(CLIENT.discovered_api(:prediction, 'v1.2').name).to eq('prediction')
 | 
			
		||||
      expect(CLIENT.discovered_api(:prediction, 'v1.2').version).to eq('v1.2')
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should discover methods' do
 | 
			
		||||
      CLIENT.discovered_method(
 | 
			
		||||
      expect(CLIENT.discovered_method(
 | 
			
		||||
        'prediction.training.insert', 'prediction', 'v1.2'
 | 
			
		||||
      ).name.should == 'insert'
 | 
			
		||||
      CLIENT.discovered_method(
 | 
			
		||||
      ).name).to eq('insert')
 | 
			
		||||
      expect(CLIENT.discovered_method(
 | 
			
		||||
        :'prediction.training.insert', :prediction, 'v1.2'
 | 
			
		||||
      ).name.should == 'insert'
 | 
			
		||||
      CLIENT.discovered_method(
 | 
			
		||||
      ).name).to eq('insert')
 | 
			
		||||
      expect(CLIENT.discovered_method(
 | 
			
		||||
        'prediction.training.delete', 'prediction', 'v1.2'
 | 
			
		||||
      ).name.should == 'delete'
 | 
			
		||||
      ).name).to eq('delete')
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should define the origin API in discovered methods' do
 | 
			
		||||
      CLIENT.discovered_method(
 | 
			
		||||
      expect(CLIENT.discovered_method(
 | 
			
		||||
        'prediction.training.insert', 'prediction', 'v1.2'
 | 
			
		||||
      ).api.name.should == 'prediction'
 | 
			
		||||
      ).api.name).to eq('prediction')
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should not find methods that are not in the discovery document' do
 | 
			
		||||
      CLIENT.discovered_method(
 | 
			
		||||
      expect(CLIENT.discovered_method(
 | 
			
		||||
        'prediction.bogus', 'prediction', 'v1.2'
 | 
			
		||||
      ).should == nil
 | 
			
		||||
      )).to eq(nil)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should raise an error for bogus methods' do
 | 
			
		||||
      (lambda do
 | 
			
		||||
      expect(lambda do
 | 
			
		||||
        CLIENT.discovered_method(42, 'prediction', 'v1.2')
 | 
			
		||||
      end).should raise_error(TypeError)
 | 
			
		||||
      end).to raise_error(TypeError)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should raise an error for bogus methods' do
 | 
			
		||||
      (lambda do
 | 
			
		||||
      expect(lambda do
 | 
			
		||||
        CLIENT.execute(:api_method => CLIENT.discovered_api('prediction', 'v1.2'))
 | 
			
		||||
      end).should raise_error(TypeError)
 | 
			
		||||
      end).to raise_error(TypeError)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should correctly determine the preferred version' do
 | 
			
		||||
      CLIENT.preferred_version('prediction').version.should_not == 'v1'
 | 
			
		||||
      CLIENT.preferred_version(:prediction).version.should_not == 'v1'
 | 
			
		||||
      expect(CLIENT.preferred_version('prediction').version).not_to eq('v1')
 | 
			
		||||
      expect(CLIENT.preferred_version(:prediction).version).not_to eq('v1')
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should return a batch path' do
 | 
			
		||||
      CLIENT.discovered_api('prediction', 'v1.2').batch_path.should_not be_nil
 | 
			
		||||
      expect(CLIENT.discovered_api('prediction', 'v1.2').batch_path).not_to be_nil
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should generate valid requests' do
 | 
			
		||||
      conn = stub_connection do |stub|
 | 
			
		||||
        stub.post('/prediction/v1.2/training?data=12345') do |env|
 | 
			
		||||
          env[:body].should == ''
 | 
			
		||||
          expect(env[:body]).to eq('')
 | 
			
		||||
          [200, {}, '{}']
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
| 
						 | 
				
			
			@ -207,7 +207,7 @@ describe Google::APIClient do
 | 
			
		|||
        # bare ampersand (&) in 0.4.7. ensure that it gets converted
 | 
			
		||||
        # to a CGI-escaped semicolon (%3B) instead.
 | 
			
		||||
        stub.post('/prediction/v1.2/training?data=12345%3B67890') do |env|
 | 
			
		||||
          env[:body].should == ''
 | 
			
		||||
          expect(env[:body]).to eq('')
 | 
			
		||||
          [200, {}, '{}']
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
| 
						 | 
				
			
			@ -222,7 +222,7 @@ describe Google::APIClient do
 | 
			
		|||
    it 'should generate valid requests when multivalued parameters are passed' do
 | 
			
		||||
      conn = stub_connection do |stub|
 | 
			
		||||
         stub.post('/prediction/v1.2/training?data=1&data=2') do |env|
 | 
			
		||||
           env.params['data'].should include('1', '2')
 | 
			
		||||
           expect(env.params['data']).to include('1', '2')
 | 
			
		||||
          [200, {}, '{}']
 | 
			
		||||
         end
 | 
			
		||||
       end
 | 
			
		||||
| 
						 | 
				
			
			@ -271,7 +271,7 @@ describe Google::APIClient do
 | 
			
		|||
 | 
			
		||||
      conn = stub_connection do |stub|
 | 
			
		||||
        stub.post('/prediction/v1.2/training') do |env|
 | 
			
		||||
          env[:url].host.should == 'testing-domain.example.com'
 | 
			
		||||
          expect(env[:url].host).to eq('testing-domain.example.com')
 | 
			
		||||
          [200, {}, '{}']          
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
| 
						 | 
				
			
			@ -291,8 +291,8 @@ describe Google::APIClient do
 | 
			
		|||
 | 
			
		||||
      conn = stub_connection do |stub|
 | 
			
		||||
        stub.post('/prediction/v1.2/training?data=12345') do |env|
 | 
			
		||||
          env[:request_headers].should have_key('Authorization')
 | 
			
		||||
          env[:request_headers]['Authorization'].should =~ /^OAuth/
 | 
			
		||||
          expect(env[:request_headers]).to have_key('Authorization')
 | 
			
		||||
          expect(env[:request_headers]['Authorization']).to match(/^OAuth/)
 | 
			
		||||
          [200, {}, '{}']
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
| 
						 | 
				
			
			@ -311,8 +311,8 @@ describe Google::APIClient do
 | 
			
		|||
 | 
			
		||||
      conn = stub_connection do |stub|
 | 
			
		||||
        stub.post('/prediction/v1.2/training?data=12345') do |env|
 | 
			
		||||
          env[:request_headers].should have_key('Authorization')
 | 
			
		||||
          env[:request_headers]['Authorization'].should =~ /^Bearer/
 | 
			
		||||
          expect(env[:request_headers]).to have_key('Authorization')
 | 
			
		||||
          expect(env[:request_headers]['Authorization']).to match(/^Bearer/)
 | 
			
		||||
          [200, {}, '{}']          
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
| 
						 | 
				
			
			@ -333,7 +333,7 @@ describe Google::APIClient do
 | 
			
		|||
        @prediction.training.insert,
 | 
			
		||||
        {'data' => '12345'}
 | 
			
		||||
      )
 | 
			
		||||
      result.response.status.should == 401
 | 
			
		||||
      expect(result.response.status).to eq(401)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should not be able to execute improperly authorized requests' do
 | 
			
		||||
| 
						 | 
				
			
			@ -343,11 +343,11 @@ describe Google::APIClient do
 | 
			
		|||
        @prediction.training.insert,
 | 
			
		||||
        {'data' => '12345'}
 | 
			
		||||
      )
 | 
			
		||||
      result.response.status.should == 401
 | 
			
		||||
      expect(result.response.status).to eq(401)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should not be able to execute improperly authorized requests' do
 | 
			
		||||
      (lambda do
 | 
			
		||||
      expect(lambda do
 | 
			
		||||
        CLIENT.authorization = :oauth_1
 | 
			
		||||
        CLIENT.authorization.token_credential_key = '12345'
 | 
			
		||||
        CLIENT.authorization.token_credential_secret = '12345'
 | 
			
		||||
| 
						 | 
				
			
			@ -355,25 +355,25 @@ describe Google::APIClient do
 | 
			
		|||
          @prediction.training.insert,
 | 
			
		||||
          {'data' => '12345'}
 | 
			
		||||
        )
 | 
			
		||||
      end).should raise_error(Google::APIClient::ClientError)
 | 
			
		||||
      end).to raise_error(Google::APIClient::ClientError)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should not be able to execute improperly authorized requests' do
 | 
			
		||||
      (lambda do
 | 
			
		||||
      expect(lambda do
 | 
			
		||||
        CLIENT.authorization = :oauth_2
 | 
			
		||||
        CLIENT.authorization.access_token = '12345'
 | 
			
		||||
        result = CLIENT.execute!(
 | 
			
		||||
          @prediction.training.insert,
 | 
			
		||||
          {'data' => '12345'}
 | 
			
		||||
        )
 | 
			
		||||
      end).should raise_error(Google::APIClient::ClientError)
 | 
			
		||||
      end).to raise_error(Google::APIClient::ClientError)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should correctly handle unnamed parameters' do
 | 
			
		||||
      conn = stub_connection do |stub|
 | 
			
		||||
        stub.post('/prediction/v1.2/training') do |env|
 | 
			
		||||
          env[:request_headers].should have_key('Content-Type')
 | 
			
		||||
          env[:request_headers]['Content-Type'].should == 'application/json'
 | 
			
		||||
          expect(env[:request_headers]).to have_key('Content-Type')
 | 
			
		||||
          expect(env[:request_headers]['Content-Type']).to eq('application/json')
 | 
			
		||||
          [200, {}, '{}']
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
| 
						 | 
				
			
			@ -396,32 +396,32 @@ describe Google::APIClient do
 | 
			
		|||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should correctly determine the discovery URI' do
 | 
			
		||||
      CLIENT.discovery_uri('plus').should ===
 | 
			
		||||
      expect(CLIENT.discovery_uri('plus')).to be ===
 | 
			
		||||
        'https://www.googleapis.com/discovery/v1/apis/plus/v1/rest'
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should find APIs that are in the discovery document' do
 | 
			
		||||
      CLIENT.discovered_api('plus').name.should == 'plus'
 | 
			
		||||
      CLIENT.discovered_api('plus').version.should == 'v1'
 | 
			
		||||
      CLIENT.discovered_api(:plus).name.should == 'plus'
 | 
			
		||||
      CLIENT.discovered_api(:plus).version.should == 'v1'
 | 
			
		||||
      expect(CLIENT.discovered_api('plus').name).to eq('plus')
 | 
			
		||||
      expect(CLIENT.discovered_api('plus').version).to eq('v1')
 | 
			
		||||
      expect(CLIENT.discovered_api(:plus).name).to eq('plus')
 | 
			
		||||
      expect(CLIENT.discovered_api(:plus).version).to eq('v1')
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should find methods that are in the discovery document' do
 | 
			
		||||
      # TODO(bobaman) Fix this when the RPC names are correct
 | 
			
		||||
      CLIENT.discovered_method(
 | 
			
		||||
      expect(CLIENT.discovered_method(
 | 
			
		||||
        'plus.activities.list', 'plus'
 | 
			
		||||
      ).name.should == 'list'
 | 
			
		||||
      ).name).to eq('list')
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should define the origin API in discovered methods' do
 | 
			
		||||
      CLIENT.discovered_method(
 | 
			
		||||
      expect(CLIENT.discovered_method(
 | 
			
		||||
        'plus.activities.list', 'plus'
 | 
			
		||||
      ).api.name.should == 'plus'
 | 
			
		||||
      ).api.name).to eq('plus')
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should not find methods that are not in the discovery document' do
 | 
			
		||||
      CLIENT.discovered_method('plus.bogus', 'plus').should == nil
 | 
			
		||||
      expect(CLIENT.discovered_method('plus.bogus', 'plus')).to eq(nil)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should generate requests against the correct URIs' do
 | 
			
		||||
| 
						 | 
				
			
			@ -443,17 +443,17 @@ describe Google::APIClient do
 | 
			
		|||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should correctly validate parameters' do
 | 
			
		||||
      (lambda do
 | 
			
		||||
      expect(lambda do
 | 
			
		||||
        CLIENT.execute(
 | 
			
		||||
          :api_method => @plus.activities.list,
 | 
			
		||||
          :parameters => {'alt' => 'json'},
 | 
			
		||||
          :authenticated => false
 | 
			
		||||
        )
 | 
			
		||||
      end).should raise_error(ArgumentError)
 | 
			
		||||
      end).to raise_error(ArgumentError)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should correctly validate parameters' do
 | 
			
		||||
      (lambda do
 | 
			
		||||
      expect(lambda do
 | 
			
		||||
        CLIENT.execute(
 | 
			
		||||
          :api_method => @plus.activities.list,
 | 
			
		||||
          :parameters => {
 | 
			
		||||
| 
						 | 
				
			
			@ -461,7 +461,7 @@ describe Google::APIClient do
 | 
			
		|||
          },
 | 
			
		||||
          :authenticated => false
 | 
			
		||||
        ).to_env(CLIENT.connection)
 | 
			
		||||
      end).should raise_error(ArgumentError)
 | 
			
		||||
      end).to raise_error(ArgumentError)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -472,27 +472,27 @@ describe Google::APIClient do
 | 
			
		|||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should correctly determine the discovery URI' do
 | 
			
		||||
      CLIENT.discovery_uri('adsense', 'v1.3').to_s.should ===
 | 
			
		||||
      expect(CLIENT.discovery_uri('adsense', 'v1.3').to_s).to be ===
 | 
			
		||||
        'https://www.googleapis.com/discovery/v1/apis/adsense/v1.3/rest'
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should find APIs that are in the discovery document' do
 | 
			
		||||
      CLIENT.discovered_api('adsense', 'v1.3').name.should == 'adsense'
 | 
			
		||||
      CLIENT.discovered_api('adsense', 'v1.3').version.should == 'v1.3'
 | 
			
		||||
      expect(CLIENT.discovered_api('adsense', 'v1.3').name).to eq('adsense')
 | 
			
		||||
      expect(CLIENT.discovered_api('adsense', 'v1.3').version).to eq('v1.3')
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should return a batch path' do
 | 
			
		||||
      CLIENT.discovered_api('adsense', 'v1.3').batch_path.should_not be_nil
 | 
			
		||||
      expect(CLIENT.discovered_api('adsense', 'v1.3').batch_path).not_to be_nil
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should find methods that are in the discovery document' do
 | 
			
		||||
      CLIENT.discovered_method(
 | 
			
		||||
      expect(CLIENT.discovered_method(
 | 
			
		||||
        'adsense.reports.generate', 'adsense', 'v1.3'
 | 
			
		||||
      ).name.should == 'generate'
 | 
			
		||||
      ).name).to eq('generate')
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should not find methods that are not in the discovery document' do
 | 
			
		||||
      CLIENT.discovered_method('adsense.bogus', 'adsense', 'v1.3').should == nil
 | 
			
		||||
      expect(CLIENT.discovered_method('adsense.bogus', 'adsense', 'v1.3')).to eq(nil)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should generate requests against the correct URIs' do
 | 
			
		||||
| 
						 | 
				
			
			@ -514,16 +514,16 @@ describe Google::APIClient do
 | 
			
		|||
        :api_method => @adsense.adclients.list,
 | 
			
		||||
        :authenticated => false
 | 
			
		||||
      )
 | 
			
		||||
      result.response.status.should == 401
 | 
			
		||||
      expect(result.response.status).to eq(401)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should fail when validating missing required parameters' do
 | 
			
		||||
      (lambda do
 | 
			
		||||
      expect(lambda do
 | 
			
		||||
        CLIENT.execute(
 | 
			
		||||
          :api_method => @adsense.reports.generate,
 | 
			
		||||
          :authenticated => false
 | 
			
		||||
        )
 | 
			
		||||
      end).should raise_error(ArgumentError)
 | 
			
		||||
      end).to raise_error(ArgumentError)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should succeed when validating parameters in a correct call' do
 | 
			
		||||
| 
						 | 
				
			
			@ -532,7 +532,7 @@ describe Google::APIClient do
 | 
			
		|||
          [200, {}, '{}']
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
      (lambda do
 | 
			
		||||
      expect(lambda do
 | 
			
		||||
        CLIENT.execute(
 | 
			
		||||
          :api_method => @adsense.reports.generate,
 | 
			
		||||
          :parameters => {
 | 
			
		||||
| 
						 | 
				
			
			@ -544,12 +544,12 @@ describe Google::APIClient do
 | 
			
		|||
          :authenticated => false,
 | 
			
		||||
          :connection => conn
 | 
			
		||||
        )
 | 
			
		||||
      end).should_not raise_error
 | 
			
		||||
      end).not_to raise_error
 | 
			
		||||
      conn.verify
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should fail when validating parameters with invalid values' do
 | 
			
		||||
      (lambda do
 | 
			
		||||
      expect(lambda do
 | 
			
		||||
        CLIENT.execute(
 | 
			
		||||
          :api_method => @adsense.reports.generate,
 | 
			
		||||
          :parameters => {
 | 
			
		||||
| 
						 | 
				
			
			@ -560,7 +560,7 @@ describe Google::APIClient do
 | 
			
		|||
          },
 | 
			
		||||
          :authenticated => false
 | 
			
		||||
        )
 | 
			
		||||
      end).should raise_error(ArgumentError)
 | 
			
		||||
      end).to raise_error(ArgumentError)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should succeed when validating repeated parameters in a correct call' do
 | 
			
		||||
| 
						 | 
				
			
			@ -571,7 +571,7 @@ describe Google::APIClient do
 | 
			
		|||
          [200, {}, '{}']
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
      (lambda do
 | 
			
		||||
      expect(lambda do
 | 
			
		||||
        CLIENT.execute(
 | 
			
		||||
          :api_method => @adsense.reports.generate,
 | 
			
		||||
          :parameters => {
 | 
			
		||||
| 
						 | 
				
			
			@ -583,12 +583,12 @@ describe Google::APIClient do
 | 
			
		|||
          :authenticated => false,
 | 
			
		||||
          :connection => conn
 | 
			
		||||
        )
 | 
			
		||||
      end).should_not raise_error
 | 
			
		||||
      end).not_to raise_error
 | 
			
		||||
      conn.verify
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should fail when validating incorrect repeated parameters' do
 | 
			
		||||
      (lambda do
 | 
			
		||||
      expect(lambda do
 | 
			
		||||
        CLIENT.execute(
 | 
			
		||||
          :api_method => @adsense.reports.generate,
 | 
			
		||||
          :parameters => {
 | 
			
		||||
| 
						 | 
				
			
			@ -599,7 +599,7 @@ describe Google::APIClient do
 | 
			
		|||
          },
 | 
			
		||||
          :authenticated => false
 | 
			
		||||
        )
 | 
			
		||||
      end).should raise_error(ArgumentError)
 | 
			
		||||
      end).to raise_error(ArgumentError)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should generate valid requests when multivalued parameters are passed' do
 | 
			
		||||
| 
						 | 
				
			
			@ -607,8 +607,8 @@ describe Google::APIClient do
 | 
			
		|||
         stub.get('/adsense/v1.3/reports?dimension=DATE&dimension=PRODUCT_CODE'+
 | 
			
		||||
                 '&endDate=2010-01-01&metric=CLICKS&metric=PAGE_VIEWS&'+
 | 
			
		||||
                 'startDate=2000-01-01') do |env|
 | 
			
		||||
           env.params['dimension'].should include('DATE', 'PRODUCT_CODE')
 | 
			
		||||
           env.params['metric'].should include('CLICKS', 'PAGE_VIEWS')
 | 
			
		||||
           expect(env.params['dimension']).to include('DATE', 'PRODUCT_CODE')
 | 
			
		||||
           expect(env.params['metric']).to include('CLICKS', 'PAGE_VIEWS')
 | 
			
		||||
          [200, {}, '{}']
 | 
			
		||||
         end
 | 
			
		||||
       end
 | 
			
		||||
| 
						 | 
				
			
			@ -634,19 +634,19 @@ describe Google::APIClient do
 | 
			
		|||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should include media upload info methods' do
 | 
			
		||||
      @drive.files.insert.media_upload.should_not == nil
 | 
			
		||||
      expect(@drive.files.insert.media_upload).not_to eq(nil)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should include accepted media types' do
 | 
			
		||||
      @drive.files.insert.media_upload.accepted_types.should_not be_empty
 | 
			
		||||
      expect(@drive.files.insert.media_upload.accepted_types).not_to be_empty
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should have an upload path' do
 | 
			
		||||
      @drive.files.insert.media_upload.uri_template.should_not == nil
 | 
			
		||||
      expect(@drive.files.insert.media_upload.uri_template).not_to eq(nil)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should have a max file size' do
 | 
			
		||||
      @drive.files.insert.media_upload.max_size.should_not == nil
 | 
			
		||||
      expect(@drive.files.insert.media_upload.max_size).not_to eq(nil)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,7 +33,7 @@ describe Google::APIClient::Gzip do
 | 
			
		|||
      [200, {}, 'Hello world']
 | 
			
		||||
    end
 | 
			
		||||
    result = conn.get('/')
 | 
			
		||||
    result.body.should == "Hello world"
 | 
			
		||||
    expect(result.body).to eq("Hello world")
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it 'should decompress gziped content' do
 | 
			
		||||
| 
						 | 
				
			
			@ -41,7 +41,7 @@ describe Google::APIClient::Gzip do
 | 
			
		|||
      [200, { 'Content-Encoding' => 'gzip'}, Base64.decode64('H4sICLVGwlEAA3RtcADzSM3JyVcozy/KSeECANXgObcMAAAA')]
 | 
			
		||||
    end
 | 
			
		||||
    result = conn.get('/')
 | 
			
		||||
    result.body.should == "Hello world\n"
 | 
			
		||||
    expect(result.body).to eq("Hello world\n")
 | 
			
		||||
  end
 | 
			
		||||
  
 | 
			
		||||
  describe 'with API Client' do
 | 
			
		||||
| 
						 | 
				
			
			@ -55,8 +55,8 @@ describe Google::APIClient::Gzip do
 | 
			
		|||
    it 'should send gzip in user agent' do
 | 
			
		||||
      conn = create_connection do |env|
 | 
			
		||||
        agent = env[:request_headers]['User-Agent']
 | 
			
		||||
        agent.should_not be_nil
 | 
			
		||||
        agent.should include 'gzip'
 | 
			
		||||
        expect(agent).not_to be_nil
 | 
			
		||||
        expect(agent).to include 'gzip'
 | 
			
		||||
        [200, {}, 'Hello world']
 | 
			
		||||
      end
 | 
			
		||||
      @client.execute(:uri => 'http://www.example.com/', :connection => conn)
 | 
			
		||||
| 
						 | 
				
			
			@ -65,8 +65,8 @@ describe Google::APIClient::Gzip do
 | 
			
		|||
    it 'should send gzip in accept-encoding' do
 | 
			
		||||
      conn = create_connection do |env|
 | 
			
		||||
        encoding = env[:request_headers]['Accept-Encoding']
 | 
			
		||||
        encoding.should_not be_nil
 | 
			
		||||
        encoding.should include 'gzip'
 | 
			
		||||
        expect(encoding).not_to be_nil
 | 
			
		||||
        expect(encoding).to include 'gzip'
 | 
			
		||||
        [200, {}, 'Hello world']
 | 
			
		||||
      end
 | 
			
		||||
      @client.execute(:uri => 'http://www.example.com/', :connection => conn)
 | 
			
		||||
| 
						 | 
				
			
			@ -75,7 +75,7 @@ describe Google::APIClient::Gzip do
 | 
			
		|||
    it 'should not send gzip in accept-encoding if disabled for request' do
 | 
			
		||||
      conn = create_connection do |env|
 | 
			
		||||
        encoding = env[:request_headers]['Accept-Encoding']
 | 
			
		||||
        encoding.should_not include('gzip') unless encoding.nil?
 | 
			
		||||
        expect(encoding).not_to include('gzip') unless encoding.nil?
 | 
			
		||||
        [200, {}, 'Hello world']
 | 
			
		||||
      end
 | 
			
		||||
      response = @client.execute(:uri => 'http://www.example.com/', :gzip => false, :connection => conn)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -21,9 +21,9 @@ fixtures_path = File.expand_path('../../../fixtures', __FILE__)
 | 
			
		|||
 | 
			
		||||
describe Google::APIClient::UploadIO do
 | 
			
		||||
  it 'should reject invalid file paths' do
 | 
			
		||||
    (lambda do
 | 
			
		||||
    expect(lambda do
 | 
			
		||||
      media = Google::APIClient::UploadIO.new('doesnotexist', 'text/plain')
 | 
			
		||||
    end).should raise_error
 | 
			
		||||
    end).to raise_error
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe 'with a file' do
 | 
			
		||||
| 
						 | 
				
			
			@ -33,11 +33,11 @@ describe Google::APIClient::UploadIO do
 | 
			
		|||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should report the correct file length' do
 | 
			
		||||
      @media.length.should == File.size(@file)
 | 
			
		||||
      expect(@media.length).to eq(File.size(@file))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should have a mime type' do
 | 
			
		||||
      @media.content_type.should == 'text/plain'
 | 
			
		||||
      expect(@media.content_type).to eq('text/plain')
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -48,11 +48,11 @@ describe Google::APIClient::UploadIO do
 | 
			
		|||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should report the correct file length' do
 | 
			
		||||
      @media.length.should == @content.length
 | 
			
		||||
      expect(@media.length).to eq(@content.length)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should have a mime type' do
 | 
			
		||||
      @media.content_type.should == 'text/plain'
 | 
			
		||||
      expect(@media.content_type).to eq('text/plain')
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			@ -64,43 +64,43 @@ describe Google::APIClient::RangedIO do
 | 
			
		|||
  end
 | 
			
		||||
  
 | 
			
		||||
  it 'should return the correct range when read entirely' do
 | 
			
		||||
    @io.read.should == "23456"
 | 
			
		||||
    expect(@io.read).to eq("23456")
 | 
			
		||||
  end
 | 
			
		||||
  
 | 
			
		||||
  it 'should maintain position' do
 | 
			
		||||
    @io.read(1).should == '2'
 | 
			
		||||
    @io.read(2).should == '34'
 | 
			
		||||
    @io.read(2).should == '56'
 | 
			
		||||
    expect(@io.read(1)).to eq('2')
 | 
			
		||||
    expect(@io.read(2)).to eq('34')
 | 
			
		||||
    expect(@io.read(2)).to eq('56')
 | 
			
		||||
  end
 | 
			
		||||
  
 | 
			
		||||
  it 'should allow rewinds' do
 | 
			
		||||
    @io.read(2).should == '23'
 | 
			
		||||
    expect(@io.read(2)).to eq('23')
 | 
			
		||||
    @io.rewind()
 | 
			
		||||
    @io.read(2).should == '23'
 | 
			
		||||
    expect(@io.read(2)).to eq('23')
 | 
			
		||||
  end
 | 
			
		||||
  
 | 
			
		||||
  it 'should allow setting position' do
 | 
			
		||||
    @io.pos = 3
 | 
			
		||||
    @io.read.should == '56'
 | 
			
		||||
    expect(@io.read).to eq('56')
 | 
			
		||||
  end
 | 
			
		||||
  
 | 
			
		||||
  it 'should not allow position to be set beyond range' do
 | 
			
		||||
    @io.pos = 10
 | 
			
		||||
    @io.read.should == ''
 | 
			
		||||
    expect(@io.read).to eq('')
 | 
			
		||||
  end
 | 
			
		||||
  
 | 
			
		||||
  it 'should return empty string when read amount is zero' do
 | 
			
		||||
    @io.read(0).should == ''
 | 
			
		||||
    expect(@io.read(0)).to eq('')
 | 
			
		||||
  end
 | 
			
		||||
  
 | 
			
		||||
  it 'should return empty string at EOF if amount is nil' do
 | 
			
		||||
    @io.read
 | 
			
		||||
    @io.read.should == ''
 | 
			
		||||
    expect(@io.read).to eq('')
 | 
			
		||||
  end
 | 
			
		||||
  
 | 
			
		||||
  it 'should return nil at EOF if amount is positive int' do
 | 
			
		||||
    @io.read
 | 
			
		||||
    @io.read(1).should == nil
 | 
			
		||||
    expect(@io.read(1)).to eq(nil)
 | 
			
		||||
  end
 | 
			
		||||
    
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			@ -127,26 +127,26 @@ describe Google::APIClient::ResumableUpload do
 | 
			
		|||
  it 'should consider 20x status as complete' do
 | 
			
		||||
    request = @uploader.to_http_request
 | 
			
		||||
    @uploader.process_http_response(mock_result(200))
 | 
			
		||||
    @uploader.complete?.should == true
 | 
			
		||||
    expect(@uploader.complete?).to eq(true)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it 'should consider 30x status as incomplete' do
 | 
			
		||||
    request = @uploader.to_http_request
 | 
			
		||||
    @uploader.process_http_response(mock_result(308))
 | 
			
		||||
    @uploader.complete?.should == false
 | 
			
		||||
    @uploader.expired?.should == false
 | 
			
		||||
    expect(@uploader.complete?).to eq(false)
 | 
			
		||||
    expect(@uploader.expired?).to eq(false)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it 'should consider 40x status as fatal' do
 | 
			
		||||
    request = @uploader.to_http_request
 | 
			
		||||
    @uploader.process_http_response(mock_result(404))
 | 
			
		||||
    @uploader.expired?.should == true
 | 
			
		||||
    expect(@uploader.expired?).to eq(true)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it 'should detect changes to location' do
 | 
			
		||||
    request = @uploader.to_http_request
 | 
			
		||||
    @uploader.process_http_response(mock_result(308, 'location' => 'https://www.googleapis.com/upload/drive/v1/files/abcdef'))
 | 
			
		||||
    @uploader.uri.to_s.should == 'https://www.googleapis.com/upload/drive/v1/files/abcdef'
 | 
			
		||||
    expect(@uploader.uri.to_s).to eq('https://www.googleapis.com/upload/drive/v1/files/abcdef')
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it 'should resume from the saved range reported by the server' do    
 | 
			
		||||
| 
						 | 
				
			
			@ -154,8 +154,8 @@ describe Google::APIClient::ResumableUpload do
 | 
			
		|||
    @uploader.to_http_request # Send bytes 0-199, only 0-99 saved
 | 
			
		||||
    @uploader.process_http_response(mock_result(308, 'range' => '0-99'))
 | 
			
		||||
    method, url, headers, body = @uploader.to_http_request # Send bytes 100-299
 | 
			
		||||
    headers['Content-Range'].should == "bytes 100-299/#{@media.length}"
 | 
			
		||||
    headers['Content-length'].should == "200"
 | 
			
		||||
    expect(headers['Content-Range']).to eq("bytes 100-299/#{@media.length}")
 | 
			
		||||
    expect(headers['Content-length']).to eq("200")
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it 'should resync the offset after 5xx errors' do
 | 
			
		||||
| 
						 | 
				
			
			@ -163,12 +163,12 @@ describe Google::APIClient::ResumableUpload do
 | 
			
		|||
    @uploader.to_http_request
 | 
			
		||||
    @uploader.process_http_response(mock_result(500)) # Invalidates range
 | 
			
		||||
    method, url, headers, body = @uploader.to_http_request # Resync
 | 
			
		||||
    headers['Content-Range'].should == "bytes */#{@media.length}"
 | 
			
		||||
    headers['Content-length'].should == "0"
 | 
			
		||||
    expect(headers['Content-Range']).to eq("bytes */#{@media.length}")
 | 
			
		||||
    expect(headers['Content-length']).to eq("0")
 | 
			
		||||
    @uploader.process_http_response(mock_result(308, 'range' => '0-99'))
 | 
			
		||||
    method, url, headers, body = @uploader.to_http_request # Send next chunk at correct range
 | 
			
		||||
    headers['Content-Range'].should == "bytes 100-299/#{@media.length}"
 | 
			
		||||
    headers['Content-length'].should == "200"
 | 
			
		||||
    expect(headers['Content-Range']).to eq("bytes 100-299/#{@media.length}")
 | 
			
		||||
    expect(headers['Content-length']).to eq("200")
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def mock_result(status, headers = {})
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -24,7 +24,7 @@ describe Google::APIClient::Request do
 | 
			
		|||
    request = Google::APIClient::Request.new(:uri => 'https://www.google.com', :parameters => {
 | 
			
		||||
      :a => '1', 'b' => '2'
 | 
			
		||||
    })
 | 
			
		||||
    request.parameters['a'].should == '1'
 | 
			
		||||
    request.parameters['b'].should == '2'
 | 
			
		||||
    expect(request.parameters['a']).to eq('1')
 | 
			
		||||
    expect(request.parameters['b']).to eq('2')
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -36,8 +36,8 @@ describe Google::APIClient::Result do
 | 
			
		|||
 | 
			
		||||
      # Response double
 | 
			
		||||
      @response = double("response")
 | 
			
		||||
      @response.stub(:status).and_return(200)
 | 
			
		||||
      @response.stub(:headers).and_return({
 | 
			
		||||
      allow(@response).to receive(:status).and_return(200)
 | 
			
		||||
      allow(@response).to receive(:headers).and_return({
 | 
			
		||||
        'etag' => '12345',
 | 
			
		||||
        'x-google-apiary-auth-scopes' =>
 | 
			
		||||
          'https://www.googleapis.com/auth/plus.me',
 | 
			
		||||
| 
						 | 
				
			
			@ -51,7 +51,7 @@ describe Google::APIClient::Result do
 | 
			
		|||
 | 
			
		||||
    describe 'with a next page token' do
 | 
			
		||||
      before do
 | 
			
		||||
        @response.stub(:body).and_return(
 | 
			
		||||
        allow(@response).to receive(:body).and_return(
 | 
			
		||||
          <<-END_OF_STRING
 | 
			
		||||
          {
 | 
			
		||||
            "kind": "plus#activityFeed",
 | 
			
		||||
| 
						 | 
				
			
			@ -70,46 +70,49 @@ describe Google::APIClient::Result do
 | 
			
		|||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should indicate a successful response' do
 | 
			
		||||
        @result.error?.should be_false
 | 
			
		||||
        expect(@result.error?).to be_falsey
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should return the correct next page token' do
 | 
			
		||||
        @result.next_page_token.should == 'NEXT+PAGE+TOKEN'
 | 
			
		||||
        expect(@result.next_page_token).to eq('NEXT+PAGE+TOKEN')
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should escape the next page token when calling next_page' do
 | 
			
		||||
        reference = @result.next_page
 | 
			
		||||
        Hash[reference.parameters].should include('pageToken')
 | 
			
		||||
        Hash[reference.parameters]['pageToken'].should == 'NEXT+PAGE+TOKEN'
 | 
			
		||||
        expect(Hash[reference.parameters]).to include('pageToken')
 | 
			
		||||
        expect(Hash[reference.parameters]['pageToken']).to eq('NEXT+PAGE+TOKEN')
 | 
			
		||||
        url = reference.to_env(CLIENT.connection)[:url]
 | 
			
		||||
        url.to_s.should include('pageToken=NEXT%2BPAGE%2BTOKEN')
 | 
			
		||||
        expect(url.to_s).to include('pageToken=NEXT%2BPAGE%2BTOKEN')
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should return content type correctly' do
 | 
			
		||||
        @result.media_type.should == 'application/json'
 | 
			
		||||
        expect(@result.media_type).to eq('application/json')
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should return the result data correctly' do
 | 
			
		||||
        @result.data?.should be_true
 | 
			
		||||
        @result.data.class.to_s.should ==
 | 
			
		||||
        expect(@result.data?).to be_truthy
 | 
			
		||||
        expect(@result.data.class.to_s).to eq(
 | 
			
		||||
            'Google::APIClient::Schema::Plus::V1::ActivityFeed'
 | 
			
		||||
        @result.data.kind.should == 'plus#activityFeed'
 | 
			
		||||
        @result.data.etag.should == 'FOO'
 | 
			
		||||
        @result.data.nextPageToken.should == 'NEXT+PAGE+TOKEN'
 | 
			
		||||
        @result.data.selfLink.should ==
 | 
			
		||||
        )
 | 
			
		||||
        expect(@result.data.kind).to eq('plus#activityFeed')
 | 
			
		||||
        expect(@result.data.etag).to eq('FOO')
 | 
			
		||||
        expect(@result.data.nextPageToken).to eq('NEXT+PAGE+TOKEN')
 | 
			
		||||
        expect(@result.data.selfLink).to eq(
 | 
			
		||||
            'https://www.googleapis.com/plus/v1/people/foo/activities/public?'
 | 
			
		||||
        @result.data.nextLink.should ==
 | 
			
		||||
        )
 | 
			
		||||
        expect(@result.data.nextLink).to eq(
 | 
			
		||||
            'https://www.googleapis.com/plus/v1/people/foo/activities/public?' +
 | 
			
		||||
            'maxResults=20&pageToken=NEXT%2BPAGE%2BTOKEN'
 | 
			
		||||
        @result.data.title.should == 'Plus Public Activity Feed for '
 | 
			
		||||
        @result.data.id.should == "123456790"
 | 
			
		||||
        @result.data.items.should be_empty
 | 
			
		||||
        )
 | 
			
		||||
        expect(@result.data.title).to eq('Plus Public Activity Feed for ')
 | 
			
		||||
        expect(@result.data.id).to eq("123456790")
 | 
			
		||||
        expect(@result.data.items).to be_empty
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    describe 'without a next page token' do
 | 
			
		||||
      before do
 | 
			
		||||
        @response.stub(:body).and_return(
 | 
			
		||||
        allow(@response).to receive(:body).and_return(
 | 
			
		||||
          <<-END_OF_STRING
 | 
			
		||||
          {
 | 
			
		||||
            "kind": "plus#activityFeed",
 | 
			
		||||
| 
						 | 
				
			
			@ -126,30 +129,32 @@ describe Google::APIClient::Result do
 | 
			
		|||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should not return a next page token' do
 | 
			
		||||
        @result.next_page_token.should == nil
 | 
			
		||||
        expect(@result.next_page_token).to eq(nil)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should return content type correctly' do
 | 
			
		||||
        @result.media_type.should == 'application/json'
 | 
			
		||||
        expect(@result.media_type).to eq('application/json')
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should return the result data correctly' do
 | 
			
		||||
        @result.data?.should be_true
 | 
			
		||||
        @result.data.class.to_s.should ==
 | 
			
		||||
        expect(@result.data?).to be_truthy
 | 
			
		||||
        expect(@result.data.class.to_s).to eq(
 | 
			
		||||
            'Google::APIClient::Schema::Plus::V1::ActivityFeed'
 | 
			
		||||
        @result.data.kind.should == 'plus#activityFeed'
 | 
			
		||||
        @result.data.etag.should == 'FOO'
 | 
			
		||||
        @result.data.selfLink.should ==
 | 
			
		||||
        )
 | 
			
		||||
        expect(@result.data.kind).to eq('plus#activityFeed')
 | 
			
		||||
        expect(@result.data.etag).to eq('FOO')
 | 
			
		||||
        expect(@result.data.selfLink).to eq(
 | 
			
		||||
            'https://www.googleapis.com/plus/v1/people/foo/activities/public?'
 | 
			
		||||
        @result.data.title.should == 'Plus Public Activity Feed for '
 | 
			
		||||
        @result.data.id.should == "123456790"
 | 
			
		||||
        @result.data.items.should be_empty
 | 
			
		||||
        )
 | 
			
		||||
        expect(@result.data.title).to eq('Plus Public Activity Feed for ')
 | 
			
		||||
        expect(@result.data.id).to eq("123456790")
 | 
			
		||||
        expect(@result.data.items).to be_empty
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    describe 'with JSON error response' do
 | 
			
		||||
      before do
 | 
			
		||||
        @response.stub(:body).and_return(
 | 
			
		||||
        allow(@response).to receive(:body).and_return(
 | 
			
		||||
         <<-END_OF_STRING
 | 
			
		||||
         {
 | 
			
		||||
          "error": {
 | 
			
		||||
| 
						 | 
				
			
			@ -166,37 +171,37 @@ describe Google::APIClient::Result do
 | 
			
		|||
         }
 | 
			
		||||
         END_OF_STRING
 | 
			
		||||
        )
 | 
			
		||||
        @response.stub(:status).and_return(400)
 | 
			
		||||
        allow(@response).to receive(:status).and_return(400)
 | 
			
		||||
        @result = Google::APIClient::Result.new(@reference, @response)
 | 
			
		||||
      end
 | 
			
		||||
      
 | 
			
		||||
 | 
			
		||||
      it 'should return error status correctly' do
 | 
			
		||||
        @result.error?.should be_true
 | 
			
		||||
        expect(@result.error?).to be_truthy
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should return the correct error message' do
 | 
			
		||||
        @result.error_message.should == 'Parse Error'
 | 
			
		||||
        expect(@result.error_message).to eq('Parse Error')
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    describe 'with 204 No Content response' do
 | 
			
		||||
      before do
 | 
			
		||||
        @response.stub(:body).and_return('')
 | 
			
		||||
        @response.stub(:status).and_return(204)
 | 
			
		||||
        @response.stub(:headers).and_return({})
 | 
			
		||||
        allow(@response).to receive(:body).and_return('')
 | 
			
		||||
        allow(@response).to receive(:status).and_return(204)
 | 
			
		||||
        allow(@response).to receive(:headers).and_return({})
 | 
			
		||||
        @result = Google::APIClient::Result.new(@reference, @response)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should indicate no data is available' do
 | 
			
		||||
        @result.data?.should be_false
 | 
			
		||||
        expect(@result.data?).to be_falsey
 | 
			
		||||
      end
 | 
			
		||||
      
 | 
			
		||||
 | 
			
		||||
      it 'should return nil for data' do
 | 
			
		||||
        @result.data.should == nil
 | 
			
		||||
        expect(@result.data).to eq(nil)
 | 
			
		||||
      end
 | 
			
		||||
      
 | 
			
		||||
 | 
			
		||||
      it 'should return nil for media_type' do
 | 
			
		||||
        @result.media_type.should == nil
 | 
			
		||||
        expect(@result.media_type).to eq(nil)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,12 +18,12 @@ require 'google/api_client'
 | 
			
		|||
 | 
			
		||||
fixtures_path = File.expand_path('../../../fixtures', __FILE__)
 | 
			
		||||
 | 
			
		||||
describe Google::APIClient::KeyUtils do  
 | 
			
		||||
describe Google::APIClient::KeyUtils do
 | 
			
		||||
  it 'should read PKCS12 files from the filesystem' do
 | 
			
		||||
    pending "Reading from PKCS12 not supported on jruby" if RUBY_PLATFORM == 'java'
 | 
			
		||||
    path =  File.expand_path('files/privatekey.p12', fixtures_path)
 | 
			
		||||
    key = Google::APIClient::KeyUtils.load_from_pkcs12(path, 'notasecret')
 | 
			
		||||
    key.should_not == nil
 | 
			
		||||
    expect(key).not_to eq(nil)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it 'should read PKCS12 files from loaded files' do
 | 
			
		||||
| 
						 | 
				
			
			@ -31,20 +31,20 @@ describe Google::APIClient::KeyUtils do
 | 
			
		|||
    path =  File.expand_path('files/privatekey.p12', fixtures_path)
 | 
			
		||||
    content = File.read(path)
 | 
			
		||||
    key = Google::APIClient::KeyUtils.load_from_pkcs12(content, 'notasecret')
 | 
			
		||||
    key.should_not == nil
 | 
			
		||||
    expect(key).not_to eq(nil)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it 'should read PEM files from the filesystem' do
 | 
			
		||||
    path =  File.expand_path('files/secret.pem', fixtures_path)
 | 
			
		||||
    key = Google::APIClient::KeyUtils.load_from_pem(path, 'notasecret')
 | 
			
		||||
    key.should_not == nil
 | 
			
		||||
    expect(key).not_to eq(nil)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it 'should read PEM files from loaded files' do
 | 
			
		||||
    path =  File.expand_path('files/secret.pem', fixtures_path)
 | 
			
		||||
    content = File.read(path)
 | 
			
		||||
    key = Google::APIClient::KeyUtils.load_from_pem(content, 'notasecret')
 | 
			
		||||
    key.should_not == nil
 | 
			
		||||
    expect(key).not_to eq(nil)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			@ -59,11 +59,12 @@ describe Google::APIClient::JWTAsserter do
 | 
			
		|||
  it 'should generate valid JWTs' do
 | 
			
		||||
    asserter = Google::APIClient::JWTAsserter.new('client1', 'scope1 scope2', @key)
 | 
			
		||||
    jwt = asserter.to_authorization.to_jwt
 | 
			
		||||
    jwt.should_not == nil
 | 
			
		||||
    expect(jwt).not_to eq(nil)
 | 
			
		||||
 | 
			
		||||
    claim = JWT.decode(jwt, @key.public_key, true)
 | 
			
		||||
    claim["iss"].should == 'client1'
 | 
			
		||||
    claim["scope"].should == 'scope1 scope2'
 | 
			
		||||
    claim = claim.first if claim.respond_to? :first
 | 
			
		||||
    expect(claim["iss"]).to eq('client1')
 | 
			
		||||
    expect(claim["scope"]).to eq('scope1 scope2')
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it 'should allow impersonation' do
 | 
			
		||||
| 
						 | 
				
			
			@ -71,7 +72,7 @@ describe Google::APIClient::JWTAsserter do
 | 
			
		|||
      stub.post('/o/oauth2/token') do |env|
 | 
			
		||||
        params = Addressable::URI.form_unencode(env[:body])
 | 
			
		||||
        JWT.decode(params.assoc("assertion").last, @key.public_key)
 | 
			
		||||
        params.assoc("grant_type").should == ['grant_type','urn:ietf:params:oauth:grant-type:jwt-bearer']
 | 
			
		||||
        expect(params.assoc("grant_type")).to eq(['grant_type','urn:ietf:params:oauth:grant-type:jwt-bearer'])
 | 
			
		||||
        [200, {}, '{
 | 
			
		||||
          "access_token" : "1/abcdef1234567890",
 | 
			
		||||
          "token_type" : "Bearer",
 | 
			
		||||
| 
						 | 
				
			
			@ -81,8 +82,8 @@ describe Google::APIClient::JWTAsserter do
 | 
			
		|||
    end
 | 
			
		||||
    asserter = Google::APIClient::JWTAsserter.new('client1', 'scope1 scope2', @key)
 | 
			
		||||
    auth = asserter.authorize('user1@email.com', { :connection => conn })
 | 
			
		||||
    auth.should_not == nil?
 | 
			
		||||
    auth.person.should == 'user1@email.com'
 | 
			
		||||
    expect(auth).not_to eq(nil?)
 | 
			
		||||
    expect(auth.person).to eq('user1@email.com')
 | 
			
		||||
    conn.verify
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -91,7 +92,7 @@ describe Google::APIClient::JWTAsserter do
 | 
			
		|||
      stub.post('/o/oauth2/token') do |env|
 | 
			
		||||
        params = Addressable::URI.form_unencode(env[:body])
 | 
			
		||||
        JWT.decode(params.assoc("assertion").last, @key.public_key)
 | 
			
		||||
        params.assoc("grant_type").should == ['grant_type','urn:ietf:params:oauth:grant-type:jwt-bearer']
 | 
			
		||||
        expect(params.assoc("grant_type")).to eq(['grant_type','urn:ietf:params:oauth:grant-type:jwt-bearer'])
 | 
			
		||||
        [200, {}, '{
 | 
			
		||||
          "access_token" : "1/abcdef1234567890",
 | 
			
		||||
          "token_type" : "Bearer",
 | 
			
		||||
| 
						 | 
				
			
			@ -101,17 +102,17 @@ describe Google::APIClient::JWTAsserter do
 | 
			
		|||
    end
 | 
			
		||||
    asserter = Google::APIClient::JWTAsserter.new('client1', 'scope1 scope2', @key)
 | 
			
		||||
    auth = asserter.authorize(nil, { :connection => conn })
 | 
			
		||||
    auth.should_not == nil?
 | 
			
		||||
    auth.access_token.should == "1/abcdef1234567890"
 | 
			
		||||
    expect(auth).not_to eq(nil?)
 | 
			
		||||
    expect(auth.access_token).to eq("1/abcdef1234567890")
 | 
			
		||||
    conn.verify
 | 
			
		||||
  end
 | 
			
		||||
  
 | 
			
		||||
 | 
			
		||||
  it 'should be refreshable' do
 | 
			
		||||
    conn = stub_connection do |stub|
 | 
			
		||||
      stub.post('/o/oauth2/token') do |env|
 | 
			
		||||
        params = Addressable::URI.form_unencode(env[:body])
 | 
			
		||||
        JWT.decode(params.assoc("assertion").last, @key.public_key)
 | 
			
		||||
        params.assoc("grant_type").should == ['grant_type','urn:ietf:params:oauth:grant-type:jwt-bearer']
 | 
			
		||||
        expect(params.assoc("grant_type")).to eq(['grant_type','urn:ietf:params:oauth:grant-type:jwt-bearer'])
 | 
			
		||||
        [200, {}, '{
 | 
			
		||||
          "access_token" : "1/abcdef1234567890",
 | 
			
		||||
          "token_type" : "Bearer",
 | 
			
		||||
| 
						 | 
				
			
			@ -121,7 +122,7 @@ describe Google::APIClient::JWTAsserter do
 | 
			
		|||
      stub.post('/o/oauth2/token') do |env|
 | 
			
		||||
        params = Addressable::URI.form_unencode(env[:body])
 | 
			
		||||
        JWT.decode(params.assoc("assertion").last, @key.public_key)
 | 
			
		||||
        params.assoc("grant_type").should == ['grant_type','urn:ietf:params:oauth:grant-type:jwt-bearer']
 | 
			
		||||
        expect(params.assoc("grant_type")).to eq(['grant_type','urn:ietf:params:oauth:grant-type:jwt-bearer'])
 | 
			
		||||
        [200, {}, '{
 | 
			
		||||
          "access_token" : "1/0987654321fedcba",
 | 
			
		||||
          "token_type" : "Bearer",
 | 
			
		||||
| 
						 | 
				
			
			@ -131,14 +132,14 @@ describe Google::APIClient::JWTAsserter do
 | 
			
		|||
    end
 | 
			
		||||
    asserter = Google::APIClient::JWTAsserter.new('client1', 'scope1 scope2', @key)
 | 
			
		||||
    auth = asserter.authorize(nil, { :connection => conn })
 | 
			
		||||
    auth.should_not == nil?
 | 
			
		||||
    auth.access_token.should == "1/abcdef1234567890"
 | 
			
		||||
    
 | 
			
		||||
    expect(auth).not_to eq(nil?)
 | 
			
		||||
    expect(auth.access_token).to eq("1/abcdef1234567890")
 | 
			
		||||
 | 
			
		||||
    auth.fetch_access_token!(:connection => conn)
 | 
			
		||||
    auth.access_token.should == "1/0987654321fedcba"
 | 
			
		||||
    
 | 
			
		||||
    expect(auth.access_token).to eq("1/0987654321fedcba")
 | 
			
		||||
 | 
			
		||||
    conn.verify
 | 
			
		||||
  end    
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
describe Google::APIClient::ComputeServiceAccount do
 | 
			
		||||
| 
						 | 
				
			
			@ -147,7 +148,7 @@ describe Google::APIClient::ComputeServiceAccount do
 | 
			
		|||
  it 'should query metadata server' do
 | 
			
		||||
    conn = stub_connection do |stub|
 | 
			
		||||
      stub.get('/computeMetadata/v1beta1/instance/service-accounts/default/token') do |env|
 | 
			
		||||
        env.url.host.should == 'metadata'
 | 
			
		||||
        expect(env.url.host).to eq('metadata')
 | 
			
		||||
        [200, {}, '{
 | 
			
		||||
          "access_token" : "1/abcdef1234567890",
 | 
			
		||||
          "token_type" : "Bearer",
 | 
			
		||||
| 
						 | 
				
			
			@ -157,8 +158,8 @@ describe Google::APIClient::ComputeServiceAccount do
 | 
			
		|||
    end
 | 
			
		||||
    service_account = Google::APIClient::ComputeServiceAccount.new
 | 
			
		||||
    auth = service_account.fetch_access_token!({ :connection => conn })
 | 
			
		||||
    auth.should_not == nil?
 | 
			
		||||
    auth["access_token"].should == "1/abcdef1234567890"
 | 
			
		||||
    expect(auth).not_to eq(nil?)
 | 
			
		||||
    expect(auth["access_token"]).to eq("1/abcdef1234567890")
 | 
			
		||||
    conn.verify
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -27,21 +27,21 @@ describe Google::APIClient::Service do
 | 
			
		|||
  APPLICATION_NAME = 'API Client Tests'
 | 
			
		||||
 | 
			
		||||
  it 'should error out when called without an API name or version' do
 | 
			
		||||
    (lambda do
 | 
			
		||||
    expect(lambda do
 | 
			
		||||
      Google::APIClient::Service.new
 | 
			
		||||
    end).should raise_error(ArgumentError)
 | 
			
		||||
    end).to raise_error(ArgumentError)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it 'should error out when called without an API version' do
 | 
			
		||||
    (lambda do
 | 
			
		||||
    expect(lambda do
 | 
			
		||||
      Google::APIClient::Service.new('foo')
 | 
			
		||||
    end).should raise_error(ArgumentError)
 | 
			
		||||
    end).to raise_error(ArgumentError)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it 'should error out when the options hash is not a hash' do
 | 
			
		||||
    (lambda do
 | 
			
		||||
    expect(lambda do
 | 
			
		||||
      Google::APIClient::Service.new('foo', 'v1', 42)
 | 
			
		||||
    end).should raise_error(ArgumentError)
 | 
			
		||||
    end).to raise_error(ArgumentError)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe 'with the AdSense Management API' do
 | 
			
		||||
| 
						 | 
				
			
			@ -112,34 +112,34 @@ describe Google::APIClient::Service do
 | 
			
		|||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should return a resource when using a valid resource name' do
 | 
			
		||||
        @adsense.accounts.should be_a(Google::APIClient::Service::Resource)
 | 
			
		||||
        expect(@adsense.accounts).to be_a(Google::APIClient::Service::Resource)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should throw an error when using an invalid resource name' do
 | 
			
		||||
        (lambda do
 | 
			
		||||
        expect(lambda do
 | 
			
		||||
           @adsense.invalid_resource
 | 
			
		||||
        end).should raise_error
 | 
			
		||||
        end).to raise_error
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should return a request when using a valid method name' do
 | 
			
		||||
        req = @adsense.adclients.list
 | 
			
		||||
        req.should be_a(Google::APIClient::Service::Request)
 | 
			
		||||
        req.method.id.should == 'adsense.adclients.list'
 | 
			
		||||
        req.parameters.should be_nil
 | 
			
		||||
        expect(req).to be_a(Google::APIClient::Service::Request)
 | 
			
		||||
        expect(req.method.id).to eq('adsense.adclients.list')
 | 
			
		||||
        expect(req.parameters).to be_nil
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should throw an error when using an invalid method name' do
 | 
			
		||||
        (lambda do
 | 
			
		||||
        expect(lambda do
 | 
			
		||||
           @adsense.adclients.invalid_method
 | 
			
		||||
        end).should raise_error
 | 
			
		||||
        end).to raise_error
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should return a valid request with parameters' do
 | 
			
		||||
        req = @adsense.adunits.list(:adClientId => '1')
 | 
			
		||||
        req.should be_a(Google::APIClient::Service::Request)
 | 
			
		||||
        req.method.id.should == 'adsense.adunits.list'
 | 
			
		||||
        req.parameters.should_not be_nil
 | 
			
		||||
        req.parameters[:adClientId].should == '1'
 | 
			
		||||
        expect(req).to be_a(Google::APIClient::Service::Request)
 | 
			
		||||
        expect(req.method.id).to eq('adsense.adunits.list')
 | 
			
		||||
        expect(req.parameters).not_to be_nil
 | 
			
		||||
        expect(req.parameters[:adClientId]).to eq('1')
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
| 
						 | 
				
			
			@ -149,7 +149,7 @@ describe Google::APIClient::Service do
 | 
			
		|||
    it 'should make a valid call with an object body' do
 | 
			
		||||
      conn = stub_connection do |stub|
 | 
			
		||||
        stub.post('/prediction/v1.5/trainedmodels?project=1') do |env|
 | 
			
		||||
          env.body.should == '{"id":"1"}'
 | 
			
		||||
          expect(env.body).to eq('{"id":"1"}')
 | 
			
		||||
          [200, {}, '{}']
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
| 
						 | 
				
			
			@ -170,7 +170,7 @@ describe Google::APIClient::Service do
 | 
			
		|||
    it 'should make a valid call with a text body' do
 | 
			
		||||
      conn = stub_connection do |stub|
 | 
			
		||||
        stub.post('/prediction/v1.5/trainedmodels?project=1') do |env|
 | 
			
		||||
          env.body.should == '{"id":"1"}'
 | 
			
		||||
          expect(env.body).to eq('{"id":"1"}')
 | 
			
		||||
          [200, {}, '{}']
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
| 
						 | 
				
			
			@ -196,20 +196,20 @@ describe Google::APIClient::Service do
 | 
			
		|||
 | 
			
		||||
      it 'should return a valid request with a body' do
 | 
			
		||||
        req = @prediction.trainedmodels.insert(:project => '1').body({'id' => '1'})
 | 
			
		||||
        req.should be_a(Google::APIClient::Service::Request)
 | 
			
		||||
        req.method.id.should == 'prediction.trainedmodels.insert'
 | 
			
		||||
        req.body.should == {'id' => '1'}
 | 
			
		||||
        req.parameters.should_not be_nil
 | 
			
		||||
        req.parameters[:project].should == '1'
 | 
			
		||||
        expect(req).to be_a(Google::APIClient::Service::Request)
 | 
			
		||||
        expect(req.method.id).to eq('prediction.trainedmodels.insert')
 | 
			
		||||
        expect(req.body).to eq({'id' => '1'})
 | 
			
		||||
        expect(req.parameters).not_to be_nil
 | 
			
		||||
        expect(req.parameters[:project]).to eq('1')
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should return a valid request with a body when using resource name' do
 | 
			
		||||
        req = @prediction.trainedmodels.insert(:project => '1').training({'id' => '1'})
 | 
			
		||||
        req.should be_a(Google::APIClient::Service::Request)
 | 
			
		||||
        req.method.id.should == 'prediction.trainedmodels.insert'
 | 
			
		||||
        req.training.should == {'id' => '1'}
 | 
			
		||||
        req.parameters.should_not be_nil
 | 
			
		||||
        req.parameters[:project].should == '1'
 | 
			
		||||
        expect(req).to be_a(Google::APIClient::Service::Request)
 | 
			
		||||
        expect(req.method.id).to eq('prediction.trainedmodels.insert')
 | 
			
		||||
        expect(req.training).to eq({'id' => '1'})
 | 
			
		||||
        expect(req.parameters).not_to be_nil
 | 
			
		||||
        expect(req.parameters[:project]).to eq('1')
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
| 
						 | 
				
			
			@ -228,7 +228,7 @@ describe Google::APIClient::Service do
 | 
			
		|||
    it 'should make a valid call with an object body and media upload' do
 | 
			
		||||
      conn = stub_connection do |stub|
 | 
			
		||||
        stub.post('/upload/drive/v1/files?uploadType=multipart') do |env|
 | 
			
		||||
          env.body.should be_a Faraday::CompositeReadIO
 | 
			
		||||
          expect(env.body).to be_a Faraday::CompositeReadIO
 | 
			
		||||
          [200, {}, '{}']
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
| 
						 | 
				
			
			@ -254,22 +254,22 @@ describe Google::APIClient::Service do
 | 
			
		|||
 | 
			
		||||
      it 'should return a valid request with a body and media upload' do
 | 
			
		||||
        req = @drive.files.insert(:uploadType => 'multipart').body(@metadata).media(@media)
 | 
			
		||||
        req.should be_a(Google::APIClient::Service::Request)
 | 
			
		||||
        req.method.id.should == 'drive.files.insert'
 | 
			
		||||
        req.body.should == @metadata
 | 
			
		||||
        req.media.should == @media
 | 
			
		||||
        req.parameters.should_not be_nil
 | 
			
		||||
        req.parameters[:uploadType].should == 'multipart'
 | 
			
		||||
        expect(req).to be_a(Google::APIClient::Service::Request)
 | 
			
		||||
        expect(req.method.id).to eq('drive.files.insert')
 | 
			
		||||
        expect(req.body).to eq(@metadata)
 | 
			
		||||
        expect(req.media).to eq(@media)
 | 
			
		||||
        expect(req.parameters).not_to be_nil
 | 
			
		||||
        expect(req.parameters[:uploadType]).to eq('multipart')
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should return a valid request with a body and media upload when using resource name' do
 | 
			
		||||
        req = @drive.files.insert(:uploadType => 'multipart').file(@metadata).media(@media)
 | 
			
		||||
        req.should be_a(Google::APIClient::Service::Request)
 | 
			
		||||
        req.method.id.should == 'drive.files.insert'
 | 
			
		||||
        req.file.should == @metadata
 | 
			
		||||
        req.media.should == @media
 | 
			
		||||
        req.parameters.should_not be_nil
 | 
			
		||||
        req.parameters[:uploadType].should == 'multipart'
 | 
			
		||||
        expect(req).to be_a(Google::APIClient::Service::Request)
 | 
			
		||||
        expect(req.method.id).to eq('drive.files.insert')
 | 
			
		||||
        expect(req.file).to eq(@metadata)
 | 
			
		||||
        expect(req.media).to eq(@media)
 | 
			
		||||
        expect(req.parameters).not_to be_nil
 | 
			
		||||
        expect(req.parameters[:uploadType]).to eq('multipart')
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
| 
						 | 
				
			
			@ -280,9 +280,9 @@ describe Google::APIClient::Service do
 | 
			
		|||
          {:application_name => APPLICATION_NAME, :authenticated => false,
 | 
			
		||||
           :cache_store => nil})
 | 
			
		||||
      result = discovery.apis.get_rest(:api => 'discovery', :version => 'v1').execute
 | 
			
		||||
      result.should_not be_nil
 | 
			
		||||
      result.data.name.should == 'discovery'
 | 
			
		||||
      result.data.version.should == 'v1'
 | 
			
		||||
      expect(result).not_to be_nil
 | 
			
		||||
      expect(result.data.name).to eq('discovery')
 | 
			
		||||
      expect(result.data.version).to eq('v1')
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			@ -307,8 +307,8 @@ describe Google::APIClient::Service::Result do
 | 
			
		|||
 | 
			
		||||
      # Response double
 | 
			
		||||
      @response = double("response")
 | 
			
		||||
      @response.stub(:status).and_return(200)
 | 
			
		||||
      @response.stub(:headers).and_return({
 | 
			
		||||
      allow(@response).to receive(:status).and_return(200)
 | 
			
		||||
      allow(@response).to receive(:headers).and_return({
 | 
			
		||||
        'etag' => '12345',
 | 
			
		||||
        'x-google-apiary-auth-scopes' =>
 | 
			
		||||
          'https://www.googleapis.com/auth/plus.me',
 | 
			
		||||
| 
						 | 
				
			
			@ -335,51 +335,54 @@ describe Google::APIClient::Service::Result do
 | 
			
		|||
            "items": []
 | 
			
		||||
          }
 | 
			
		||||
          END_OF_STRING
 | 
			
		||||
        @response.stub(:body).and_return(@body)
 | 
			
		||||
        allow(@response).to receive(:body).and_return(@body)
 | 
			
		||||
        base_result = Google::APIClient::Result.new(@reference, @response)
 | 
			
		||||
        @result = Google::APIClient::Service::Result.new(@request, base_result)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should indicate a successful response' do
 | 
			
		||||
        @result.error?.should be_false
 | 
			
		||||
        expect(@result.error?).to be_falsey
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should return the correct next page token' do
 | 
			
		||||
        @result.next_page_token.should == 'NEXT+PAGE+TOKEN'
 | 
			
		||||
        expect(@result.next_page_token).to eq('NEXT+PAGE+TOKEN')
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'generate a correct request when calling next_page' do
 | 
			
		||||
        next_page_request = @result.next_page
 | 
			
		||||
        next_page_request.parameters.should include('pageToken')
 | 
			
		||||
        next_page_request.parameters['pageToken'].should == 'NEXT+PAGE+TOKEN'
 | 
			
		||||
        expect(next_page_request.parameters).to include('pageToken')
 | 
			
		||||
        expect(next_page_request.parameters['pageToken']).to eq('NEXT+PAGE+TOKEN')
 | 
			
		||||
        @request.parameters.each_pair do |param, value|
 | 
			
		||||
          next_page_request.parameters[param].should == value
 | 
			
		||||
          expect(next_page_request.parameters[param]).to eq(value)
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should return content type correctly' do
 | 
			
		||||
        @result.media_type.should == 'application/json'
 | 
			
		||||
        expect(@result.media_type).to eq('application/json')
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should return the body correctly' do
 | 
			
		||||
        @result.body.should == @body
 | 
			
		||||
        expect(@result.body).to eq(@body)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should return the result data correctly' do
 | 
			
		||||
        @result.data?.should be_true
 | 
			
		||||
        @result.data.class.to_s.should ==
 | 
			
		||||
        expect(@result.data?).to be_truthy
 | 
			
		||||
        expect(@result.data.class.to_s).to eq(
 | 
			
		||||
            'Google::APIClient::Schema::Plus::V1::ActivityFeed'
 | 
			
		||||
        @result.data.kind.should == 'plus#activityFeed'
 | 
			
		||||
        @result.data.etag.should == 'FOO'
 | 
			
		||||
        @result.data.nextPageToken.should == 'NEXT+PAGE+TOKEN'
 | 
			
		||||
        @result.data.selfLink.should ==
 | 
			
		||||
        )
 | 
			
		||||
        expect(@result.data.kind).to eq('plus#activityFeed')
 | 
			
		||||
        expect(@result.data.etag).to eq('FOO')
 | 
			
		||||
        expect(@result.data.nextPageToken).to eq('NEXT+PAGE+TOKEN')
 | 
			
		||||
        expect(@result.data.selfLink).to eq(
 | 
			
		||||
            'https://www.googleapis.com/plus/v1/people/foo/activities/public?'
 | 
			
		||||
        @result.data.nextLink.should ==
 | 
			
		||||
        )
 | 
			
		||||
        expect(@result.data.nextLink).to eq(
 | 
			
		||||
            'https://www.googleapis.com/plus/v1/people/foo/activities/public?' +
 | 
			
		||||
            'maxResults=20&pageToken=NEXT%2BPAGE%2BTOKEN'
 | 
			
		||||
        @result.data.title.should == 'Plus Public Activity Feed for '
 | 
			
		||||
        @result.data.id.should == "123456790"
 | 
			
		||||
        @result.data.items.should be_empty
 | 
			
		||||
        )
 | 
			
		||||
        expect(@result.data.title).to eq('Plus Public Activity Feed for ')
 | 
			
		||||
        expect(@result.data.id).to eq("123456790")
 | 
			
		||||
        expect(@result.data.items).to be_empty
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -396,34 +399,36 @@ describe Google::APIClient::Service::Result do
 | 
			
		|||
            "items": []
 | 
			
		||||
          }
 | 
			
		||||
          END_OF_STRING
 | 
			
		||||
        @response.stub(:body).and_return(@body)
 | 
			
		||||
        allow(@response).to receive(:body).and_return(@body)
 | 
			
		||||
        base_result = Google::APIClient::Result.new(@reference, @response)
 | 
			
		||||
        @result = Google::APIClient::Service::Result.new(@request, base_result)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should not return a next page token' do
 | 
			
		||||
        @result.next_page_token.should == nil
 | 
			
		||||
        expect(@result.next_page_token).to eq(nil)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should return content type correctly' do
 | 
			
		||||
        @result.media_type.should == 'application/json'
 | 
			
		||||
        expect(@result.media_type).to eq('application/json')
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should return the body correctly' do
 | 
			
		||||
        @result.body.should == @body
 | 
			
		||||
        expect(@result.body).to eq(@body)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should return the result data correctly' do
 | 
			
		||||
        @result.data?.should be_true
 | 
			
		||||
        @result.data.class.to_s.should ==
 | 
			
		||||
        expect(@result.data?).to be_truthy
 | 
			
		||||
        expect(@result.data.class.to_s).to eq(
 | 
			
		||||
            'Google::APIClient::Schema::Plus::V1::ActivityFeed'
 | 
			
		||||
        @result.data.kind.should == 'plus#activityFeed'
 | 
			
		||||
        @result.data.etag.should == 'FOO'
 | 
			
		||||
        @result.data.selfLink.should ==
 | 
			
		||||
        )
 | 
			
		||||
        expect(@result.data.kind).to eq('plus#activityFeed')
 | 
			
		||||
        expect(@result.data.etag).to eq('FOO')
 | 
			
		||||
        expect(@result.data.selfLink).to eq(
 | 
			
		||||
            'https://www.googleapis.com/plus/v1/people/foo/activities/public?'
 | 
			
		||||
        @result.data.title.should == 'Plus Public Activity Feed for '
 | 
			
		||||
        @result.data.id.should == "123456790"
 | 
			
		||||
        @result.data.items.should be_empty
 | 
			
		||||
        )
 | 
			
		||||
        expect(@result.data.title).to eq('Plus Public Activity Feed for ')
 | 
			
		||||
        expect(@result.data.id).to eq("123456790")
 | 
			
		||||
        expect(@result.data.items).to be_empty
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -444,44 +449,44 @@ describe Google::APIClient::Service::Result do
 | 
			
		|||
          }
 | 
			
		||||
         }
 | 
			
		||||
         END_OF_STRING
 | 
			
		||||
        @response.stub(:body).and_return(@body)
 | 
			
		||||
        @response.stub(:status).and_return(400)
 | 
			
		||||
        allow(@response).to receive(:body).and_return(@body)
 | 
			
		||||
        allow(@response).to receive(:status).and_return(400)
 | 
			
		||||
        base_result = Google::APIClient::Result.new(@reference, @response)
 | 
			
		||||
        @result = Google::APIClient::Service::Result.new(@request, base_result)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should return error status correctly' do
 | 
			
		||||
        @result.error?.should be_true
 | 
			
		||||
        expect(@result.error?).to be_truthy
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should return the correct error message' do
 | 
			
		||||
        @result.error_message.should == 'Parse Error'
 | 
			
		||||
        expect(@result.error_message).to eq('Parse Error')
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should return the body correctly' do
 | 
			
		||||
        @result.body.should == @body
 | 
			
		||||
        expect(@result.body).to eq(@body)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    describe 'with 204 No Content response' do
 | 
			
		||||
      before do
 | 
			
		||||
        @response.stub(:body).and_return('')
 | 
			
		||||
        @response.stub(:status).and_return(204)
 | 
			
		||||
        @response.stub(:headers).and_return({})
 | 
			
		||||
        allow(@response).to receive(:body).and_return('')
 | 
			
		||||
        allow(@response).to receive(:status).and_return(204)
 | 
			
		||||
        allow(@response).to receive(:headers).and_return({})
 | 
			
		||||
        base_result = Google::APIClient::Result.new(@reference, @response)
 | 
			
		||||
        @result = Google::APIClient::Service::Result.new(@request, base_result)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should indicate no data is available' do
 | 
			
		||||
        @result.data?.should be_false
 | 
			
		||||
        expect(@result.data?).to be_falsey
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should return nil for data' do
 | 
			
		||||
        @result.data.should == nil
 | 
			
		||||
        expect(@result.data).to eq(nil)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should return nil for media_type' do
 | 
			
		||||
        @result.media_type.should == nil
 | 
			
		||||
        expect(@result.media_type).to eq(nil)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
| 
						 | 
				
			
			@ -507,11 +512,11 @@ describe Google::APIClient::Service::BatchRequest do
 | 
			
		|||
        block_called = 0
 | 
			
		||||
        batch = @discovery.batch(@calls) do |result|
 | 
			
		||||
          block_called += 1
 | 
			
		||||
          result.status.should == 200
 | 
			
		||||
          expect(result.status).to eq(200)
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        batch.execute
 | 
			
		||||
        block_called.should == 2
 | 
			
		||||
        expect(block_called).to eq(2)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should execute both when using individual callbacks' do
 | 
			
		||||
| 
						 | 
				
			
			@ -520,19 +525,19 @@ describe Google::APIClient::Service::BatchRequest do
 | 
			
		|||
 | 
			
		||||
        batch.add(@calls[0]) do |result|
 | 
			
		||||
          call1_returned = true
 | 
			
		||||
          result.status.should == 200
 | 
			
		||||
          result.call_index.should == 0
 | 
			
		||||
          expect(result.status).to eq(200)
 | 
			
		||||
          expect(result.call_index).to eq(0)
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        batch.add(@calls[1]) do |result|
 | 
			
		||||
          call2_returned = true
 | 
			
		||||
          result.status.should == 200
 | 
			
		||||
          result.call_index.should == 1
 | 
			
		||||
          expect(result.status).to eq(200)
 | 
			
		||||
          expect(result.call_index).to eq(1)
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        batch.execute
 | 
			
		||||
        call1_returned.should == true
 | 
			
		||||
        call2_returned.should == true
 | 
			
		||||
        expect(call1_returned).to eq(true)
 | 
			
		||||
        expect(call2_returned).to eq(true)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -549,15 +554,15 @@ describe Google::APIClient::Service::BatchRequest do
 | 
			
		|||
        batch = @discovery.batch(@calls) do |result|
 | 
			
		||||
          block_called += 1
 | 
			
		||||
          if result.call_index == 0
 | 
			
		||||
            result.status.should == 200
 | 
			
		||||
            expect(result.status).to eq(200)
 | 
			
		||||
          else
 | 
			
		||||
            result.status.should >= 400
 | 
			
		||||
            result.status.should < 500
 | 
			
		||||
            expect(result.status).to be >= 400
 | 
			
		||||
            expect(result.status).to be < 500
 | 
			
		||||
          end
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        batch.execute
 | 
			
		||||
        block_called.should == 2
 | 
			
		||||
        expect(block_called).to eq(2)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'should execute both when using individual callbacks' do
 | 
			
		||||
| 
						 | 
				
			
			@ -566,20 +571,20 @@ describe Google::APIClient::Service::BatchRequest do
 | 
			
		|||
 | 
			
		||||
        batch.add(@calls[0]) do |result|
 | 
			
		||||
          call1_returned = true
 | 
			
		||||
          result.status.should == 200
 | 
			
		||||
          result.call_index.should == 0
 | 
			
		||||
          expect(result.status).to eq(200)
 | 
			
		||||
          expect(result.call_index).to eq(0)
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        batch.add(@calls[1]) do |result|
 | 
			
		||||
          call2_returned = true
 | 
			
		||||
          result.status.should >= 400
 | 
			
		||||
          result.status.should < 500
 | 
			
		||||
          result.call_index.should == 1
 | 
			
		||||
          expect(result.status).to be >= 400
 | 
			
		||||
          expect(result.status).to be < 500
 | 
			
		||||
          expect(result.call_index).to eq(1)
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        batch.execute
 | 
			
		||||
        call1_returned.should == true
 | 
			
		||||
        call2_returned.should == true
 | 
			
		||||
        expect(call1_returned).to eq(true)
 | 
			
		||||
        expect(call2_returned).to eq(true)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,35 +33,35 @@ describe Google::APIClient::Service::SimpleFileStore do
 | 
			
		|||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should return nil when asked if a key exists' do
 | 
			
		||||
      @cache.exist?('invalid').should be_nil
 | 
			
		||||
      File.exists?(FILE_NAME).should be_false
 | 
			
		||||
      expect(@cache.exist?('invalid')).to be_nil
 | 
			
		||||
      expect(File.exists?(FILE_NAME)).to be_falsey
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should return nil when asked to read a key' do
 | 
			
		||||
      @cache.read('invalid').should be_nil
 | 
			
		||||
      File.exists?(FILE_NAME).should be_false
 | 
			
		||||
      expect(@cache.read('invalid')).to be_nil
 | 
			
		||||
      expect(File.exists?(FILE_NAME)).to be_falsey
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should return nil when asked to fetch a key' do
 | 
			
		||||
      @cache.fetch('invalid').should be_nil
 | 
			
		||||
      File.exists?(FILE_NAME).should be_false
 | 
			
		||||
      expect(@cache.fetch('invalid')).to be_nil
 | 
			
		||||
      expect(File.exists?(FILE_NAME)).to be_falsey
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should create a cache file when asked to fetch a key with a default' do
 | 
			
		||||
      @cache.fetch('new_key') do
 | 
			
		||||
      expect(@cache.fetch('new_key') do
 | 
			
		||||
        'value'
 | 
			
		||||
      end.should == 'value'
 | 
			
		||||
      File.exists?(FILE_NAME).should be_true
 | 
			
		||||
      end).to eq('value')
 | 
			
		||||
      expect(File.exists?(FILE_NAME)).to be_truthy
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should create a cache file when asked to write a key' do
 | 
			
		||||
      @cache.write('new_key', 'value')
 | 
			
		||||
      File.exists?(FILE_NAME).should be_true
 | 
			
		||||
      expect(File.exists?(FILE_NAME)).to be_truthy
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should return nil when asked to delete a key' do
 | 
			
		||||
      @cache.delete('invalid').should be_nil
 | 
			
		||||
      File.exists?(FILE_NAME).should be_false
 | 
			
		||||
      expect(@cache.delete('invalid')).to be_nil
 | 
			
		||||
      expect(File.exists?(FILE_NAME)).to be_falsey
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -73,61 +73,61 @@ describe Google::APIClient::Service::SimpleFileStore do
 | 
			
		|||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should return true when asked if an existing key exists' do
 | 
			
		||||
      @cache.exist?('existing_key').should be_true
 | 
			
		||||
      expect(@cache.exist?('existing_key')).to be_truthy
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should return false when asked if a nonexistent key exists' do
 | 
			
		||||
      @cache.exist?('invalid').should be_false
 | 
			
		||||
      expect(@cache.exist?('invalid')).to be_falsey
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should return the value for an existing key when asked to read it' do
 | 
			
		||||
      @cache.read('existing_key').should == 'existing_value'
 | 
			
		||||
      expect(@cache.read('existing_key')).to eq('existing_value')
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should return nil for a nonexistent key when asked to read it' do
 | 
			
		||||
      @cache.read('invalid').should be_nil
 | 
			
		||||
      expect(@cache.read('invalid')).to be_nil
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should return the value for an existing key when asked to read it' do
 | 
			
		||||
      @cache.read('existing_key').should == 'existing_value'
 | 
			
		||||
      expect(@cache.read('existing_key')).to eq('existing_value')
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should return nil for a nonexistent key when asked to fetch it' do
 | 
			
		||||
      @cache.fetch('invalid').should be_nil
 | 
			
		||||
      expect(@cache.fetch('invalid')).to be_nil
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should return and save the default value for a nonexistent key when asked to fetch it with a default' do
 | 
			
		||||
      @cache.fetch('new_key') do
 | 
			
		||||
      expect(@cache.fetch('new_key') do
 | 
			
		||||
        'value'
 | 
			
		||||
      end.should == 'value'
 | 
			
		||||
      @cache.read('new_key').should == 'value'
 | 
			
		||||
      end).to eq('value')
 | 
			
		||||
      expect(@cache.read('new_key')).to eq('value')
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should remove an existing value and return true when asked to delete it' do
 | 
			
		||||
      @cache.delete('existing_key').should be_true
 | 
			
		||||
      @cache.read('existing_key').should be_nil
 | 
			
		||||
      expect(@cache.delete('existing_key')).to be_truthy
 | 
			
		||||
      expect(@cache.read('existing_key')).to be_nil
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should return false when asked to delete a nonexistent key' do
 | 
			
		||||
      @cache.delete('invalid').should be_false
 | 
			
		||||
      expect(@cache.delete('invalid')).to be_falsey
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should convert keys to strings when storing them' do
 | 
			
		||||
      @cache.write(:symbol_key, 'value')
 | 
			
		||||
      @cache.read('symbol_key').should == 'value'
 | 
			
		||||
      expect(@cache.read('symbol_key')).to eq('value')
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should convert keys to strings when reading them' do
 | 
			
		||||
      @cache.read(:existing_key).should == 'existing_value'
 | 
			
		||||
      expect(@cache.read(:existing_key)).to eq('existing_value')
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should convert keys to strings when fetching them' do
 | 
			
		||||
      @cache.fetch(:existing_key).should == 'existing_value'
 | 
			
		||||
      expect(@cache.fetch(:existing_key)).to eq('existing_value')
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should convert keys to strings when deleting them' do
 | 
			
		||||
      @cache.delete(:existing_key).should be_true
 | 
			
		||||
      @cache.read('existing_key').should be_nil
 | 
			
		||||
      expect(@cache.delete(:existing_key)).to be_truthy
 | 
			
		||||
      expect(@cache.read('existing_key')).to be_nil
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -24,19 +24,19 @@ shared_examples_for 'configurable user agent' do
 | 
			
		|||
  
 | 
			
		||||
  it 'should allow the user agent to be modified' do
 | 
			
		||||
    client.user_agent = 'Custom User Agent/1.2.3'
 | 
			
		||||
    client.user_agent.should == 'Custom User Agent/1.2.3'
 | 
			
		||||
    expect(client.user_agent).to eq('Custom User Agent/1.2.3')
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it 'should allow the user agent to be set to nil' do
 | 
			
		||||
    client.user_agent = nil
 | 
			
		||||
    client.user_agent.should == nil
 | 
			
		||||
    expect(client.user_agent).to eq(nil)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it 'should not allow the user agent to be used with bogus values' do
 | 
			
		||||
    (lambda do
 | 
			
		||||
    expect(lambda do
 | 
			
		||||
      client.user_agent = 42
 | 
			
		||||
      client.execute(:uri=>'https://www.google.com/')
 | 
			
		||||
    end).should raise_error(TypeError)
 | 
			
		||||
    end).to raise_error(TypeError)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it 'should transmit a User-Agent header when sending requests' do
 | 
			
		||||
| 
						 | 
				
			
			@ -45,8 +45,8 @@ shared_examples_for 'configurable user agent' do
 | 
			
		|||
    conn = stub_connection do |stub|
 | 
			
		||||
      stub.get('/') do |env|
 | 
			
		||||
        headers = env[:request_headers]
 | 
			
		||||
        headers.should have_key('User-Agent')
 | 
			
		||||
        headers['User-Agent'].should == client.user_agent
 | 
			
		||||
        expect(headers).to have_key('User-Agent')
 | 
			
		||||
        expect(headers['User-Agent']).to eq(client.user_agent)
 | 
			
		||||
        [200, {}, ['']]
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
| 
						 | 
				
			
			@ -61,11 +61,11 @@ describe Google::APIClient do
 | 
			
		|||
  let(:client) { Google::APIClient.new(:application_name => 'API Client Tests') }
 | 
			
		||||
 | 
			
		||||
  it 'should make its version number available' do
 | 
			
		||||
    Google::APIClient::VERSION::STRING.should be_instance_of(String)
 | 
			
		||||
    expect(Google::APIClient::VERSION::STRING).to be_instance_of(String)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it 'should default to OAuth 2' do
 | 
			
		||||
    Signet::OAuth2::Client.should === client.authorization
 | 
			
		||||
    expect(Signet::OAuth2::Client).to be === client.authorization
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe 'configure for no authentication' do
 | 
			
		||||
| 
						 | 
				
			
			@ -83,15 +83,17 @@ describe Google::APIClient do
 | 
			
		|||
    end
 | 
			
		||||
 | 
			
		||||
    it 'should use the default OAuth1 client configuration' do
 | 
			
		||||
      client.authorization.temporary_credential_uri.to_s.should ==
 | 
			
		||||
      expect(client.authorization.temporary_credential_uri.to_s).to eq(
 | 
			
		||||
        'https://www.google.com/accounts/OAuthGetRequestToken'
 | 
			
		||||
      client.authorization.authorization_uri.to_s.should include(
 | 
			
		||||
      )
 | 
			
		||||
      expect(client.authorization.authorization_uri.to_s).to include(
 | 
			
		||||
        'https://www.google.com/accounts/OAuthAuthorizeToken'
 | 
			
		||||
      )
 | 
			
		||||
      client.authorization.token_credential_uri.to_s.should ==
 | 
			
		||||
      expect(client.authorization.token_credential_uri.to_s).to eq(
 | 
			
		||||
        'https://www.google.com/accounts/OAuthGetAccessToken'
 | 
			
		||||
      client.authorization.client_credential_key.should == 'anonymous'
 | 
			
		||||
      client.authorization.client_credential_secret.should == 'anonymous'
 | 
			
		||||
      )
 | 
			
		||||
      expect(client.authorization.client_credential_key).to eq('anonymous')
 | 
			
		||||
      expect(client.authorization.client_credential_secret).to eq('anonymous')
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it_should_behave_like 'configurable user agent'
 | 
			
		||||
| 
						 | 
				
			
			@ -113,7 +115,7 @@ describe Google::APIClient do
 | 
			
		|||
      client.authorization = :oauth_2
 | 
			
		||||
      @connection = stub_connection do |stub|
 | 
			
		||||
        stub.post('/prediction/v1.2/training?data=12345') do |env|
 | 
			
		||||
          env[:request_headers]['Authorization'].should == 'Bearer 12345'
 | 
			
		||||
          expect(env[:request_headers]['Authorization']).to eq('Bearer 12345')
 | 
			
		||||
          [200, {}, '{}']
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
| 
						 | 
				
			
			@ -234,7 +236,7 @@ describe Google::APIClient do
 | 
			
		|||
      count = 0
 | 
			
		||||
      @connection = stub_connection do |stub|
 | 
			
		||||
        stub.get('/foo') do |env|
 | 
			
		||||
          count.should == 0
 | 
			
		||||
          expect(count).to eq(0)
 | 
			
		||||
          count += 1
 | 
			
		||||
          [403, {}, '{}']
 | 
			
		||||
        end
 | 
			
		||||
| 
						 | 
				
			
			@ -259,10 +261,10 @@ describe Google::APIClient do
 | 
			
		|||
        end
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      client.execute(  
 | 
			
		||||
      expect(client.execute(  
 | 
			
		||||
        :uri => 'https://www.gogole.com/foo',
 | 
			
		||||
        :connection => @connection
 | 
			
		||||
      ).status.should == 200
 | 
			
		||||
      ).status).to eq(200)
 | 
			
		||||
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -276,11 +278,11 @@ describe Google::APIClient do
 | 
			
		|||
        end
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      client.execute(  
 | 
			
		||||
      expect(client.execute(  
 | 
			
		||||
        :uri => 'https://www.gogole.com/foo',
 | 
			
		||||
        :connection => @connection
 | 
			
		||||
      ).status.should == 500
 | 
			
		||||
      count.should == 3
 | 
			
		||||
      ).status).to eq(500)
 | 
			
		||||
      expect(count).to eq(3)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
  end  
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,6 +4,14 @@ $LOAD_PATH.uniq!
 | 
			
		|||
require 'rspec'
 | 
			
		||||
require 'faraday'
 | 
			
		||||
 | 
			
		||||
begin
 | 
			
		||||
  require 'simplecov'
 | 
			
		||||
 | 
			
		||||
  SimpleCov.start
 | 
			
		||||
rescue LoadError
 | 
			
		||||
  # SimpleCov missing, so just run specs with no coverage.
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
Faraday::Adapter.load_middleware(:test)
 | 
			
		||||
 | 
			
		||||
module Faraday
 | 
			
		||||
| 
						 | 
				
			
			@ -46,7 +54,7 @@ module JSONMatchers
 | 
			
		|||
      "expected #{@target.inspect} not to be #{@expected}"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
  
 | 
			
		||||
 | 
			
		||||
  def be_json(expected)
 | 
			
		||||
    EqualsJson.new(expected)
 | 
			
		||||
  end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -37,7 +37,7 @@ namespace :gem do
 | 
			
		|||
 | 
			
		||||
    # Dependencies used in the examples
 | 
			
		||||
    s.add_development_dependency('rake', '>= 0.9.0')
 | 
			
		||||
    s.add_development_dependency('rspec', '>= 2.11.0')
 | 
			
		||||
    s.add_development_dependency('rspec', '~> 3.0')
 | 
			
		||||
 | 
			
		||||
    s.require_path = 'lib'
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,7 +7,6 @@ namespace :spec do
 | 
			
		|||
  RSpec::Core::RakeTask.new(:all) do |t|
 | 
			
		||||
    t.pattern = FileList['spec/**/*_spec.rb']
 | 
			
		||||
    t.rspec_opts = ['--color', '--format', 'documentation']
 | 
			
		||||
    t.rcov = false
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  desc 'Generate HTML Specdocs for all specs.'
 | 
			
		||||
| 
						 | 
				
			
			@ -17,41 +16,7 @@ namespace :spec do
 | 
			
		|||
    t.rspec_opts = %W( --format html --out #{File.join(specdoc_path, 'index.html')} )
 | 
			
		||||
    t.fail_on_error = false
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  RSpec::Core::RakeTask.new(:rcov) do |t|
 | 
			
		||||
    if RCOV_ENABLED
 | 
			
		||||
      if `which rcov`.strip == ""
 | 
			
		||||
        STDERR.puts(
 | 
			
		||||
            "Please install rcov and ensure that its binary is in the PATH:"
 | 
			
		||||
        )
 | 
			
		||||
        STDERR.puts("sudo gem install rcov")
 | 
			
		||||
        exit(1)
 | 
			
		||||
      end
 | 
			
		||||
      t.rcov = true
 | 
			
		||||
    else
 | 
			
		||||
      t.rcov = false
 | 
			
		||||
    end
 | 
			
		||||
    t.rcov_opts = %w(
 | 
			
		||||
         --exclude gems/
 | 
			
		||||
         --exclude spec/
 | 
			
		||||
         --exclude lib/google/api_client/environment.rb
 | 
			
		||||
         --exclude lib/compat
 | 
			
		||||
    )
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  namespace :rcov do
 | 
			
		||||
    desc 'Browse the code coverage report.'
 | 
			
		||||
    task :browse => 'spec:rcov' do
 | 
			
		||||
      require 'launchy'
 | 
			
		||||
      Launchy::Browser.run('coverage/index.html')
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
if RCOV_ENABLED
 | 
			
		||||
  desc 'Alias to spec:rcov'
 | 
			
		||||
  task 'spec' => 'spec:rcov'
 | 
			
		||||
else
 | 
			
		||||
  desc 'Alias to spec:all'
 | 
			
		||||
  task 'spec' => 'spec:all'
 | 
			
		||||
end
 | 
			
		||||
desc 'Alias to spec:all'
 | 
			
		||||
task 'spec' => 'spec:all'
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue