# Copyright 2015 Google Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. require 'spec_helper' require 'google/apis/core/batch' require 'google/apis/core/json_representation' require 'hurley/test' RSpec.describe Google::Apis::Core::BatchCommand do include TestHelpers include_context 'HTTP client' let(:command) do command = Google::Apis::Core::BatchCommand.new(:post, 'https://www.googleapis.com/batch') end let(:get_command) { Google::Apis::Core::HttpCommand.new(:get, 'https://www.googleapis.com/zoo/animals/1') } let(:post_with_string_command) do command = Google::Apis::Core::HttpCommand.new(:post, 'https://www.googleapis.com/zoo/animals/2') command.body = 'Hello world' command.header[:content_type] = 'text/plain' command end let(:post_with_io_command) do command = Google::Apis::Core::HttpCommand.new(:post, 'https://www.googleapis.com/zoo/animals/3') command.body = StringIO.new('Goodbye!') command.header[:content_type] = 'text/plain' command end before(:example) do response = < 'multipart/mixed; boundary=batch123' }, body: response) end it 'should send content' do b = ->(_res, _err) {} command.add(get_command, &b) command.add(post_with_string_command, &b) command.add(post_with_io_command, &b) command.execute(client) expected_body = <