diff --git a/lib/mountebank/stub/http_response.rb b/lib/mountebank/stub/http_response.rb index b0f985d..1759c75 100644 --- a/lib/mountebank/stub/http_response.rb +++ b/lib/mountebank/stub/http_response.rb @@ -4,7 +4,7 @@ def self.create(statusCode=200, headers={}, body='', behaviors={}, mode='') payload[:statusCode] = statusCode payload[:headers] = headers unless headers.empty? payload[:body] = body unless body.empty? - payload[:_mode] = mode unless mode.empty? + payload[:_mode] = mode if (mode == 'text' or mode == 'binary') data = {is: payload} data.merge!(_behaviors: behaviors) unless behaviors.empty? diff --git a/spec/mountebank/stub/http_response_spec.rb b/spec/mountebank/stub/http_response_spec.rb index 0917bd3..5f87f30 100644 --- a/spec/mountebank/stub/http_response_spec.rb +++ b/spec/mountebank/stub/http_response_spec.rb @@ -22,6 +22,14 @@ end end + context 'invalid binary mode' do + let(:mode) { 'random' } + it 'returns response object without binary mode' do + expect(response).to be_a Mountebank::Stub::HttpResponse + expect(response.to_json).to eq '{"is":{"statusCode":200,"headers":{"Content-Type":"application/json"},"body":"{\"foo\":\"bar\"}"}}' + end + end + context 'with behaviors' do let(:behaviors) { { wait: 10000 } } it 'returns a response object' do