spec/support/shared_examples/request.rb in vacuum-0.2.0 vs spec/support/shared_examples/request.rb in vacuum-0.2.1

- old
+ new

@@ -84,9 +84,56 @@ request.get.should be_a Vacuum::Response::Base end end end + describe '#get!' do + let(:response_class) do + Vacuum::Response.const_get request.send(:class_basename) + end + + context 'when response is bad' do + let(:mock_response) do + body = <<-XML.gsub!(/>\s+</, '><').strip! + <?xml version=\"1.0\" ?> + <ErrorResponse> + <Error> + <Code>RequestThrottled</Code> + <Message>Request from 192.168.0.1 is throttled.</Message> + </Error> + <RequestID>123</RequestID> + </ErrorResponse> + XML + + response_class.new body, 503 + end + + before do + request.stub!(:get).and_return mock_response + end + + it 'raises a Bad Response error' do + expect do + request.get! + end.to raise_error Vacuum::BadResponse, '503 RequestThrottled' + end + end + + context 'when response is OK' do + let(:mock_response) do + response_class.new('', 200) + end + + before do + request.stub!(:get).and_return mock_response + end + + it 'returns the response' do + request.get!.should eql mock_response + end + end + end + describe '#parameters' do it 'includes default parameters' do request.parameters.should have_key 'AWSAccessKeyId' end