So many versions!!
[arvados.git] / spec / google / api_client / discovery_spec.rb
index 0b0f89c22d11749a3c8691006ee73fc887459eea..a047bab038dc1306453422fcd80f505a2ca9a80a 100644 (file)
@@ -22,7 +22,6 @@ require 'multi_json'
 require 'compat/multi_json'
 require 'signet/oauth_1/client'
 require 'google/api_client'
-require 'google/api_client/version'
 
 describe Google::APIClient do
   include ConnectionHelpers
@@ -35,40 +34,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 +79,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 +134,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 +206,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 +221,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 +270,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 +290,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 +310,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 +332,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 +342,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 +354,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 +395,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 +442,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 +460,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 +471,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 +513,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 +531,7 @@ describe Google::APIClient do
           [200, {}, '{}']
         end
       end
-      (lambda do
+      expect(lambda do
         CLIENT.execute(
           :api_method => @adsense.reports.generate,
           :parameters => {
@@ -544,12 +543,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 +559,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 +570,7 @@ describe Google::APIClient do
           [200, {}, '{}']
         end
       end
-      (lambda do
+      expect(lambda do
         CLIENT.execute(
           :api_method => @adsense.reports.generate,
           :parameters => {
@@ -583,12 +582,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 +598,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 +606,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 +633,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