webmock 1.7.4 → 1.7.5

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -4,3 +4,5 @@ rvm:
4
4
  - 1.9.3
5
5
  - ree
6
6
  - jruby
7
+
8
+ script: "bundle exec rake && rake em_http_request_1_x_spec"
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.7.5
4
+
5
+ * Added support for Patron 0.4.15. This change is not backward compatible so please upgrade Patron to version >= 0.4.15 if you want to use it with WebMock.
6
+
7
+ Thanks to [Andreas Garnæs](https://github.com/andreas)
8
+
3
9
  ## 1.7.4
4
10
 
5
11
  * Added support for matching EM-HTTP-Request requests with body declared as a Hash
data/Gemfile CHANGED
@@ -1,6 +1,11 @@
1
1
  source 'http://rubygems.org/'
2
2
 
3
3
  gemspec
4
+ if ENV["EM_HTTP_REQUEST_1_X"]
5
+ gem 'em-http-request', '>= 1.0.0.beta.4'
6
+ gem 'em-synchrony', '>= 0.3.0.beta.1'
7
+ end
8
+
4
9
 
5
10
  group :development do
6
11
  gem 'rake'
data/README.md CHANGED
@@ -647,6 +647,7 @@ People who submitted patches and new features or suggested improvements. Many th
647
647
  * Nikita Fedyashev
648
648
  * Lin Jen-Shin
649
649
  * David Yeu
650
+ * Andreas Garnæs
650
651
 
651
652
  For a full list of contributors you can visit the
652
653
  [contributors](https://github.com/bblimke/webmock/contributors) page.
data/Rakefile CHANGED
@@ -25,6 +25,11 @@ RSpec::Core::RakeTask.new(:spec_http_without_webmock) do |t|
25
25
  t.pattern = 'spec/real_net_http_spec.rb'
26
26
  end
27
27
 
28
+
29
+ task :em_http_request_1_x_spec do
30
+ sh "EM_HTTP_REQUEST_1_X=true bundle install && bundle exec rspec spec/em_http_request_spec.rb" if RUBY_VERSION >= "1.9.2"
31
+ end
32
+
28
33
  require 'rake/testtask'
29
34
  Rake::TestTask.new(:test) do |test|
30
35
  test.test_files = FileList["test/**/*.rb"].exclude("test/test_helper.rb")
@@ -38,6 +43,7 @@ Rake::TestTask.new(:minitest) do |test|
38
43
  test.warning = false
39
44
  end
40
45
 
46
+
41
47
  task :default => [:spec, :spec_http_without_webmock, :test, :minitest]
42
48
 
43
49
  require 'rdoc/task'
@@ -25,7 +25,7 @@ if defined?(::Patron)
25
25
  WebMock::HttpLibAdapters::PatronAdapter.
26
26
  handle_file_name(req, webmock_response)
27
27
  res = WebMock::HttpLibAdapters::PatronAdapter.
28
- build_patron_response(webmock_response)
28
+ build_patron_response(webmock_response, default_response_charset)
29
29
  WebMock::CallbackRegistry.invoke_callbacks(
30
30
  {:lib => :patron}, request_signature, webmock_response)
31
31
  res
@@ -98,15 +98,22 @@ if defined?(::Patron)
98
98
  request_signature
99
99
  end
100
100
 
101
- def self.build_patron_response(webmock_response)
101
+ def self.build_patron_response(webmock_response, default_response_charset)
102
102
  raise ::Patron::TimeoutError if webmock_response.should_timeout
103
103
  webmock_response.raise_error_if_any
104
- res = ::Patron::Response.new
105
- res.instance_variable_set(:@body, webmock_response.body)
106
- res.instance_variable_set(:@status, webmock_response.status[0])
107
- res.instance_variable_set(:@status_line, webmock_response.status[1])
108
- res.instance_variable_set(:@headers, webmock_response.headers)
109
- res
104
+
105
+ header_fields = (webmock_response.headers || []).map { |(k, vs)| Array(vs).map { |v| "#{k}: #{v}" } }.flatten
106
+ status_line = "HTTP/1.1 #{webmock_response.status[0]} #{webmock_response.status[1]}"
107
+ header_data = ([status_line] + header_fields).join("\r\n")
108
+
109
+ ::Patron::Response.new(
110
+ "",
111
+ webmock_response.status[0],
112
+ 0,
113
+ header_data,
114
+ webmock_response.body,
115
+ default_response_charset
116
+ )
110
117
  end
111
118
 
112
119
  def self.build_webmock_response(patron_response)
@@ -1,3 +1,3 @@
1
1
  module WebMock
2
- VERSION = '1.7.4' unless defined?(::WebMock::VERSION)
2
+ VERSION = '1.7.5' unless defined?(::WebMock::VERSION)
3
3
  end
data/spec/patron_spec.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
4
  require 'webmock_shared'
3
5
 
@@ -84,6 +86,42 @@ unless RUBY_PLATFORM =~ /java/
84
86
  stub_http_request(:copy, "www.example.com/abc").with(:headers => {'Destination' => "/def"})
85
87
  @sess.copy("/abc", "/def")
86
88
  end
89
+
90
+ if /^1\.9/ === RUBY_VERSION
91
+ describe "handling encoding same way as patron" do
92
+ around(:each) do |example|
93
+ @encoding = Encoding.default_internal
94
+ Encoding.default_internal = "UTF-8"
95
+ example.run
96
+ Encoding.default_internal = @encoding
97
+ end
98
+
99
+ it "should encode body based on charset in headers" do
100
+ stub_request(:get, "www.example.com").
101
+ to_return(:headers => {'Content-Type' => 'text/html; charset=iso-8859-1'},
102
+ :body => "Øl".encode("iso-8859-1"))
103
+
104
+ @sess.get("").body.encoding.should == Encoding.default_internal
105
+ end
106
+
107
+ it "should encode body based on encoding-attribute in body" do
108
+ stub_request(:get, "www.example.com").
109
+ to_return(:body => "<?xml encoding=\"iso-8859-1\">Øl</xml>".encode("iso-8859-1"))
110
+
111
+
112
+ @sess.get("").body.encoding.should == Encoding.default_internal
113
+ end
114
+
115
+ it "should encode body based on Session#default_response_charset" do
116
+ stub_request(:get, "www.example.com").
117
+ to_return(:body => "Øl".encode("iso-8859-1"))
118
+
119
+ @sess.default_response_charset = "iso-8859-1"
120
+
121
+ @sess.get("").body.encoding.should == Encoding.default_internal
122
+ end
123
+ end
124
+ end
87
125
  end
88
126
  end
89
127
  end
@@ -23,11 +23,15 @@ module PatronSpecHelper
23
23
  headers[k] = v
24
24
  end
25
25
  end
26
+
27
+ status_line_pattern = %r(\AHTTP/(\d+\.\d+)\s+(\d\d\d)\s*([^\r\n]+)?)
28
+ message = response.status_line.match(status_line_pattern)[3] || ""
29
+
26
30
  OpenStruct.new({
27
31
  :body => response.body,
28
32
  :headers => WebMock::Util::Headers.normalize_headers(headers),
29
33
  :status => response.status.to_s,
30
- :message => response.status_line
34
+ :message => message
31
35
  })
32
36
  end
33
37
 
data/webmock.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.add_development_dependency 'rspec', '>= 2.0.0'
21
21
  s.add_development_dependency 'httpclient', '>= 2.1.5.2'
22
22
  s.add_development_dependency 'patron', '>= 0.4.9'
23
- s.add_development_dependency 'em-http-request', '>= 0.2.14'
23
+ s.add_development_dependency 'em-http-request', '~> 0.3.0'
24
24
  s.add_development_dependency 'curb', '>= 0.7.8'
25
25
  s.add_development_dependency 'typhoeus', '>= 0.2.4'
26
26
  s.add_development_dependency 'minitest', '>= 2.2.2'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webmock
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.4
4
+ version: 1.7.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-17 00:00:00.000000000Z
12
+ date: 2011-08-27 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable
16
- requirement: &2160447620 !ruby/object:Gem::Requirement
16
+ requirement: &2153330000 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -24,10 +24,10 @@ dependencies:
24
24
  version: 2.2.5
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *2160447620
27
+ version_requirements: *2153330000
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: crack
30
- requirement: &2160424420 !ruby/object:Gem::Requirement
30
+ requirement: &2153329140 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ! '>='
@@ -35,10 +35,10 @@ dependencies:
35
35
  version: 0.1.7
36
36
  type: :runtime
37
37
  prerelease: false
38
- version_requirements: *2160424420
38
+ version_requirements: *2153329140
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: rspec
41
- requirement: &2160422500 !ruby/object:Gem::Requirement
41
+ requirement: &2153328680 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
44
  - - ! '>='
@@ -46,10 +46,10 @@ dependencies:
46
46
  version: 2.0.0
47
47
  type: :development
48
48
  prerelease: false
49
- version_requirements: *2160422500
49
+ version_requirements: *2153328680
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: httpclient
52
- requirement: &2160421560 !ruby/object:Gem::Requirement
52
+ requirement: &2153328200 !ruby/object:Gem::Requirement
53
53
  none: false
54
54
  requirements:
55
55
  - - ! '>='
@@ -57,10 +57,10 @@ dependencies:
57
57
  version: 2.1.5.2
58
58
  type: :development
59
59
  prerelease: false
60
- version_requirements: *2160421560
60
+ version_requirements: *2153328200
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: patron
63
- requirement: &2160420320 !ruby/object:Gem::Requirement
63
+ requirement: &2153327700 !ruby/object:Gem::Requirement
64
64
  none: false
65
65
  requirements:
66
66
  - - ! '>='
@@ -68,21 +68,21 @@ dependencies:
68
68
  version: 0.4.9
69
69
  type: :development
70
70
  prerelease: false
71
- version_requirements: *2160420320
71
+ version_requirements: *2153327700
72
72
  - !ruby/object:Gem::Dependency
73
73
  name: em-http-request
74
- requirement: &2160418840 !ruby/object:Gem::Requirement
74
+ requirement: &2153327020 !ruby/object:Gem::Requirement
75
75
  none: false
76
76
  requirements:
77
- - - ! '>='
77
+ - - ~>
78
78
  - !ruby/object:Gem::Version
79
- version: 0.2.14
79
+ version: 0.3.0
80
80
  type: :development
81
81
  prerelease: false
82
- version_requirements: *2160418840
82
+ version_requirements: *2153327020
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: curb
85
- requirement: &2160400940 !ruby/object:Gem::Requirement
85
+ requirement: &2153326340 !ruby/object:Gem::Requirement
86
86
  none: false
87
87
  requirements:
88
88
  - - ! '>='
@@ -90,10 +90,10 @@ dependencies:
90
90
  version: 0.7.8
91
91
  type: :development
92
92
  prerelease: false
93
- version_requirements: *2160400940
93
+ version_requirements: *2153326340
94
94
  - !ruby/object:Gem::Dependency
95
95
  name: typhoeus
96
- requirement: &2160400240 !ruby/object:Gem::Requirement
96
+ requirement: &2153317840 !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
99
99
  - - ! '>='
@@ -101,10 +101,10 @@ dependencies:
101
101
  version: 0.2.4
102
102
  type: :development
103
103
  prerelease: false
104
- version_requirements: *2160400240
104
+ version_requirements: *2153317840
105
105
  - !ruby/object:Gem::Dependency
106
106
  name: minitest
107
- requirement: &2160399300 !ruby/object:Gem::Requirement
107
+ requirement: &2153317380 !ruby/object:Gem::Requirement
108
108
  none: false
109
109
  requirements:
110
110
  - - ! '>='
@@ -112,10 +112,10 @@ dependencies:
112
112
  version: 2.2.2
113
113
  type: :development
114
114
  prerelease: false
115
- version_requirements: *2160399300
115
+ version_requirements: *2153317380
116
116
  - !ruby/object:Gem::Dependency
117
117
  name: rdoc
118
- requirement: &2160398420 !ruby/object:Gem::Requirement
118
+ requirement: &2153316780 !ruby/object:Gem::Requirement
119
119
  none: false
120
120
  requirements:
121
121
  - - ! '>'
@@ -123,7 +123,7 @@ dependencies:
123
123
  version: 3.5.0
124
124
  type: :development
125
125
  prerelease: false
126
- version_requirements: *2160398420
126
+ version_requirements: *2153316780
127
127
  description: WebMock allows stubbing HTTP requests and setting expectations on HTTP
128
128
  requests.
129
129
  email: