From d6beafcb4bc7d08e68648cf30432cff38cf89140 Mon Sep 17 00:00:00 2001 From: Patrick Robinson Date: Fri, 15 Jan 2016 09:26:12 +1100 Subject: [PATCH 1/4] Make sure test is never flakey --- spec/unit/matchers/honour_origin_cache_headers_spec.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/unit/matchers/honour_origin_cache_headers_spec.rb b/spec/unit/matchers/honour_origin_cache_headers_spec.rb index e36ec8f..699e791 100644 --- a/spec/unit/matchers/honour_origin_cache_headers_spec.rb +++ b/spec/unit/matchers/honour_origin_cache_headers_spec.rb @@ -5,6 +5,7 @@ describe 'honour_origin_cache_headers' do context 'fix_date_header' do + let(:date) { Time.now } it 'should leave filled in date unchanged' do origin_response = double(RestClient::Response) allow(origin_response).to receive(:headers) { { :date => 'something' } } @@ -12,10 +13,10 @@ end it 'should fill in date if it is absent' do - pending + allow(Time).to receive(:now).and_return(date) origin_response = double(RestClient::Response) allow(origin_response).to receive(:headers) { { } } - expect(fix_date_header(origin_response).headers[:date]).to eq(Time.now.httpdate) + expect(fix_date_header(origin_response).headers[:date]).to eq(date.httpdate) end end From e461797aef80400ba8c9dada3a3375d5f543bcac Mon Sep 17 00:00:00 2001 From: Patrick Robinson Date: Fri, 15 Jan 2016 09:27:11 +1100 Subject: [PATCH 2/4] Return a real variable to the stub Otherwise it will always be an empty hash --- spec/unit/matchers/honour_origin_cache_headers_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/unit/matchers/honour_origin_cache_headers_spec.rb b/spec/unit/matchers/honour_origin_cache_headers_spec.rb index 699e791..6f6aaa1 100644 --- a/spec/unit/matchers/honour_origin_cache_headers_spec.rb +++ b/spec/unit/matchers/honour_origin_cache_headers_spec.rb @@ -6,6 +6,7 @@ describe 'honour_origin_cache_headers' do context 'fix_date_header' do let(:date) { Time.now } + let(:headers) { {} } it 'should leave filled in date unchanged' do origin_response = double(RestClient::Response) allow(origin_response).to receive(:headers) { { :date => 'something' } } @@ -15,7 +16,7 @@ it 'should fill in date if it is absent' do allow(Time).to receive(:now).and_return(date) origin_response = double(RestClient::Response) - allow(origin_response).to receive(:headers) { { } } + allow(origin_response).to receive(:headers).and_return(headers) expect(fix_date_header(origin_response).headers[:date]).to eq(date.httpdate) end From 89d165f56b63d43d8b42e39075be6c52e81f228f Mon Sep 17 00:00:00 2001 From: Patrick Robinson Date: Fri, 15 Jan 2016 09:28:08 +1100 Subject: [PATCH 3/4] Make the assignment of date more succinct --- lib/akamai_rspec/matchers/honour_origin_headers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/akamai_rspec/matchers/honour_origin_headers.rb b/lib/akamai_rspec/matchers/honour_origin_headers.rb index 5225e09..a55051d 100644 --- a/lib/akamai_rspec/matchers/honour_origin_headers.rb +++ b/lib/akamai_rspec/matchers/honour_origin_headers.rb @@ -18,7 +18,7 @@ end def fix_date_header(origin_response) - origin_response.headers[:date] = Time.now.httpdate unless origin_response.headers[:date] + origin_response.headers[:date] ||= Time.now.httpdate origin_response end From cba47a2098b67348251167df748b32e33f964494 Mon Sep 17 00:00:00 2001 From: Patrick Robinson Date: Fri, 15 Jan 2016 09:32:57 +1100 Subject: [PATCH 4/4] fail should be without a capital letter to avoid a NameError --- spec/functional/matchers_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/functional/matchers_spec.rb b/spec/functional/matchers_spec.rb index 1ff26b6..e99a232 100644 --- a/spec/functional/matchers_spec.rb +++ b/spec/functional/matchers_spec.rb @@ -3,6 +3,6 @@ describe 'be_forwarded_to_index' do it 'should have tests' do pending - Fail + fail end end