Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support regex header matching #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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