From 85aebf684bf958a3bbe50b5d994210f53fe318ac Mon Sep 17 00:00:00 2001 From: Hiro Asari Date: Mon, 18 Nov 2013 13:12:45 -0500 Subject: [PATCH] Add specs for pretty print JSON They only check that the response includes `\n`, which should not happen otherwise. --- spec/unit/endpoint/builds_spec.rb | 39 ++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/spec/unit/endpoint/builds_spec.rb b/spec/unit/endpoint/builds_spec.rb index 51e06eb7..1c7654e8 100644 --- a/spec/unit/endpoint/builds_spec.rb +++ b/spec/unit/endpoint/builds_spec.rb @@ -1,5 +1,42 @@ require 'spec_helper' describe Travis::Api::App::Endpoint::Builds do - it 'has to be tested' + include Travis::Testing::Stubs + + it 'works with default options' do + get('/repos.json', {}).should be_ok + end + + context '/repos.json is requested' do + before :each do + @plain_response_body = get('/repos.json').body + end + + context 'when `pretty=true` is given' do + it 'prints pretty formatted data' do + response = get('/repos.json?pretty=true') + response.should be_ok + response.body.should_not eq(@plain_response_body) + response.body.should match(/\n/) + end + end + + context 'when `pretty=1` is given' do + it 'prints pretty formatted data' do + response = get('/repos.json?pretty=1') + response.should be_ok + response.body.should_not eq(@plain_response_body) + response.body.should match(/\n/) + end + end + + context 'when `pretty=bogus` is given' do + it 'prints plain-formatted data' do + response = get('/repos.json?pretty=bogus') + response.should be_ok + response.body.should eq(@plain_response_body) + end + end + end + end