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
8 changes: 7 additions & 1 deletion lib/airborne/request_expectations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ def expect_header_contains(key, content)
expect_header_impl(key, content, true)
end

def expect_header_matches(key, content)
expect_header_impl(key, content, false, true)
end

def optional(hash)
OptionalHashTypeExpectations.new(hash)
end
Expand All @@ -58,11 +62,13 @@ def date

private

def expect_header_impl(key, content, contains = nil)
def expect_header_impl(key, content, contains = nil, matches = nil)
header = headers[key]
if header
if contains
expect(header.downcase).to include(content.downcase)
elsif matches
expect(header.downcase).to match(content)
else
expect(header.downcase).to eq(content.downcase)
end
Expand Down
21 changes: 21 additions & 0 deletions spec/airborne/expectations/expect_header_matches_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'spec_helper'

describe 'expect header matches' do
it 'should ensure partial header match exists' do
mock_get('simple_get', 'Content-Type' => 'application/json')
get '/simple_get'
expect_header_matches(:content_type, /json/)
end

it 'should ensure header is present' do
mock_get('simple_get', 'Content-Type' => 'application/json')
get '/simple_get'
expect { expect_header_matches(:foo, /json/) }.to raise_error
end

it 'should ensure partial header is present' do
mock_get('simple_get', 'Content-Type' => 'application/json')
get '/simple_get'
expect { expect_header_matches(:content_type, /bar/) }.to raise_error
end
end