Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions lib/airborne/request_expectations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,24 @@ def date
private

def expect_header_impl(key, content, contains = nil)
header = headers[key]
if header
content = content.downcase
header = headers[key]

if header.is_a?(Array)
header = header.map(&:downcase)

if contains
expect(header).to include(a_string_matching(content))
else
expect(header).to include(content)
end
elsif header
header = header.downcase

if contains
expect(header.downcase).to include(content.downcase)
expect(header).to include(content)
else
expect(header.downcase).to eq(content.downcase)
expect(header).to eq(content)
end
else
fail RSpec::Expectations::ExpectationNotMetError, "Header #{key} not present in HTTP response"
Expand Down
14 changes: 14 additions & 0 deletions spec/airborne/expectations/expect_header_contains_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,18 @@
get '/simple_get'
expect { expect_header_contains(:content_type, 'bar') }.to raise_error
end

describe 'with multi-value headers' do
it 'should ensure partial header match exists' do
mock_get('simple_get', 'Set-Cookie' => ['cookie-name=myvalue; Path=/', 'another=value;'])
get '/simple_get'
expect_header_contains(:set_cookie, 'another=')
end

it 'should ensure partial header is present' do
mock_get('simple_get', 'Set-Cookie' => ['cookie-name=myvalue; Path=/', 'another=value;'])
get '/simple_get'
expect { expect_header_contains(:set_cookie, 'bar') }.to raise_error
end
end
end
14 changes: 14 additions & 0 deletions spec/airborne/expectations/expect_header_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,18 @@
get '/simple_get'
expect { expect_header(:foo, 'bar') }.to raise_error
end

describe 'with multi-value headers' do
it 'should find exact match for header content' do
mock_get('simple_get', 'Set-Cookie' => ['cookie-name=myvalue; Path=/', 'another=value;'])
get '/simple_get'
expect_header(:set_cookie, 'cookie-name=myvalue; Path=/')
end

it 'should find exact match for header content' do
mock_get('simple_get', 'Set-Cookie' => ['cookie-name=myvalue; Path=/', 'another=value;'])
get '/simple_get'
expect { expect_header(:set_cookie, 'another=') }.to raise_error
end
end
end