spec/google/api_client/media_spec.rb in google-api-client-0.4.4 vs spec/google/api_client/media_spec.rb in google-api-client-0.4.5

- old
+ new

@@ -23,54 +23,61 @@ it 'should reject invalid file paths' do (lambda do media = Google::APIClient::UploadIO.new('doesnotexist', 'text/plain') end).should raise_error end - + describe 'with a file' do before do @file = File.expand_path('files/sample.txt', fixtures_path) @media = Google::APIClient::UploadIO.new(@file, 'text/plain') end - + it 'should report the correct file length' do @media.length.should == File.size(@file) end - + it 'should have a mime type' do @media.content_type.should == 'text/plain' end end - + describe 'with StringIO' do before do @content = "hello world" @media = Google::APIClient::UploadIO.new(StringIO.new(@content), 'text/plain', 'test.txt') end it 'should report the correct file length' do @media.length.should == @content.length end - + it 'should have a mime type' do @media.content_type.should == 'text/plain' end end end describe Google::APIClient::ResumableUpload do + CLIENT ||= Google::APIClient.new + + after do + # Reset client to not-quite-pristine state + CLIENT.key = nil + CLIENT.user_ip = nil + end + before do - @client = Google::APIClient.new - @drive = @client.discovered_api('drive', 'v1') + @drive = CLIENT.discovered_api('drive', 'v1') @file = File.expand_path('files/sample.txt', fixtures_path) @media = Google::APIClient::UploadIO.new(@file, 'text/plain') @uploader = Google::APIClient::ResumableUpload.new( mock_result(308), @media, 'https://www.googleapis.com/upload/drive/v1/files/12345') end - + it 'should consider 20x status as complete' do api_client = stub('api', :execute => mock_result(200)) @uploader.send_chunk(api_client) @uploader.complete?.should == true end @@ -91,12 +98,12 @@ it 'should detect changes to location' do api_client = stub('api', :execute => mock_result(308, 'location' => 'https://www.googleapis.com/upload/drive/v1/files/abcdef')) @uploader.send_chunk(api_client) @uploader.location.should == 'https://www.googleapis.com/upload/drive/v1/files/abcdef' 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 api_client = mock('api') api_client.should_receive(:execute).and_return(mock_result(308, 'range' => '0-99')) api_client.should_receive(:execute).with( hash_including(:headers => hash_including( "Content-Range" => "bytes 100-299/#{@media.length}", @@ -105,11 +112,11 @@ @uploader.chunk_size = 200 @uploader.send_chunk(api_client) # Send bytes 0-199, only 0-99 saved @uploader.send_chunk(api_client) # Send bytes 100-299 end - + it 'should resync the offset after 5xx errors' do api_client = mock('api') api_client.should_receive(:execute).and_return(mock_result(500)) api_client.should_receive(:execute).with( hash_including(:headers => hash_including( @@ -130,7 +137,7 @@ def mock_result(status, headers = {}) reference = Google::APIClient::Reference.new(:api_method => @drive.files.insert) stub('result', :status => status, :headers => headers, :reference => reference) end - + end