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:
Sérgio Gomes 2014-08-14 16:54:16 +01:00
parent bfa5225766
commit 78ff182905
14 changed files with 410 additions and 425 deletions

View File

@ -33,9 +33,8 @@ end
group :test, :development do group :test, :development do
gem 'json', '~> 1.7.7' gem 'json', '~> 1.7.7'
gem 'rake', '>= 0.9.0' gem 'rake', '>= 0.9.0'
gem 'rspec', '>= 2.11.0' gem 'rspec', '~> 3.0'
gem 'rcov', '>= 0.9.9', :platform => :mri_18 gem 'simplecov', :platforms => [:ruby_19, :ruby_20], :require => false
end end
gem 'idn', :platforms => :mri_18
gem 'idn', :platform => :mri_18

View File

@ -28,9 +28,9 @@ describe Google::APIClient::BatchRequest do
it 'should raise an error if making an empty batch request' do it 'should raise an error if making an empty batch request' do
batch = Google::APIClient::BatchRequest.new batch = Google::APIClient::BatchRequest.new
(lambda do expect(lambda do
CLIENT.execute(batch) CLIENT.execute(batch)
end).should raise_error(Google::APIClient::BatchError) end).to raise_error(Google::APIClient::BatchError)
end end
it 'should allow query parameters in batch requests' do it 'should allow query parameters in batch requests' do
@ -39,7 +39,7 @@ describe Google::APIClient::BatchRequest do
'a' => '12345' 'a' => '12345'
}) })
method, uri, headers, body = batch.to_http_request method, uri, headers, body = batch.to_http_request
body.read.should include("/?a=12345") expect(body.read).to include("/?a=12345")
end end
describe 'with the discovery API' do describe 'with the discovery API' do
@ -73,8 +73,8 @@ describe Google::APIClient::BatchRequest do
expected_ids = ids.clone expected_ids = ids.clone
batch = Google::APIClient::BatchRequest.new do |result| batch = Google::APIClient::BatchRequest.new do |result|
block_called += 1 block_called += 1
result.status.should == 200 expect(result.status).to eq(200)
expected_ids.should include(result.response.call_id) expect(expected_ids).to include(result.response.call_id)
expected_ids.delete(result.response.call_id) expected_ids.delete(result.response.call_id)
end end
@ -82,7 +82,7 @@ describe Google::APIClient::BatchRequest do
batch.add(@call2, ids[1]) batch.add(@call2, ids[1])
CLIENT.execute(batch) CLIENT.execute(batch)
block_called.should == 2 expect(block_called).to eq(2)
end end
it 'should execute both when using individual callbacks' do it 'should execute both when using individual callbacks' do
@ -91,25 +91,25 @@ describe Google::APIClient::BatchRequest do
call1_returned, call2_returned = false, false call1_returned, call2_returned = false, false
batch.add(@call1) do |result| batch.add(@call1) do |result|
call1_returned = true call1_returned = true
result.status.should == 200 expect(result.status).to eq(200)
end end
batch.add(@call2) do |result| batch.add(@call2) do |result|
call2_returned = true call2_returned = true
result.status.should == 200 expect(result.status).to eq(200)
end end
CLIENT.execute(batch) CLIENT.execute(batch)
call1_returned.should == true expect(call1_returned).to be_truthy
call2_returned.should == true expect(call2_returned).to be_truthy
end end
it 'should raise an error if using the same call ID more than once' do it 'should raise an error if using the same call ID more than once' do
batch = Google::APIClient::BatchRequest.new batch = Google::APIClient::BatchRequest.new
(lambda do expect(lambda do
batch.add(@call1, 'my_id') batch.add(@call1, 'my_id')
batch.add(@call2, 'my_id') batch.add(@call2, 'my_id')
end).should raise_error(Google::APIClient::BatchError) end).to raise_error(Google::APIClient::BatchError)
end end
end end
@ -138,13 +138,13 @@ describe Google::APIClient::BatchRequest do
expected_ids = ids.clone expected_ids = ids.clone
batch = Google::APIClient::BatchRequest.new do |result| batch = Google::APIClient::BatchRequest.new do |result|
block_called += 1 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) expected_ids.delete(result.response.call_id)
if result.response.call_id == ids[0] if result.response.call_id == ids[0]
result.status.should == 200 expect(result.status).to eq(200)
else else
result.status.should >= 400 expect(result.status).to be >= 400
result.status.should < 500 expect(result.status).to be < 500
end end
end end
@ -152,7 +152,7 @@ describe Google::APIClient::BatchRequest do
batch.add(@call2, ids[1]) batch.add(@call2, ids[1])
CLIENT.execute(batch) CLIENT.execute(batch)
block_called.should == 2 expect(block_called).to eq(2)
end end
it 'should execute both when using individual callbacks' do it 'should execute both when using individual callbacks' do
@ -161,17 +161,17 @@ describe Google::APIClient::BatchRequest do
call1_returned, call2_returned = false, false call1_returned, call2_returned = false, false
batch.add(@call1) do |result| batch.add(@call1) do |result|
call1_returned = true call1_returned = true
result.status.should == 200 expect(result.status).to eq(200)
end end
batch.add(@call2) do |result| batch.add(@call2) do |result|
call2_returned = true call2_returned = true
result.status.should >= 400 expect(result.status).to be >= 400
result.status.should < 500 expect(result.status).to be < 500
end end
CLIENT.execute(batch) CLIENT.execute(batch)
call1_returned.should == true expect(call1_returned).to be_truthy
call2_returned.should == true expect(call2_returned).to be_truthy
end end
end end
end end
@ -236,12 +236,12 @@ describe Google::APIClient::BatchRequest do
batch.add(@call1, '1').add(@call2, '2') batch.add(@call1, '1').add(@call2, '2')
request = batch.to_env(CLIENT.connection) request = batch.to_env(CLIENT.connection)
boundary = Google::APIClient::BatchRequest::BATCH_BOUNDARY boundary = Google::APIClient::BatchRequest::BATCH_BOUNDARY
request[:method].to_s.downcase.should == 'post' expect(request[:method].to_s.downcase).to eq('post')
request[:url].to_s.should == 'https://www.googleapis.com/batch' expect(request[:url].to_s).to eq('https://www.googleapis.com/batch')
request[:request_headers]['Content-Type'].should == "multipart/mixed;boundary=#{boundary}" expect(request[:request_headers]['Content-Type']).to eq("multipart/mixed;boundary=#{boundary}")
# TODO - Fix headers body = request[:body].read
#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)}--/ expect(body).to include(@call1[:body])
#request[:body].read.gsub("\r", "").should =~ expected_body expect(body).to include(@call2[:body])
end end
end end

View File

