Skip to content

Commit

Permalink
Patron adds an "Expect" header.
Browse files Browse the repository at this point in the history
  • Loading branch information
myronmarston committed Oct 13, 2011
1 parent c2a794b commit 90d9413
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
4 changes: 1 addition & 3 deletions features/request_matching/headers.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Feature: Matching on Headers

Use the `:headers` request matcher to match requests on the request headers.

Background:
Scenario Outline: Replay interaction that matches the headers
Given a previously recorded cassette file "cassettes/example.yml" with:
"""
---
Expand Down Expand Up @@ -41,8 +41,6 @@ Feature: Matching on Headers
body: user 2 response
http_version: "1.1"
"""

Scenario Outline: Replay interaction that matches the headers
And a file named "header_matching.rb" with:
"""ruby
include_http_adapter_for("<http_lib>")
Expand Down
19 changes: 14 additions & 5 deletions features/step_definitions/cli_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,33 @@ def normalize_http_interaction(i)
i.response.status.message ||= ''

# Remove non-deterministic headers and headers
# that get added by a particular HTTP library (bu tnot by others)
# that get added by a particular HTTP library (but not by others)
i.response.headers.reject! { |k, v| %w[ server date connection ].include?(k) }
i.request.headers.reject! { |k, v| %w[ accept user-agent connection ].include?(k) }
i.request.headers.reject! { |k, v| %w[ accept user-agent connection expect ].include?(k) }

# Some HTTP libraries include an extra space ("OK " instead of "OK")
i.response.status.message = i.response.status.message.strip

if @stubbing_lib_for_current_scenario =~ /excon|faraday/
if @scenario_parameters.to_s =~ /excon|faraday/
# Excon/Faraday do not expose the status message or http version,
# so we have no way to record these attributes.
i.response.status.message = nil
i.response.http_version = nil
elsif @stubbing_lib_for_current_scenario.to_s.include?('webmock')
elsif @scenario_parameters.to_s.include?('webmock')
# WebMock does not expose the HTTP version so we have no way to record it
i.response.http_version = nil
end
end

def normalize_cassette_content(content)
return content unless @scenario_parameters.to_s.include?('patron')
interactions = YAML.load(content)
interactions.each do |i|
i.request.headers.merge!('Expect' => [''])
end
YAML.dump(interactions)
end

def modify_file(file_name, orig_text, new_text)
in_current_dir do
file = File.read(file_name)
Expand All @@ -66,7 +75,7 @@ def modify_file(file_name, orig_text, new_text)
end

Given /^a previously recorded cassette file "([^"]*)" with:$/ do |file_name, content|
write_file(file_name, content)
write_file(file_name, normalize_cassette_content(content))
end

Given /^(\d+) days have passed since the cassette was recorded$/ do |day_count|
Expand Down
4 changes: 2 additions & 2 deletions features/support/http_lib_filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def cell_values
# logic in our step definitions based on the http stubbing library.
Before do |scenario|
if scenario.respond_to?(:cell_values)
@stubbing_lib_for_current_scenario = scenario.cell_values.find { |v| v =~ /fakeweb|webmock|typhoeus|faraday|excon/ }
@scenario_parameters = scenario.cell_values
else
@stubbing_lib_for_current_scenario = nil
@scenario_parameters = nil
end
end

0 comments on commit 90d9413

Please sign in to comment.