vcr 1.7.1 → 1.7.2

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1 +1,4 @@
1
1
  script: "rake ci:build"
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
data/CHANGELOG.md CHANGED
@@ -1,6 +1,16 @@
1
1
  ## In git
2
2
 
3
- [Full Changelog](http://github.com/myronmarston/vcr/compare/v1.7.1...master)
3
+ [Full Changelog](http://github.com/myronmarston/vcr/compare/v1.7.2...master)
4
+
5
+ ## 1.7.2 (March 26, 2011)
6
+
7
+ [Full Changelog](http://github.com/myronmarston/vcr/compare/v1.7.1...v1.7.2)
8
+
9
+ * Fixed Typhoeus adapter so headers are returned in the same form during
10
+ playback as they would be without VCR. Bug reported by
11
+ [Avdi Grimm](https://github.com/avdi).
12
+ * Fixed Faraday adapter so it treats response headers in the same way
13
+ Faraday itself does (i.e. with lowercase keys).
4
14
 
5
15
  ## 1.7.1 (March 19, 2011)
6
16
 
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ group :development do
5
5
  # patron and em-http-request can't install on JRuby, so we have to limit their platform here.
6
6
  platforms :ruby do
7
7
  gem 'patron', '0.4.9'
8
- gem 'em-http-request', '~> 0.2.7'
8
+ gem 'em-http-request', '~> 0.3.0'
9
9
  gem 'curb', '0.7.8'
10
10
  gem 'typhoeus', '~> 0.2.1'
11
11
  end
@@ -32,7 +32,7 @@ module VCR
32
32
  ::Typhoeus::Response.new(
33
33
  :code => response.status.code,
34
34
  :body => response.body,
35
- :headers_hash => response.headers
35
+ :headers_hash => normalized_response_headers(response)
36
36
  )
37
37
  end
38
38
  )
@@ -65,6 +65,16 @@ module VCR
65
65
 
66
66
  hash
67
67
  end
68
+
69
+ def normalized_response_headers(response)
70
+ hash = {}
71
+
72
+ response.headers.each do |key, values|
73
+ hash[key] = values.size == 1 ? values.first : values
74
+ end if response.headers
75
+
76
+ hash
77
+ end
68
78
  end
69
79
  end
70
80
  end
@@ -18,7 +18,7 @@ module VCR
18
18
  elsif response = VCR::HttpStubbingAdapters::Faraday.stubbed_response_for(request_matcher)
19
19
  env.update(
20
20
  :status => response.status.code,
21
- :response_headers => correctly_cased_headers(response.headers || {}),
21
+ :response_headers => normalized_headers(response.headers),
22
22
  :body => response.body
23
23
  )
24
24
 
@@ -64,15 +64,14 @@ module VCR
64
64
  )
65
65
  end
66
66
 
67
- def correctly_cased_headers(headers)
68
- correctly_cased_hash = {}
67
+ def normalized_headers(headers)
68
+ hash = {}
69
69
 
70
- headers.each do |key, value|
71
- key = key.to_s.split('-').map { |segment| segment.capitalize }.join("-")
72
- correctly_cased_hash[key] = value
73
- end
70
+ headers.each do |key, values|
71
+ hash[key] = values.join(', ')
72
+ end if headers
74
73
 
75
- correctly_cased_hash
74
+ hash
76
75
  end
77
76
  end
78
77
  end
data/lib/vcr/version.rb CHANGED
@@ -3,7 +3,7 @@ module VCR
3
3
 
4
4
  def version
5
5
  @version ||= begin
6
- string = '1.7.1'
6
+ string = '1.7.2'
7
7
 
8
8
  def string.parts
9
9
  split('.').map { |p| p.to_i }
@@ -127,7 +127,8 @@ end
127
127
  end
128
128
 
129
129
  def get_header(header_key, response)
130
- response.headers[header_key]
130
+ header = response.headers[header_key.downcase]
131
+ header.split(', ')
131
132
  end
132
133
 
133
134
  def make_http_request(method, url, body = nil, headers = {})
@@ -14,6 +14,41 @@ shared_examples_for "an http library" do |library, supported_request_match_attri
14
14
  # so this gives us another alias we can use for the original method.
15
15
  alias make_request make_http_request
16
16
 
17
+ 1.upto(2) do |header_count|
18
+ describe "making an HTTP request that responds with #{header_count} Set-Cookie header(s)" do
19
+ define_method :get_set_cookie_header do
20
+ VCR.use_cassette('header_test', :record => :once) do
21
+ get_header 'Set-Cookie', make_http_request(:get, "http://localhost:#{VCR::SinatraApp.port}/set-cookie-headers/#{header_count}")
22
+ end
23
+ end
24
+
25
+ define_method :should_be_pending do
26
+ if header_count == 2
27
+ [
28
+ 'Faraday (patron)',
29
+ 'HTTP Client',
30
+ 'EM HTTP Request',
31
+ 'Curb'
32
+ ].include?(adapter_module.http_library_name)
33
+ end
34
+ end
35
+
36
+ it 'returns the same header value when recording and replaying' do
37
+ pending "There appears to be a bug in the the HTTP stubbing library", :if => should_be_pending do
38
+ (recorded_val = get_set_cookie_header).should_not be_nil
39
+ replayed_val = get_set_cookie_header
40
+
41
+ # we don't care about order differences if the values are arrays
42
+ if recorded_val.is_a?(Array) && replayed_val.is_a?(Array)
43
+ replayed_val.should =~ recorded_val
44
+ else
45
+ replayed_val.should == recorded_val
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+
17
52
  describe 'making an HTTP request' do
18
53
  let(:status) { VCR::ResponseStatus.new(200, 'OK') }
19
54
  let(:interaction) { VCR::HTTPInteraction.new(request, response) }
@@ -39,16 +74,8 @@ shared_examples_for "an http library" do |library, supported_request_match_attri
39
74
  let(:request) { VCR::Request.new(:get, url) }
40
75
  let(:response) { VCR::Response.new(status, nil, response_body, '1.1') }
41
76
 
42
- def should_be_pending?
43
- return false unless described_class == VCR::HttpStubbingAdapters::WebMock
44
- return false unless request.uri.include?(CGI.escape('&'))
45
- self.class.included_modules.first.http_library_name == 'EM HTTP Request'
46
- end
47
-
48
77
  it 'returns the expected response for the same request' do
49
- pending "WebMock/EM-HTTP bug", :if => should_be_pending? do
50
- get_body_string(make_http_request(:get, url)).should == response_body
51
- end
78
+ get_body_string(make_http_request(:get, url)).should == response_body
52
79
  end
53
80
  end
54
81
  end
@@ -14,6 +14,16 @@ module VCR
14
14
  "FOO!"
15
15
  end
16
16
 
17
+ get '/set-cookie-headers/1' do
18
+ headers 'Set-Cookie' => 'foo'
19
+ 'header set'
20
+ end
21
+
22
+ get '/set-cookie-headers/2' do
23
+ headers 'Set-Cookie' => %w[ foo bar ]
24
+ 'header set'
25
+ end
26
+
17
27
  def self.port
18
28
  server.port
19
29
  end
data/vcr.gemspec CHANGED
@@ -41,7 +41,7 @@ Gem::Specification.new do |s|
41
41
 
42
42
  {
43
43
  'patron' => '0.4.9',
44
- 'em-http-request' => '~> 0.2.7',
44
+ 'em-http-request' => '~> 0.3.0',
45
45
  'curb' => '0.7.8',
46
46
  'typhoeus' => '~> 0.2.1'
47
47
  }.each do |lib, version|
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vcr
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 7
9
- - 1
10
- version: 1.7.1
9
+ - 2
10
+ version: 1.7.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Myron Marston
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-19 00:00:00 -07:00
18
+ date: 2011-03-26 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -267,12 +267,12 @@ dependencies:
267
267
  requirements:
268
268
  - - ~>
269
269
  - !ruby/object:Gem::Version
270
- hash: 25
270
+ hash: 19
271
271
  segments:
272
272
  - 0
273
- - 2
274
- - 7
275
- version: 0.2.7
273
+ - 3
274
+ - 0
275
+ version: 0.3.0
276
276
  requirement: *id016
277
277
  - !ruby/object:Gem::Dependency
278
278
  prerelease: false