@ -35,40 +35,40 @@ describe Google::APIClient do
end end
it 'should raise a type error for bogus authorization' do 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) Google::APIClient.new(:application_name => 'API Client Tests', :authorization => 42)
end).should raise_error(TypeError) end).to raise_error(TypeError)
end end
it 'should not be able to retrieve the discovery document for a bogus API' do it 'should not be able to retrieve the discovery document for a bogus API' do
(lambda do expect(lambda do
CLIENT.discovery_document('bogus') CLIENT.discovery_document('bogus')
end).should raise_error(Google::APIClient::TransmissionError) end).to raise_error(Google::APIClient::TransmissionError)
(lambda do expect(lambda do
CLIENT.discovered_api('bogus') CLIENT.discovered_api('bogus')
end).should raise_error(Google::APIClient::TransmissionError) end).to raise_error(Google::APIClient::TransmissionError)
end end
it 'should raise an error for bogus services' do it 'should raise an error for bogus services' do
(lambda do expect(lambda do
CLIENT.discovered_api(42) CLIENT.discovered_api(42)
end).should raise_error(TypeError) end).to raise_error(TypeError)
end end
it 'should raise an error for bogus services' do it 'should raise an error for bogus services' do
(lambda do expect(lambda do
CLIENT.preferred_version(42) CLIENT.preferred_version(42)
end).should raise_error(TypeError) end).to raise_error(TypeError)
end end
it 'should raise an error for bogus methods' do it 'should raise an error for bogus methods' do
(lambda do expect(lambda do
CLIENT.execute(42) CLIENT.execute(42)
end).should raise_error(TypeError) end).to raise_error(TypeError)
end end
it 'should not return a preferred version for bogus service names' do 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 end
describe 'with the prediction API' do describe 'with the prediction API' do
@ -80,7 +80,7 @@ describe Google::APIClient do
end end
it 'should correctly determine the discovery URI' do 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' 'https://www.googleapis.com/discovery/v1/apis/prediction/v1/rest'
end end
@ -135,61 +135,61 @@ describe Google::APIClient do
end end
it 'should correctly generate API objects' do it 'should correctly generate API objects' do
CLIENT.discovered_api('prediction', 'v1.2').name.should == 'prediction' expect(CLIENT.discovered_api('prediction', 'v1.2').name).to eq('prediction')
CLIENT.discovered_api('prediction', 'v1.2').version.should == 'v1.2' expect(CLIENT.discovered_api('prediction', 'v1.2').version).to eq('v1.2')
CLIENT.discovered_api(:prediction, 'v1.2').name.should == 'prediction' expect(CLIENT.discovered_api(:prediction, 'v1.2').name).to eq('prediction')
CLIENT.discovered_api(:prediction, 'v1.2').version.should == 'v1.2' expect(CLIENT.discovered_api(:prediction, 'v1.2').version).to eq('v1.2')
end end
it 'should discover methods' do it 'should discover methods' do
CLIENT.discovered_method( expect(CLIENT.discovered_method(
'prediction.training.insert', 'prediction', 'v1.2' 'prediction.training.insert', 'prediction', 'v1.2'
).name.should == 'insert' ).name).to eq('insert')
CLIENT.discovered_method( expect(CLIENT.discovered_method(
:'prediction.training.insert', :prediction, 'v1.2' :'prediction.training.insert', :prediction, 'v1.2'
).name.should == 'insert' ).name).to eq('insert')
CLIENT.discovered_method( expect(CLIENT.discovered_method(
'prediction.training.delete', 'prediction', 'v1.2' 'prediction.training.delete', 'prediction', 'v1.2'
).name.should == 'delete' ).name).to eq('delete')
end end
it 'should define the origin API in discovered methods' do it 'should define the origin API in discovered methods' do
CLIENT.discovered_method( expect(CLIENT.discovered_method(
'prediction.training.insert', 'prediction', 'v1.2' 'prediction.training.insert', 'prediction', 'v1.2'
).api.name.should == 'prediction' ).api.name).to eq('prediction')
end end
it 'should not find methods that are not in the discovery document' do 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' 'prediction.bogus', 'prediction', 'v1.2'
).should == nil )).to eq(nil)
end end
it 'should raise an error for bogus methods' do it 'should raise an error for bogus methods' do
(lambda do expect(lambda do
CLIENT.discovered_method(42, 'prediction', 'v1.2') CLIENT.discovered_method(42, 'prediction', 'v1.2')
end).should raise_error(TypeError) end).to raise_error(TypeError)
end end
it 'should raise an error for bogus methods' do it 'should raise an error for bogus methods' do
(lambda do expect(lambda do
CLIENT.execute(:api_method => CLIENT.discovered_api('prediction', 'v1.2')) CLIENT.execute(:api_method => CLIENT.discovered_api('prediction', 'v1.2'))
end).should raise_error(TypeError) end).to raise_error(TypeError)
end end
it 'should correctly determine the preferred version' do it 'should correctly determine the preferred version' do
CLIENT.preferred_version('prediction').version.should_not == 'v1' expect(CLIENT.preferred_version('prediction').version).not_to eq('v1')
CLIENT.preferred_version(:prediction).version.should_not == 'v1' expect(CLIENT.preferred_version(:prediction).version).not_to eq('v1')
end end
it 'should return a batch path' do 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 end
it 'should generate valid requests' do it 'should generate valid requests' do
conn = stub_connection do |stub| conn = stub_connection do |stub|
stub.post('/prediction/v1.2/training?data=12345') do |env| stub.post('/prediction/v1.2/training?data=12345') do |env|
env[:body].should == '' expect(env[:body]).to eq('')
[200, {}, '{}'] [200, {}, '{}']
end end
end end
@ -207,7 +207,7 @@ describe Google::APIClient do
# bare ampersand (&) in 0.4.7. ensure that it gets converted # bare ampersand (&) in 0.4.7. ensure that it gets converted
# to a CGI-escaped semicolon (%3B) instead. # to a CGI-escaped semicolon (%3B) instead.
stub.post('/prediction/v1.2/training?data=12345%3B67890') do |env| stub.post('/prediction/v1.2/training?data=12345%3B67890') do |env|
env[:body].should == '' expect(env[:body]).to eq('')
[200, {}, '{}'] [200, {}, '{}']
end end
end end
@ -222,7 +222,7 @@ describe Google::APIClient do
it 'should generate valid requests when multivalued parameters are passed' do it 'should generate valid requests when multivalued parameters are passed' do
conn = stub_connection do |stub| conn = stub_connection do |stub|
stub.post('/prediction/v1.2/training?data=1&data=2') do |env| 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, {}, '{}'] [200, {}, '{}']
end end
end end
@ -271,7 +271,7 @@ describe Google::APIClient do
conn = stub_connection do |stub| conn = stub_connection do |stub|
stub.post('/prediction/v1.2/training') do |env| 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, {}, '{}'] [200, {}, '{}']
end end
end end
@ -291,8 +291,8 @@ describe Google::APIClient do
conn = stub_connection do |stub| conn = stub_connection do |stub|
stub.post('/prediction/v1.2/training?data=12345') do |env| stub.post('/prediction/v1.2/training?data=12345') do |env|
env[:request_headers].should have_key('Authorization') expect(env[:request_headers]).to have_key('Authorization')
env[:request_headers]['Authorization'].should =~ /^OAuth/ expect(env[:request_headers]['Authorization']).to match(/^OAuth/)
[200, {}, '{}'] [200, {}, '{}']
end end
end end
@ -311,8 +311,8 @@ describe Google::APIClient do
conn = stub_connection do |stub| conn = stub_connection do |stub|
stub.post('/prediction/v1.2/training?data=12345') do |env| stub.post('/prediction/v1.2/training?data=12345') do |env|
env[:request_headers].should have_key('Authorization') expect(env[:request_headers]).to have_key('Authorization')
env[:request_headers]['Authorization'].should =~ /^Bearer/ expect(env[:request_headers]['Authorization']).to match(/^Bearer/)
[200, {}, '{}'] [200, {}, '{}']
end end
end end
@ -333,7 +333,7 @@ describe Google::APIClient do
@prediction.training.insert, @prediction.training.insert,
{'data' => '12345'} {'data' => '12345'}
) )
result.response.status.should == 401 expect(result.response.status).to eq(401)
end end
it 'should not be able to execute improperly authorized requests' do it 'should not be able to execute improperly authorized requests' do
@ -343,11 +343,11 @@ describe Google::APIClient do
@prediction.training.insert, @prediction.training.insert,
{'data' => '12345'} {'data' => '12345'}
) )
result.response.status.should == 401 expect(result.response.status).to eq(401)
end end
it 'should not be able to execute improperly authorized requests' do it 'should not be able to execute improperly authorized requests' do
(lambda do expect(lambda do
CLIENT.authorization = :oauth_1 CLIENT.authorization = :oauth_1
CLIENT.authorization.token_credential_key = '12345' CLIENT.authorization.token_credential_key = '12345'
CLIENT.authorization.token_credential_secret = '12345' CLIENT.authorization.token_credential_secret = '12345'
@ -355,25 +355,25 @@ describe Google::APIClient do
@prediction.training.insert, @prediction.training.insert,
{'data' => '12345'} {'data' => '12345'}
) )
end).should raise_error(Google::APIClient::ClientError) end).to raise_error(Google::APIClient::ClientError)
end end
it 'should not be able to execute improperly authorized requests' do it 'should not be able to execute improperly authorized requests' do
(lambda do expect(lambda do
CLIENT.authorization = :oauth_2 CLIENT.authorization = :oauth_2
CLIENT.authorization.access_token = '12345' CLIENT.authorization.access_token = '12345'
result = CLIENT.execute!( result = CLIENT.execute!(
@prediction.training.insert, @prediction.training.insert,
{'data' => '12345'} {'data' => '12345'}
) )
end).should raise_error(Google::APIClient::ClientError) end).to raise_error(Google::APIClient::ClientError)
end end
it 'should correctly handle unnamed parameters' do it 'should correctly handle unnamed parameters' do
conn = stub_connection do |stub| conn = stub_connection do |stub|
stub.post('/prediction/v1.2/training') do |env| stub.post('/prediction/v1.2/training') do |env|
env[:request_headers].should have_key('Content-Type') expect(env[:request_headers]).to have_key('Content-Type')
env[:request_headers]['Content-Type'].should == 'application/json' expect(env[:request_headers]['Content-Type']).to eq('application/json')
[200, {}, '{}'] [200, {}, '{}']
end end
end end
@ -396,32 +396,32 @@ describe Google::APIClient do
end end
it 'should correctly determine the discovery URI' do 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' 'https://www.googleapis.com/discovery/v1/apis/plus/v1/rest'
end end
it 'should find APIs that are in the discovery document' do it 'should find APIs that are in the discovery document' do
CLIENT.discovered_api('plus').name.should == 'plus' expect(CLIENT.discovered_api('plus').name).to eq('plus')
CLIENT.discovered_api('plus').version.should == 'v1' expect(CLIENT.discovered_api('plus').version).to eq('v1')
CLIENT.discovered_api(:plus).name.should == 'plus' expect(CLIENT.discovered_api(:plus).name).to eq('plus')
CLIENT.discovered_api(:plus).version.should == 'v1' expect(CLIENT.discovered_api(:plus).version).to eq('v1')
end end
it 'should find methods that are in the discovery document' do it 'should find methods that are in the discovery document' do
# TODO(bobaman) Fix this when the RPC names are correct # TODO(bobaman) Fix this when the RPC names are correct
CLIENT.discovered_method( expect(CLIENT.discovered_method(
'plus.activities.list', 'plus' 'plus.activities.list', 'plus'
).name.should == 'list' ).name).to eq('list')
end end
it 'should define the origin API in discovered methods' do it 'should define the origin API in discovered methods' do
CLIENT.discovered_method( expect(CLIENT.discovered_method(
'plus.activities.list', 'plus' 'plus.activities.list', 'plus'
).api.name.should == 'plus' ).api.name).to eq('plus')
end end
it 'should not find methods that are not in the discovery document' do 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 end
it 'should generate requests against the correct URIs' do it 'should generate requests against the correct URIs' do
@ -443,17 +443,17 @@ describe Google::APIClient do
end end
it 'should correctly validate parameters' do it 'should correctly validate parameters' do
(lambda do expect(lambda do
CLIENT.execute( CLIENT.execute(
:api_method => @plus.activities.list, :api_method => @plus.activities.list,
:parameters => {'alt' => 'json'}, :parameters => {'alt' => 'json'},
:authenticated => false :authenticated => false
) )
end).should raise_error(ArgumentError) end).to raise_error(ArgumentError)
end end
it 'should correctly validate parameters' do it 'should correctly validate parameters' do
(lambda do expect(lambda do
CLIENT.execute( CLIENT.execute(
:api_method => @plus.activities.list, :api_method => @plus.activities.list,
:parameters => { :parameters => {
@ -461,7 +461,7 @@ describe Google::APIClient do
}, },
:authenticated => false :authenticated => false
).to_env(CLIENT.connection) ).to_env(CLIENT.connection)
end).should raise_error(ArgumentError) end).to raise_error(ArgumentError)
end end
end end
@ -472,27 +472,27 @@ describe Google::APIClient do
end end
it 'should correctly determine the discovery URI' do 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' 'https://www.googleapis.com/discovery/v1/apis/adsense/v1.3/rest'
end end
it 'should find APIs that are in the discovery document' do it 'should find APIs that are in the discovery document' do
CLIENT.discovered_api('adsense', 'v1.3').name.should == 'adsense' expect(CLIENT.discovered_api('adsense', 'v1.3').name).to eq('adsense')
CLIENT.discovered_api('adsense', 'v1.3').version.should == 'v1.3' expect(CLIENT.discovered_api('adsense', 'v1.3').version).to eq('v1.3')
end end
it 'should return a batch path' do 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 end
it 'should find methods that are in the discovery document' do it 'should find methods that are in the discovery document' do
CLIENT.discovered_method( expect(CLIENT.discovered_method(
'adsense.reports.generate', 'adsense', 'v1.3' 'adsense.reports.generate', 'adsense', 'v1.3'
).name.should == 'generate' ).name).to eq('generate')
end end
it 'should not find methods that are not in the discovery document' do 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 end
it 'should generate requests against the correct URIs' do it 'should generate requests against the correct URIs' do
@ -514,16 +514,16 @@ describe Google::APIClient do
:api_method => @adsense.adclients.list, :api_method => @adsense.adclients.list,
:authenticated => false :authenticated => false
) )
result.response.status.should == 401 expect(result.response.status).to eq(401)
end end
it 'should fail when validating missing required parameters' do it 'should fail when validating missing required parameters' do
(lambda do expect(lambda do
CLIENT.execute( CLIENT.execute(
:api_method => @adsense.reports.generate, :api_method => @adsense.reports.generate,
:authenticated => false :authenticated => false
) )
end).should raise_error(ArgumentError) end).to raise_error(ArgumentError)
end end
it 'should succeed when validating parameters in a correct call' do it 'should succeed when validating parameters in a correct call' do
@ -532,7 +532,7 @@ describe Google::APIClient do
[200, {}, '{}'] [200, {}, '{}']
end end
end end
(lambda do expect(lambda do
CLIENT.execute( CLIENT.execute(
:api_method => @adsense.reports.generate, :api_method => @adsense.reports.generate,
:parameters => { :parameters => {
@ -544,12 +544,12 @@ describe Google::APIClient do
:authenticated => false, :authenticated => false,
:connection => conn :connection => conn
) )
end).should_not raise_error end).not_to raise_error
conn.verify conn.verify
end end
it 'should fail when validating parameters with invalid values' do it 'should fail when validating parameters with invalid values' do
(lambda do expect(lambda do
CLIENT.execute( CLIENT.execute(
:api_method => @adsense.reports.generate, :api_method => @adsense.reports.generate,
:parameters => { :parameters => {
@ -560,7 +560,7 @@ describe Google::APIClient do
}, },
:authenticated => false :authenticated => false
) )
end).should raise_error(ArgumentError) end).to raise_error(ArgumentError)
end end
it 'should succeed when validating repeated parameters in a correct call' do it 'should succeed when validating repeated parameters in a correct call' do
@ -571,7 +571,7 @@ describe Google::APIClient do
[200, {}, '{}'] [200, {}, '{}']
end end
end end
(lambda do expect(lambda do
CLIENT.execute( CLIENT.execute(
:api_method => @adsense.reports.generate, :api_method => @adsense.reports.generate,
:parameters => { :parameters => {
@ -583,12 +583,12 @@ describe Google::APIClient do
:authenticated => false, :authenticated => false,
:connection => conn :connection => conn
) )
end).should_not raise_error end).not_to raise_error
conn.verify conn.verify
end end
it 'should fail when validating incorrect repeated parameters' do it 'should fail when validating incorrect repeated parameters' do
(lambda do expect(lambda do
CLIENT.execute( CLIENT.execute(
:api_method => @adsense.reports.generate, :api_method => @adsense.reports.generate,
:parameters => { :parameters => {
@ -599,7 +599,7 @@ describe Google::APIClient do
}, },
:authenticated => false :authenticated => false
) )
end).should raise_error(ArgumentError) end).to raise_error(ArgumentError)
end end
it 'should generate valid requests when multivalued parameters are passed' do 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'+ stub.get('/adsense/v1.3/reports?dimension=DATE&dimension=PRODUCT_CODE'+
'&endDate=2010-01-01&metric=CLICKS&metric=PAGE_VIEWS&'+ '&endDate=2010-01-01&metric=CLICKS&metric=PAGE_VIEWS&'+
'startDate=2000-01-01') do |env| 'startDate=2000-01-01') do |env|
env.params['dimension'].should include('DATE', 'PRODUCT_CODE') expect(env.params['dimension']).to include('DATE', 'PRODUCT_CODE')
env.params['metric'].should include('CLICKS', 'PAGE_VIEWS') expect(env.params['metric']).to include('CLICKS', 'PAGE_VIEWS')
[200, {}, '{}'] [200, {}, '{}']
end end
end end
@ -634,19 +634,19 @@ describe Google::APIClient do
end end
it 'should include media upload info methods' do 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 end
it 'should include accepted media types' do 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 end
it 'should have an upload path' do 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 end
it 'should have a max file size' do 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 end
end end

View File

@ -33,7 +33,7 @@ describe Google::APIClient::Gzip do
[200, {}, 'Hello world'] [200, {}, 'Hello world']
end end
result = conn.get('/') result = conn.get('/')
result.body.should == "Hello world" expect(result.body).to eq("Hello world")
end end
it 'should decompress gziped content' do it 'should decompress gziped content' do
@ -41,7 +41,7 @@ describe Google::APIClient::Gzip do
[200, { 'Content-Encoding' => 'gzip'}, Base64.decode64('H4sICLVGwlEAA3RtcADzSM3JyVcozy/KSeECANXgObcMAAAA')] [200, { 'Content-Encoding' => 'gzip'}, Base64.decode64('H4sICLVGwlEAA3RtcADzSM3JyVcozy/KSeECANXgObcMAAAA')]
end end
result = conn.get('/') result = conn.get('/')
result.body.should == "Hello world\n" expect(result.body).to eq("Hello world\n")
end end
describe 'with API Client' do describe 'with API Client' do
@ -55,8 +55,8 @@ describe Google::APIClient::Gzip do
it 'should send gzip in user agent' do it 'should send gzip in user agent' do
conn = create_connection do |env| conn = create_connection do |env|
agent = env[:request_headers]['User-Agent'] agent = env[:request_headers]['User-Agent']
agent.should_not be_nil expect(agent).not_to be_nil
agent.should include 'gzip' expect(agent).to include 'gzip'
[200, {}, 'Hello world'] [200, {}, 'Hello world']
end end
@client.execute(:uri => 'http://www.example.com/', :connection => conn) @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 it 'should send gzip in accept-encoding' do
conn = create_connection do |env| conn = create_connection do |env|
encoding = env[:request_headers]['Accept-Encoding'] encoding = env[:request_headers]['Accept-Encoding']
encoding.should_not be_nil expect(encoding).not_to be_nil
encoding.should include 'gzip' expect(encoding).to include 'gzip'
[200, {}, 'Hello world'] [200, {}, 'Hello world']
end end
@client.execute(:uri => 'http://www.example.com/', :connection => conn) @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 it 'should not send gzip in accept-encoding if disabled for request' do
conn = create_connection do |env| conn = create_connection do |env|
encoding = env[:request_headers]['Accept-Encoding'] 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'] [200, {}, 'Hello world']
end end
response = @client.execute(:uri => 'http://www.example.com/', :gzip => false, :connection => conn) response = @client.execute(:uri => 'http://www.example.com/', :gzip => false, :connection => conn)

View File

@ -21,9 +21,9 @@ fixtures_path = File.expand_path('../../../fixtures', __FILE__)
describe Google::APIClient::UploadIO do describe Google::APIClient::UploadIO do
it 'should reject invalid file paths' do it 'should reject invalid file paths' do
(lambda do expect(lambda do
media = Google::APIClient::UploadIO.new('doesnotexist', 'text/plain') media = Google::APIClient::UploadIO.new('doesnotexist', 'text/plain')
end).should raise_error end).to raise_error
end end
describe 'with a file' do describe 'with a file' do
@ -33,11 +33,11 @@ describe Google::APIClient::UploadIO do
end end
it 'should report the correct file length' do it 'should report the correct file length' do
@media.length.should == File.size(@file) expect(@media.length).to eq(File.size(@file))
end end
it 'should have a mime type' do it 'should have a mime type' do
@media.content_type.should == 'text/plain' expect(@media.content_type).to eq('text/plain')
end end
end end
@ -48,11 +48,11 @@ describe Google::APIClient::UploadIO do
end end
it 'should report the correct file length' do it 'should report the correct file length' do
@media.length.should == @content.length expect(@media.length).to eq(@content.length)
end end
it 'should have a mime type' do it 'should have a mime type' do
@media.content_type.should == 'text/plain' expect(@media.content_type).to eq('text/plain')
end end
end end
end end
@ -64,43 +64,43 @@ describe Google::APIClient::RangedIO do
end end
it 'should return the correct range when read entirely' do it 'should return the correct range when read entirely' do
@io.read.should == "23456" expect(@io.read).to eq("23456")
end end
it 'should maintain position' do it 'should maintain position' do
@io.read(1).should == '2' expect(@io.read(1)).to eq('2')
@io.read(2).should == '34' expect(@io.read(2)).to eq('34')
@io.read(2).should == '56' expect(@io.read(2)).to eq('56')
end end
it 'should allow rewinds' do it 'should allow rewinds' do
@io.read(2).should == '23' expect(@io.read(2)).to eq('23')
@io.rewind() @io.rewind()
@io.read(2).should == '23' expect(@io.read(2)).to eq('23')
end end
it 'should allow setting position' do it 'should allow setting position' do
@io.pos = 3 @io.pos = 3
@io.read.should == '56' expect(@io.read).to eq('56')
end end
it 'should not allow position to be set beyond range' do it 'should not allow position to be set beyond range' do
@io.pos = 10 @io.pos = 10
@io.read.should == '' expect(@io.read).to eq('')
end end
it 'should return empty string when read amount is zero' do it 'should return empty string when read amount is zero' do
@io.read(0).should == '' expect(@io.read(0)).to eq('')
end end
it 'should return empty string at EOF if amount is nil' do it 'should return empty string at EOF if amount is nil' do
@io.read @io.read
@io.read.should == '' expect(@io.read).to eq('')
end end
it 'should return nil at EOF if amount is positive int' do it 'should return nil at EOF if amount is positive int' do
@io.read @io.read
@io.read(1).should == nil expect(@io.read(1)).to eq(nil)
end end
end end
@ -127,26 +127,26 @@ describe Google::APIClient::ResumableUpload do
it 'should consider 20x status as complete' do it 'should consider 20x status as complete' do
request = @uploader.to_http_request request = @uploader.to_http_request
@uploader.process_http_response(mock_result(200)) @uploader.process_http_response(mock_result(200))
@uploader.complete?.should == true expect(@uploader.complete?).to eq(true)
end end
it 'should consider 30x status as incomplete' do it 'should consider 30x status as incomplete' do
request = @uploader.to_http_request request = @uploader.to_http_request
@uploader.process_http_response(mock_result(308)) @uploader.process_http_response(mock_result(308))
@uploader.complete?.should == false expect(@uploader.complete?).to eq(false)
@uploader.expired?.should == false expect(@uploader.expired?).to eq(false)
end end
it 'should consider 40x status as fatal' do it 'should consider 40x status as fatal' do
request = @uploader.to_http_request request = @uploader.to_http_request
@uploader.process_http_response(mock_result(404)) @uploader.process_http_response(mock_result(404))
@uploader.expired?.should == true expect(@uploader.expired?).to eq(true)
end end
it 'should detect changes to location' do it 'should detect changes to location' do
request = @uploader.to_http_request request = @uploader.to_http_request
@uploader.process_http_response(mock_result(308, 'location' => 'https://www.googleapis.com/upload/drive/v1/files/abcdef')) @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 end
it 'should resume from the saved range reported by the server' do 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.to_http_request # Send bytes 0-199, only 0-99 saved
@uploader.process_http_response(mock_result(308, 'range' => '0-99')) @uploader.process_http_response(mock_result(308, 'range' => '0-99'))
method, url, headers, body = @uploader.to_http_request # Send bytes 100-299 method, url, headers, body = @uploader.to_http_request # Send bytes 100-299
headers['Content-Range'].should == "bytes 100-299/#{@media.length}" expect(headers['Content-Range']).to eq("bytes 100-299/#{@media.length}")
headers['Content-length'].should == "200" expect(headers['Content-length']).to eq("200")
end end
it 'should resync the offset after 5xx errors' do it 'should resync the offset after 5xx errors' do
@ -163,12 +163,12 @@ describe Google::APIClient::ResumableUpload do
@uploader.to_http_request @uploader.to_http_request
@uploader.process_http_response(mock_result(500)) # Invalidates range @uploader.process_http_response(mock_result(500)) # Invalidates range
method, url, headers, body = @uploader.to_http_request # Resync method, url, headers, body = @uploader.to_http_request # Resync
headers['Content-Range'].should == "bytes */#{@media.length}" expect(headers['Content-Range']).to eq("bytes */#{@media.length}")
headers['Content-length'].should == "0" expect(headers['Content-length']).to eq("0")
@uploader.process_http_response(mock_result(308, 'range' => '0-99')) @uploader.process_http_response(mock_result(308, 'range' => '0-99'))
method, url, headers, body = @uploader.to_http_request # Send next chunk at correct range method, url, headers, body = @uploader.to_http_request # Send next chunk at correct range
headers['Content-Range'].should == "bytes 100-299/#{@media.length}" expect(headers['Content-Range']).to eq("bytes 100-299/#{@media.length}")
headers['Content-length'].should == "200" expect(headers['Content-length']).to eq("200")
end end
def mock_result(status, headers = {}) def mock_result(status, headers = {})

View File

@ -24,7 +24,7 @@ describe Google::APIClient::Request do
request = Google::APIClient::Request.new(:uri => 'https://www.google.com', :parameters => { request = Google::APIClient::Request.new(:uri => 'https://www.google.com', :parameters => {
:a => '1', 'b' => '2' :a => '1', 'b' => '2'
}) })
request.parameters['a'].should == '1' expect(request.parameters['a']).to eq('1')
request.parameters['b'].should == '2' expect(request.parameters['b']).to eq('2')
end end
end end

View File

@ -36,8 +36,8 @@ describe Google::APIClient::Result do
# Response double # Response double
@response = double("response") @response = double("response")
@response.stub(:status).and_return(200) allow(@response).to receive(:status).and_return(200)
@response.stub(:headers).and_return({ allow(@response).to receive(:headers).and_return({
'etag' => '12345', 'etag' => '12345',
'x-google-apiary-auth-scopes' => 'x-google-apiary-auth-scopes' =>
'https://www.googleapis.com/auth/plus.me', 'https://www.googleapis.com/auth/plus.me',
@ -51,7 +51,7 @@ describe Google::APIClient::Result do
describe 'with a next page token' do describe 'with a next page token' do
before do before do
@response.stub(:body).and_return( allow(@response).to receive(:body).and_return(
<<-END_OF_STRING <<-END_OF_STRING
{ {
"kind": "plus#activityFeed", "kind": "plus#activityFeed",
@ -70,46 +70,49 @@ describe Google::APIClient::Result do
end end
it 'should indicate a successful response' do it 'should indicate a successful response' do
@result.error?.should be_false expect(@result.error?).to be_falsey
end end
it 'should return the correct next page token' do 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 end
it 'should escape the next page token when calling next_page' do it 'should escape the next page token when calling next_page' do
reference = @result.next_page reference = @result.next_page
Hash[reference.parameters].should include('pageToken') expect(Hash[reference.parameters]).to include('pageToken')
Hash[reference.parameters]['pageToken'].should == 'NEXT+PAGE+TOKEN' expect(Hash[reference.parameters]['pageToken']).to eq('NEXT+PAGE+TOKEN')
url = reference.to_env(CLIENT.connection)[:url] 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 end
it 'should return content type correctly' do it 'should return content type correctly' do
@result.media_type.should == 'application/json' expect(@result.media_type).to eq('application/json')
end end
it 'should return the result data correctly' do it 'should return the result data correctly' do
@result.data?.should be_true expect(@result.data?).to be_truthy
@result.data.class.to_s.should == expect(@result.data.class.to_s).to eq(
'Google::APIClient::Schema::Plus::V1::ActivityFeed' 'Google::APIClient::Schema::Plus::V1::ActivityFeed'
@result.data.kind.should == 'plus#activityFeed' )
@result.data.etag.should == 'FOO' expect(@result.data.kind).to eq('plus#activityFeed')
@result.data.nextPageToken.should == 'NEXT+PAGE+TOKEN' expect(@result.data.etag).to eq('FOO')
@result.data.selfLink.should == 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?' '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?' + 'https://www.googleapis.com/plus/v1/people/foo/activities/public?' +
'maxResults=20&pageToken=NEXT%2BPAGE%2BTOKEN' 'maxResults=20&pageToken=NEXT%2BPAGE%2BTOKEN'
@result.data.title.should == 'Plus Public Activity Feed for ' )
@result.data.id.should == "123456790" expect(@result.data.title).to eq('Plus Public Activity Feed for ')
@result.data.items.should be_empty expect(@result.data.id).to eq("123456790")
expect(@result.data.items).to be_empty
end end
end end
describe 'without a next page token' do describe 'without a next page token' do
before do before do
@response.stub(:body).and_return( allow(@response).to receive(:body).and_return(
<<-END_OF_STRING <<-END_OF_STRING
{ {
"kind": "plus#activityFeed", "kind": "plus#activityFeed",
@ -126,30 +129,32 @@ describe Google::APIClient::Result do
end end
it 'should not return a next page token' do it 'should not return a next page token' do
@result.next_page_token.should == nil expect(@result.next_page_token).to eq(nil)
end end
it 'should return content type correctly' do it 'should return content type correctly' do
@result.media_type.should == 'application/json' expect(@result.media_type).to eq('application/json')
end end
it 'should return the result data correctly' do it 'should return the result data correctly' do
@result.data?.should be_true expect(@result.data?).to be_truthy
@result.data.class.to_s.should == expect(@result.data.class.to_s).to eq(
'Google::APIClient::Schema::Plus::V1::ActivityFeed' 'Google::APIClient::Schema::Plus::V1::ActivityFeed'
@result.data.kind.should == 'plus#activityFeed' )
@result.data.etag.should == 'FOO' expect(@result.data.kind).to eq('plus#activityFeed')
@result.data.selfLink.should == expect(@result.data.etag).to eq('FOO')
expect(@result.data.selfLink).to eq(
'https://www.googleapis.com/plus/v1/people/foo/activities/public?' 'https://www.googleapis.com/plus/v1/people/foo/activities/public?'
@result.data.title.should == 'Plus Public Activity Feed for ' )
@result.data.id.should == "123456790" expect(@result.data.title).to eq('Plus Public Activity Feed for ')
@result.data.items.should be_empty expect(@result.data.id).to eq("123456790")
expect(@result.data.items).to be_empty
end end
end end
describe 'with JSON error response' do describe 'with JSON error response' do
before do before do
@response.stub(:body).and_return( allow(@response).to receive(:body).and_return(
<<-END_OF_STRING <<-END_OF_STRING
{ {
"error": { "error": {
@ -166,37 +171,37 @@ describe Google::APIClient::Result do
} }
END_OF_STRING END_OF_STRING
) )
@response.stub(:status).and_return(400) allow(@response).to receive(:status).and_return(400)
@result = Google::APIClient::Result.new(@reference, @response) @result = Google::APIClient::Result.new(@reference, @response)
end end
it 'should return error status correctly' do it 'should return error status correctly' do
@result.error?.should be_true expect(@result.error?).to be_truthy
end end
it 'should return the correct error message' do it 'should return the correct error message' do
@result.error_message.should == 'Parse Error' expect(@result.error_message).to eq('Parse Error')
end end
end end
describe 'with 204 No Content response' do describe 'with 204 No Content response' do
before do before do
@response.stub(:body).and_return('') allow(@response).to receive(:body).and_return('')
@response.stub(:status).and_return(204) allow(@response).to receive(:status).and_return(204)
@response.stub(:headers).and_return({}) allow(@response).to receive(:headers).and_return({})
@result = Google::APIClient::Result.new(@reference, @response) @result = Google::APIClient::Result.new(@reference, @response)
end end
it 'should indicate no data is available' do it 'should indicate no data is available' do
@result.data?.should be_false expect(@result.data?).to be_falsey
end end
it 'should return nil for data' do it 'should return nil for data' do
@result.data.should == nil expect(@result.data).to eq(nil)
end end
it 'should return nil for media_type' do it 'should return nil for media_type' do
@result.media_type.should == nil expect(@result.media_type).to eq(nil)
end end
end end
end end

View File

@ -23,7 +23,7 @@ describe Google::APIClient::KeyUtils do
pending "Reading from PKCS12 not supported on jruby" if RUBY_PLATFORM == 'java' pending "Reading from PKCS12 not supported on jruby" if RUBY_PLATFORM == 'java'
path = File.expand_path('files/privatekey.p12', fixtures_path) path = File.expand_path('files/privatekey.p12', fixtures_path)
key = Google::APIClient::KeyUtils.load_from_pkcs12(path, 'notasecret') key = Google::APIClient::KeyUtils.load_from_pkcs12(path, 'notasecret')
key.should_not == nil expect(key).not_to eq(nil)
end end
it 'should read PKCS12 files from loaded files' do 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) path = File.expand_path('files/privatekey.p12', fixtures_path)
content = File.read(path) content = File.read(path)
key = Google::APIClient::KeyUtils.load_from_pkcs12(content, 'notasecret') key = Google::APIClient::KeyUtils.load_from_pkcs12(content, 'notasecret')
key.should_not == nil expect(key).not_to eq(nil)
end end
it 'should read PEM files from the filesystem' do it 'should read PEM files from the filesystem' do
path = File.expand_path('files/secret.pem', fixtures_path) path = File.expand_path('files/secret.pem', fixtures_path)
key = Google::APIClient::KeyUtils.load_from_pem(path, 'notasecret') key = Google::APIClient::KeyUtils.load_from_pem(path, 'notasecret')
key.should_not == nil expect(key).not_to eq(nil)
end end
it 'should read PEM files from loaded files' do it 'should read PEM files from loaded files' do
path = File.expand_path('files/secret.pem', fixtures_path) path = File.expand_path('files/secret.pem', fixtures_path)
content = File.read(path) content = File.read(path)
key = Google::APIClient::KeyUtils.load_from_pem(content, 'notasecret') key = Google::APIClient::KeyUtils.load_from_pem(content, 'notasecret')
key.should_not == nil expect(key).not_to eq(nil)
end end
end end
@ -59,11 +59,12 @@ describe Google::APIClient::JWTAsserter do
it 'should generate valid JWTs' do it 'should generate valid JWTs' do
asserter = Google::APIClient::JWTAsserter.new('client1', 'scope1 scope2', @key) asserter = Google::APIClient::JWTAsserter.new('client1', 'scope1 scope2', @key)
jwt = asserter.to_authorization.to_jwt 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 = JWT.decode(jwt, @key.public_key, true)
claim["iss"].should == 'client1' claim = claim.first if claim.respond_to? :first
claim["scope"].should == 'scope1 scope2' expect(claim["iss"]).to eq('client1')
expect(claim["scope"]).to eq('scope1 scope2')
end end
it 'should allow impersonation' do it 'should allow impersonation' do
@ -71,7 +72,7 @@ describe Google::APIClient::JWTAsserter do
stub.post('/o/oauth2/token') do |env| stub.post('/o/oauth2/token') do |env|
params = Addressable::URI.form_unencode(env[:body]) params = Addressable::URI.form_unencode(env[:body])
JWT.decode(params.assoc("assertion").last, @key.public_key) 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, {}, '{ [200, {}, '{
"access_token" : "1/abcdef1234567890", "access_token" : "1/abcdef1234567890",
"token_type" : "Bearer", "token_type" : "Bearer",
@ -81,8 +82,8 @@ describe Google::APIClient::JWTAsserter do
end end
asserter = Google::APIClient::JWTAsserter.new('client1', 'scope1 scope2', @key) asserter = Google::APIClient::JWTAsserter.new('client1', 'scope1 scope2', @key)
auth = asserter.authorize('user1@email.com', { :connection => conn }) auth = asserter.authorize('user1@email.com', { :connection => conn })
auth.should_not == nil? expect(auth).not_to eq(nil?)
auth.person.should == 'user1@email.com' expect(auth.person).to eq('user1@email.com')
conn.verify conn.verify
end end
@ -91,7 +92,7 @@ describe Google::APIClient::JWTAsserter do
stub.post('/o/oauth2/token') do |env| stub.post('/o/oauth2/token') do |env|
params = Addressable::URI.form_unencode(env[:body]) params = Addressable::URI.form_unencode(env[:body])
JWT.decode(params.assoc("assertion").last, @key.public_key) 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, {}, '{ [200, {}, '{
"access_token" : "1/abcdef1234567890", "access_token" : "1/abcdef1234567890",
"token_type" : "Bearer", "token_type" : "Bearer",
@ -101,8 +102,8 @@ describe Google::APIClient::JWTAsserter do
end end
asserter = Google::APIClient::JWTAsserter.new('client1', 'scope1 scope2', @key) asserter = Google::APIClient::JWTAsserter.new('client1', 'scope1 scope2', @key)
auth = asserter.authorize(nil, { :connection => conn }) auth = asserter.authorize(nil, { :connection => conn })
auth.should_not == nil? expect(auth).not_to eq(nil?)
auth.access_token.should == "1/abcdef1234567890" expect(auth.access_token).to eq("1/abcdef1234567890")
conn.verify conn.verify
end end
@ -111,7 +112,7 @@ describe Google::APIClient::JWTAsserter do
stub.post('/o/oauth2/token') do |env| stub.post('/o/oauth2/token') do |env|
params = Addressable::URI.form_unencode(env[:body]) params = Addressable::URI.form_unencode(env[:body])
JWT.decode(params.assoc("assertion").last, @key.public_key) 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, {}, '{ [200, {}, '{
"access_token" : "1/abcdef1234567890", "access_token" : "1/abcdef1234567890",
"token_type" : "Bearer", "token_type" : "Bearer",
@ -121,7 +122,7 @@ describe Google::APIClient::JWTAsserter do
stub.post('/o/oauth2/token') do |env| stub.post('/o/oauth2/token') do |env|
params = Addressable::URI.form_unencode(env[:body]) params = Addressable::URI.form_unencode(env[:body])
JWT.decode(params.assoc("assertion").last, @key.public_key) 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, {}, '{ [200, {}, '{
"access_token" : "1/0987654321fedcba", "access_token" : "1/0987654321fedcba",
"token_type" : "Bearer", "token_type" : "Bearer",
@ -131,11 +132,11 @@ describe Google::APIClient::JWTAsserter do
end end
asserter = Google::APIClient::JWTAsserter.new('client1', 'scope1 scope2', @key) asserter = Google::APIClient::JWTAsserter.new('client1', 'scope1 scope2', @key)
auth = asserter.authorize(nil, { :connection => conn }) auth = asserter.authorize(nil, { :connection => conn })
auth.should_not == nil? expect(auth).not_to eq(nil?)
auth.access_token.should == "1/abcdef1234567890" expect(auth.access_token).to eq("1/abcdef1234567890")
auth.fetch_access_token!(:connection => conn) auth.fetch_access_token!(:connection => conn)
auth.access_token.should == "1/0987654321fedcba" expect(auth.access_token).to eq("1/0987654321fedcba")
conn.verify conn.verify
end end
@ -147,7 +148,7 @@ describe Google::APIClient::ComputeServiceAccount do
it 'should query metadata server' do it 'should query metadata server' do
conn = stub_connection do |stub| conn = stub_connection do |stub|
stub.get('/computeMetadata/v1beta1/instance/service-accounts/default/token') do |env| stub.get('/computeMetadata/v1beta1/instance/service-accounts/default/token') do |env|
env.url.host.should == 'metadata' expect(env.url.host).to eq('metadata')
[200, {}, '{ [200, {}, '{
"access_token" : "1/abcdef1234567890", "access_token" : "1/abcdef1234567890",
"token_type" : "Bearer", "token_type" : "Bearer",
@ -157,8 +158,8 @@ describe Google::APIClient::ComputeServiceAccount do
end end
service_account = Google::APIClient::ComputeServiceAccount.new service_account = Google::APIClient::ComputeServiceAccount.new
auth = service_account.fetch_access_token!({ :connection => conn }) auth = service_account.fetch_access_token!({ :connection => conn })
auth.should_not == nil? expect(auth).not_to eq(nil?)
auth["access_token"].should == "1/abcdef1234567890" expect(auth["access_token"]).to eq("1/abcdef1234567890")
conn.verify conn.verify
end end
end end

View File

@ -27,21 +27,21 @@ describe Google::APIClient::Service do
APPLICATION_NAME = 'API Client Tests' APPLICATION_NAME = 'API Client Tests'
it 'should error out when called without an API name or version' do it 'should error out when called without an API name or version' do
(lambda do expect(lambda do
Google::APIClient::Service.new Google::APIClient::Service.new
end).should raise_error(ArgumentError) end).to raise_error(ArgumentError)
end end
it 'should error out when called without an API version' do it 'should error out when called without an API version' do
(lambda do expect(lambda do
Google::APIClient::Service.new('foo') Google::APIClient::Service.new('foo')
end).should raise_error(ArgumentError) end).to raise_error(ArgumentError)
end end
it 'should error out when the options hash is not a hash' do 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) Google::APIClient::Service.new('foo', 'v1', 42)
end).should raise_error(ArgumentError) end).to raise_error(ArgumentError)
end end
describe 'with the AdSense Management API' do describe 'with the AdSense Management API' do
@ -112,34 +112,34 @@ describe Google::APIClient::Service do
end end
it 'should return a resource when using a valid resource name' do 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 end
it 'should throw an error when using an invalid resource name' do it 'should throw an error when using an invalid resource name' do
(lambda do expect(lambda do
@adsense.invalid_resource @adsense.invalid_resource
end).should raise_error end).to raise_error
end end
it 'should return a request when using a valid method name' do it 'should return a request when using a valid method name' do
req = @adsense.adclients.list req = @adsense.adclients.list
req.should be_a(Google::APIClient::Service::Request) expect(req).to be_a(Google::APIClient::Service::Request)
req.method.id.should == 'adsense.adclients.list' expect(req.method.id).to eq('adsense.adclients.list')
req.parameters.should be_nil expect(req.parameters).to be_nil
end end
it 'should throw an error when using an invalid method name' do it 'should throw an error when using an invalid method name' do
(lambda do expect(lambda do
@adsense.adclients.invalid_method @adsense.adclients.invalid_method
end).should raise_error end).to raise_error
end end
it 'should return a valid request with parameters' do it 'should return a valid request with parameters' do
req = @adsense.adunits.list(:adClientId => '1') req = @adsense.adunits.list(:adClientId => '1')
req.should be_a(Google::APIClient::Service::Request) expect(req).to be_a(Google::APIClient::Service::Request)
req.method.id.should == 'adsense.adunits.list' expect(req.method.id).to eq('adsense.adunits.list')
req.parameters.should_not be_nil expect(req.parameters).not_to be_nil
req.parameters[:adClientId].should == '1' expect(req.parameters[:adClientId]).to eq('1')
end end
end end
end end
@ -149,7 +149,7 @@ describe Google::APIClient::Service do
it 'should make a valid call with an object body' do it 'should make a valid call with an object body' do
conn = stub_connection do |stub| conn = stub_connection do |stub|
stub.post('/prediction/v1.5/trainedmodels?project=1') do |env| stub.post('/prediction/v1.5/trainedmodels?project=1') do |env|
env.body.should == '{"id":"1"}' expect(env.body).to eq('{"id":"1"}')
[200, {}, '{}'] [200, {}, '{}']
end end
end end
@ -170,7 +170,7 @@ describe Google::APIClient::Service do
it 'should make a valid call with a text body' do it 'should make a valid call with a text body' do
conn = stub_connection do |stub| conn = stub_connection do |stub|
stub.post('/prediction/v1.5/trainedmodels?project=1') do |env| stub.post('/prediction/v1.5/trainedmodels?project=1') do |env|
env.body.should == '{"id":"1"}' expect(env.body).to eq('{"id":"1"}')
[200, {}, '{}'] [200, {}, '{}']
end end
end end
@ -196,20 +196,20 @@ describe Google::APIClient::Service do
it 'should return a valid request with a body' do it 'should return a valid request with a body' do
req = @prediction.trainedmodels.insert(:project => '1').body({'id' => '1'}) req = @prediction.trainedmodels.insert(:project => '1').body({'id' => '1'})
req.should be_a(Google::APIClient::Service::Request) expect(req).to be_a(Google::APIClient::Service::Request)
req.method.id.should == 'prediction.trainedmodels.insert' expect(req.method.id).to eq('prediction.trainedmodels.insert')
req.body.should == {'id' => '1'} expect(req.body).to eq({'id' => '1'})
req.parameters.should_not be_nil expect(req.parameters).not_to be_nil
req.parameters[:project].should == '1' expect(req.parameters[:project]).to eq('1')
end end
it 'should return a valid request with a body when using resource name' do it 'should return a valid request with a body when using resource name' do
req = @prediction.trainedmodels.insert(:project => '1').training({'id' => '1'}) req = @prediction.trainedmodels.insert(:project => '1').training({'id' => '1'})
req.should be_a(Google::APIClient::Service::Request) expect(req).to be_a(Google::APIClient::Service::Request)
req.method.id.should == 'prediction.trainedmodels.insert' expect(req.method.id).to eq('prediction.trainedmodels.insert')
req.training.should == {'id' => '1'} expect(req.training).to eq({'id' => '1'})
req.parameters.should_not be_nil expect(req.parameters).not_to be_nil
req.parameters[:project].should == '1' expect(req.parameters[:project]).to eq('1')
end end
end 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 it 'should make a valid call with an object body and media upload' do
conn = stub_connection do |stub| conn = stub_connection do |stub|
stub.post('/upload/drive/v1/files?uploadType=multipart') do |env| 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, {}, '{}'] [200, {}, '{}']
end end
end end
@ -254,22 +254,22 @@ describe Google::APIClient::Service do
it 'should return a valid request with a body and media upload' 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 = @drive.files.insert(:uploadType => 'multipart').body(@metadata).media(@media)
req.should be_a(Google::APIClient::Service::Request) expect(req).to be_a(Google::APIClient::Service::Request)
req.method.id.should == 'drive.files.insert' expect(req.method.id).to eq('drive.files.insert')
req.body.should == @metadata expect(req.body).to eq(@metadata)
req.media.should == @media expect(req.media).to eq(@media)
req.parameters.should_not be_nil expect(req.parameters).not_to be_nil
req.parameters[:uploadType].should == 'multipart' expect(req.parameters[:uploadType]).to eq('multipart')
end end
it 'should return a valid request with a body and media upload when using resource name' do 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 = @drive.files.insert(:uploadType => 'multipart').file(@metadata).media(@media)
req.should be_a(Google::APIClient::Service::Request) expect(req).to be_a(Google::APIClient::Service::Request)
req.method.id.should == 'drive.files.insert' expect(req.method.id).to eq('drive.files.insert')
req.file.should == @metadata expect(req.file).to eq(@metadata)
req.media.should == @media expect(req.media).to eq(@media)
req.parameters.should_not be_nil expect(req.parameters).not_to be_nil
req.parameters[:uploadType].should == 'multipart' expect(req.parameters[:uploadType]).to eq('multipart')
end end
end end
end end
@ -280,9 +280,9 @@ describe Google::APIClient::Service do
{:application_name => APPLICATION_NAME, :authenticated => false, {:application_name => APPLICATION_NAME, :authenticated => false,
:cache_store => nil}) :cache_store => nil})
result = discovery.apis.get_rest(:api => 'discovery', :version => 'v1').execute result = discovery.apis.get_rest(:api => 'discovery', :version => 'v1').execute
result.should_not be_nil expect(result).not_to be_nil
result.data.name.should == 'discovery' expect(result.data.name).to eq('discovery')
result.data.version.should == 'v1' expect(result.data.version).to eq('v1')
end end
end end
end end
@ -307,8 +307,8 @@ describe Google::APIClient::Service::Result do
# Response double # Response double
@response = double("response") @response = double("response")
@response.stub(:status).and_return(200) allow(@response).to receive(:status).and_return(200)
@response.stub(:headers).and_return({ allow(@response).to receive(:headers).and_return({
'etag' => '12345', 'etag' => '12345',
'x-google-apiary-auth-scopes' => 'x-google-apiary-auth-scopes' =>
'https://www.googleapis.com/auth/plus.me', 'https://www.googleapis.com/auth/plus.me',
@ -335,51 +335,54 @@ describe Google::APIClient::Service::Result do
"items": [] "items": []
} }
END_OF_STRING 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) base_result = Google::APIClient::Result.new(@reference, @response)
@result = Google::APIClient::Service::Result.new(@request, base_result) @result = Google::APIClient::Service::Result.new(@request, base_result)
end end
it 'should indicate a successful response' do it 'should indicate a successful response' do
@result.error?.should be_false expect(@result.error?).to be_falsey
end end
it 'should return the correct next page token' do 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 end
it 'generate a correct request when calling next_page' do it 'generate a correct request when calling next_page' do
next_page_request = @result.next_page next_page_request = @result.next_page
next_page_request.parameters.should include('pageToken') expect(next_page_request.parameters).to include('pageToken')
next_page_request.parameters['pageToken'].should == 'NEXT+PAGE+TOKEN' expect(next_page_request.parameters['pageToken']).to eq('NEXT+PAGE+TOKEN')
@request.parameters.each_pair do |param, value| @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
end end
it 'should return content type correctly' do it 'should return content type correctly' do
@result.media_type.should == 'application/json' expect(@result.media_type).to eq('application/json')
end end
it 'should return the body correctly' do it 'should return the body correctly' do
@result.body.should == @body expect(@result.body).to eq(@body)
end end
it 'should return the result data correctly' do it 'should return the result data correctly' do
@result.data?.should be_true expect(@result.data?).to be_truthy
@result.data.class.to_s.should == expect(@result.data.class.to_s).to eq(
'Google::APIClient::Schema::Plus::V1::ActivityFeed' 'Google::APIClient::Schema::Plus::V1::ActivityFeed'
@result.data.kind.should == 'plus#activityFeed' )
@result.data.etag.should == 'FOO' expect(@result.data.kind).to eq('plus#activityFeed')
@result.data.nextPageToken.should == 'NEXT+PAGE+TOKEN' expect(@result.data.etag).to eq('FOO')
@result.data.selfLink.should == 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?' '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?' + 'https://www.googleapis.com/plus/v1/people/foo/activities/public?' +
'maxResults=20&pageToken=NEXT%2BPAGE%2BTOKEN' 'maxResults=20&pageToken=NEXT%2BPAGE%2BTOKEN'
@result.data.title.should == 'Plus Public Activity Feed for ' )
@result.data.id.should == "123456790" expect(@result.data.title).to eq('Plus Public Activity Feed for ')
@result.data.items.should be_empty expect(@result.data.id).to eq("123456790")
expect(@result.data.items).to be_empty
end end
end end
@ -396,34 +399,36 @@ describe Google::APIClient::Service::Result do
"items": [] "items": []
} }
END_OF_STRING 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) base_result = Google::APIClient::Result.new(@reference, @response)
@result = Google::APIClient::Service::Result.new(@request, base_result) @result = Google::APIClient::Service::Result.new(@request, base_result)
end end
it 'should not return a next page token' do it 'should not return a next page token' do
@result.next_page_token.should == nil expect(@result.next_page_token).to eq(nil)
end end
it 'should return content type correctly' do it 'should return content type correctly' do
@result.media_type.should == 'application/json' expect(@result.media_type).to eq('application/json')
end end
it 'should return the body correctly' do it 'should return the body correctly' do
@result.body.should == @body expect(@result.body).to eq(@body)
end end
it 'should return the result data correctly' do it 'should return the result data correctly' do
@result.data?.should be_true expect(@result.data?).to be_truthy
@result.data.class.to_s.should == expect(@result.data.class.to_s).to eq(
'Google::APIClient::Schema::Plus::V1::ActivityFeed' 'Google::APIClient::Schema::Plus::V1::ActivityFeed'
@result.data.kind.should == 'plus#activityFeed' )
@result.data.etag.should == 'FOO' expect(@result.data.kind).to eq('plus#activityFeed')
@result.data.selfLink.should == expect(@result.data.etag).to eq('FOO')
expect(@result.data.selfLink).to eq(
'https://www.googleapis.com/plus/v1/people/foo/activities/public?' 'https://www.googleapis.com/plus/v1/people/foo/activities/public?'
@result.data.title.should == 'Plus Public Activity Feed for ' )
@result.data.id.should == "123456790" expect(@result.data.title).to eq('Plus Public Activity Feed for ')
@result.data.items.should be_empty expect(@result.data.id).to eq("123456790")
expect(@result.data.items).to be_empty
end end
end end
@ -444,44 +449,44 @@ describe Google::APIClient::Service::Result do
} }
} }
END_OF_STRING END_OF_STRING
@response.stub(:body).and_return(@body) allow(@response).to receive(:body).and_return(@body)
@response.stub(:status).and_return(400) allow(@response).to receive(:status).and_return(400)
base_result = Google::APIClient::Result.new(@reference, @response) base_result = Google::APIClient::Result.new(@reference, @response)
@result = Google::APIClient::Service::Result.new(@request, base_result) @result = Google::APIClient::Service::Result.new(@request, base_result)
end end
it 'should return error status correctly' do it 'should return error status correctly' do
@result.error?.should be_true expect(@result.error?).to be_truthy
end end
it 'should return the correct error message' do it 'should return the correct error message' do
@result.error_message.should == 'Parse Error' expect(@result.error_message).to eq('Parse Error')
end end
it 'should return the body correctly' do it 'should return the body correctly' do
@result.body.should == @body expect(@result.body).to eq(@body)
end end
end end
describe 'with 204 No Content response' do describe 'with 204 No Content response' do
before do before do
@response.stub(:body).and_return('') allow(@response).to receive(:body).and_return('')
@response.stub(:status).and_return(204) allow(@response).to receive(:status).and_return(204)
@response.stub(:headers).and_return({}) allow(@response).to receive(:headers).and_return({})
base_result = Google::APIClient::Result.new(@reference, @response) base_result = Google::APIClient::Result.new(@reference, @response)
@result = Google::APIClient::Service::Result.new(@request, base_result) @result = Google::APIClient::Service::Result.new(@request, base_result)
end end
it 'should indicate no data is available' do it 'should indicate no data is available' do
@result.data?.should be_false expect(@result.data?).to be_falsey
end end
it 'should return nil for data' do it 'should return nil for data' do
@result.data.should == nil expect(@result.data).to eq(nil)
end end
it 'should return nil for media_type' do it 'should return nil for media_type' do
@result.media_type.should == nil expect(@result.media_type).to eq(nil)
end end
end end
end end
@ -507,11 +512,11 @@ describe Google::APIClient::Service::BatchRequest do
block_called = 0 block_called = 0
batch = @discovery.batch(@calls) do |result| batch = @discovery.batch(@calls) do |result|
block_called += 1 block_called += 1
result.status.should == 200 expect(result.status).to eq(200)
end end
batch.execute batch.execute
block_called.should == 2 expect(block_called).to eq(2)
end end
it 'should execute both when using individual callbacks' do 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| batch.add(@calls[0]) do |result|
call1_returned = true call1_returned = true
result.status.should == 200 expect(result.status).to eq(200)
result.call_index.should == 0 expect(result.call_index).to eq(0)
end end
batch.add(@calls[1]) do |result| batch.add(@calls[1]) do |result|
call2_returned = true call2_returned = true
result.status.should == 200 expect(result.status).to eq(200)
result.call_index.should == 1 expect(result.call_index).to eq(1)
end end
batch.execute batch.execute
call1_returned.should == true expect(call1_returned).to eq(true)
call2_returned.should == true expect(call2_returned).to eq(true)
end end
end end
@ -549,15 +554,15 @@ describe Google::APIClient::Service::BatchRequest do
batch = @discovery.batch(@calls) do |result| batch = @discovery.batch(@calls) do |result|
block_called += 1 block_called += 1
if result.call_index == 0 if result.call_index == 0
result.status.should == 200 expect(result.status).to eq(200)
else else
result.status.should >= 400 expect(result.status).to be >= 400
result.status.should < 500 expect(result.status).to be < 500
end end
end end
batch.execute batch.execute
block_called.should == 2 expect(block_called).to eq(2)
end end
it 'should execute both when using individual callbacks' do 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| batch.add(@calls[0]) do |result|
call1_returned = true call1_returned = true
result.status.should == 200 expect(result.status).to eq(200)
result.call_index.should == 0 expect(result.call_index).to eq(0)
end end
batch.add(@calls[1]) do |result| batch.add(@calls[1]) do |result|
call2_returned = true call2_returned = true
result.status.should >= 400 expect(result.status).to be >= 400
result.status.should < 500 expect(result.status).to be < 500
result.call_index.should == 1 expect(result.call_index).to eq(1)
end end
batch.execute batch.execute
call1_returned.should == true expect(call1_returned).to eq(true)
call2_returned.should == true expect(call2_returned).to eq(true)
end end
end end
end end

View File

@ -33,35 +33,35 @@ describe Google::APIClient::Service::SimpleFileStore do
end end
it 'should return nil when asked if a key exists' do it 'should return nil when asked if a key exists' do
@cache.exist?('invalid').should be_nil expect(@cache.exist?('invalid')).to be_nil
File.exists?(FILE_NAME).should be_false expect(File.exists?(FILE_NAME)).to be_falsey
end end
it 'should return nil when asked to read a key' do it 'should return nil when asked to read a key' do
@cache.read('invalid').should be_nil expect(@cache.read('invalid')).to be_nil
File.exists?(FILE_NAME).should be_false expect(File.exists?(FILE_NAME)).to be_falsey
end end
it 'should return nil when asked to fetch a key' do it 'should return nil when asked to fetch a key' do
@cache.fetch('invalid').should be_nil expect(@cache.fetch('invalid')).to be_nil
File.exists?(FILE_NAME).should be_false expect(File.exists?(FILE_NAME)).to be_falsey
end end
it 'should create a cache file when asked to fetch a key with a default' do 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' 'value'
end.should == 'value' end).to eq('value')
File.exists?(FILE_NAME).should be_true expect(File.exists?(FILE_NAME)).to be_truthy
end end
it 'should create a cache file when asked to write a key' do it 'should create a cache file when asked to write a key' do
@cache.write('new_key', 'value') @cache.write('new_key', 'value')
File.exists?(FILE_NAME).should be_true expect(File.exists?(FILE_NAME)).to be_truthy
end end
it 'should return nil when asked to delete a key' do it 'should return nil when asked to delete a key' do
@cache.delete('invalid').should be_nil expect(@cache.delete('invalid')).to be_nil
File.exists?(FILE_NAME).should be_false expect(File.exists?(FILE_NAME)).to be_falsey
end end
end end
@ -73,61 +73,61 @@ describe Google::APIClient::Service::SimpleFileStore do
end end
it 'should return true when asked if an existing key exists' do 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 end
it 'should return false when asked if a nonexistent key exists' do 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 end
it 'should return the value for an existing key when asked to read it' do 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 end
it 'should return nil for a nonexistent key when asked to read it' do 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 end
it 'should return the value for an existing key when asked to read it' do 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 end
it 'should return nil for a nonexistent key when asked to fetch it' do 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 end
it 'should return and save the default value for a nonexistent key when asked to fetch it with a default' do 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' 'value'
end.should == 'value' end).to eq('value')
@cache.read('new_key').should == 'value' expect(@cache.read('new_key')).to eq('value')
end end
it 'should remove an existing value and return true when asked to delete it' do it 'should remove an existing value and return true when asked to delete it' do
@cache.delete('existing_key').should be_true expect(@cache.delete('existing_key')).to be_truthy
@cache.read('existing_key').should be_nil expect(@cache.read('existing_key')).to be_nil
end end
it 'should return false when asked to delete a nonexistent key' do 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 end
it 'should convert keys to strings when storing them' do it 'should convert keys to strings when storing them' do
@cache.write(:symbol_key, 'value') @cache.write(:symbol_key, 'value')
@cache.read('symbol_key').should == 'value' expect(@cache.read('symbol_key')).to eq('value')
end end
it 'should convert keys to strings when reading them' do 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 end
it 'should convert keys to strings when fetching them' do 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 end
it 'should convert keys to strings when deleting them' do it 'should convert keys to strings when deleting them' do
@cache.delete(:existing_key).should be_true expect(@cache.delete(:existing_key)).to be_truthy
@cache.read('existing_key').should be_nil expect(@cache.read('existing_key')).to be_nil
end end
end end

View File

@ -24,19 +24,19 @@ shared_examples_for 'configurable user agent' do
it 'should allow the user agent to be modified' do it 'should allow the user agent to be modified' do
client.user_agent = 'Custom User Agent/1.2.3' 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 end
it 'should allow the user agent to be set to nil' do it 'should allow the user agent to be set to nil' do
client.user_agent = nil client.user_agent = nil
client.user_agent.should == nil expect(client.user_agent).to eq(nil)
end end
it 'should not allow the user agent to be used with bogus values' do it 'should not allow the user agent to be used with bogus values' do
(lambda do expect(lambda do
client.user_agent = 42 client.user_agent = 42
client.execute(:uri=>'https://www.google.com/') client.execute(:uri=>'https://www.google.com/')
end).should raise_error(TypeError) end).to raise_error(TypeError)
end end
it 'should transmit a User-Agent header when sending requests' do 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| conn = stub_connection do |stub|
stub.get('/') do |env| stub.get('/') do |env|
headers = env[:request_headers] headers = env[:request_headers]
headers.should have_key('User-Agent') expect(headers).to have_key('User-Agent')
headers['User-Agent'].should == client.user_agent expect(headers['User-Agent']).to eq(client.user_agent)
[200, {}, ['']] [200, {}, ['']]
end end
end end
@ -61,11 +61,11 @@ describe Google::APIClient do
let(:client) { Google::APIClient.new(:application_name => 'API Client Tests') } let(:client) { Google::APIClient.new(:application_name => 'API Client Tests') }
it 'should make its version number available' do 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 end
it 'should default to OAuth 2' do it 'should default to OAuth 2' do
Signet::OAuth2::Client.should === client.authorization expect(Signet::OAuth2::Client).to be === client.authorization
end end
describe 'configure for no authentication' do describe 'configure for no authentication' do
@ -83,15 +83,17 @@ describe Google::APIClient do
end end
it 'should use the default OAuth1 client configuration' do 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' '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' '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' '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 end
it_should_behave_like 'configurable user agent' it_should_behave_like 'configurable user agent'
@ -113,7 +115,7 @@ describe Google::APIClient do
client.authorization = :oauth_2 client.authorization = :oauth_2
@connection = stub_connection do |stub| @connection = stub_connection do |stub|
stub.post('/prediction/v1.2/training?data=12345') do |env| 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, {}, '{}'] [200, {}, '{}']
end end
end end
@ -234,7 +236,7 @@ describe Google::APIClient do
count = 0 count = 0
@connection = stub_connection do |stub| @connection = stub_connection do |stub|
stub.get('/foo') do |env| stub.get('/foo') do |env|
count.should == 0 expect(count).to eq(0)
count += 1 count += 1
[403, {}, '{}'] [403, {}, '{}']
end end
@ -259,10 +261,10 @@ describe Google::APIClient do
end end
end end
client.execute( expect(client.execute(
:uri => 'https://www.gogole.com/foo', :uri => 'https://www.gogole.com/foo',
:connection => @connection :connection => @connection
).status.should == 200 ).status).to eq(200)
end end
@ -276,11 +278,11 @@ describe Google::APIClient do
end end
end end
client.execute( expect(client.execute(
:uri => 'https://www.gogole.com/foo', :uri => 'https://www.gogole.com/foo',
:connection => @connection :connection => @connection
).status.should == 500 ).status).to eq(500)
count.should == 3 expect(count).to eq(3)
end end
end end

View File

@ -4,6 +4,14 @@ $LOAD_PATH.uniq!
require 'rspec' require 'rspec'
require 'faraday' require 'faraday'
begin
require 'simplecov'
SimpleCov.start
rescue LoadError
# SimpleCov missing, so just run specs with no coverage.
end
Faraday::Adapter.load_middleware(:test) Faraday::Adapter.load_middleware(:test)
module Faraday module Faraday

View File

@ -37,7 +37,7 @@ namespace :gem do
# Dependencies used in the examples # Dependencies used in the examples
s.add_development_dependency('rake', '>= 0.9.0') 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' s.require_path = 'lib'

View File

@ -7,7 +7,6 @@ namespace :spec do
RSpec::Core::RakeTask.new(:all) do |t| RSpec::Core::RakeTask.new(:all) do |t|
t.pattern = FileList['spec/**/*_spec.rb'] t.pattern = FileList['spec/**/*_spec.rb']
t.rspec_opts = ['--color', '--format', 'documentation'] t.rspec_opts = ['--color', '--format', 'documentation']
t.rcov = false
end end
desc 'Generate HTML Specdocs for all specs.' 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.rspec_opts = %W( --format html --out #{File.join(specdoc_path, 'index.html')} )
t.fail_on_error = false t.fail_on_error = false
end 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 end
if RCOV_ENABLED desc 'Alias to spec:all'
desc 'Alias to spec:rcov' task 'spec' => 'spec:all'
task 'spec' => 'spec:rcov'
else
desc 'Alias to spec:all'
task 'spec' => 'spec:all'
end