webmock 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,8 +1,17 @@
1
1
  #Changelog
2
2
 
3
+ ## 1.2.0
4
+
5
+ * RSpec 2 compatibility. Thanks to Sam Phillips!
6
+
7
+ * :allow_localhost => true' now permits 127.0.0.1 as well as 'localhost'. Thanks to Mack Earnhardt
8
+
9
+ * Request URI matching in now 2x faster!
10
+
11
+
3
12
  ## 1.1.0
4
13
 
5
- * [VCR](http://github.com/myronmarston/vcr/) compatibility. Many thanks to Myron Masteron for all suggestions.
14
+ * [VCR](http://github.com/myronmarston/vcr/) compatibility. Many thanks to Myron Marston for all suggestions.
6
15
 
7
16
  * Support for stubbing requests and returning responses with multiple headers with the same name. i.e multiple Accept headers.
8
17
 
data/README.md CHANGED
@@ -429,7 +429,7 @@ People who submitted patches and new features or suggested improvements. Many th
429
429
  * Tekin Suleyman
430
430
  * Tom Ward
431
431
  * Nadim Bitar
432
- * Myron Masteron
432
+ * Myron Marston
433
433
 
434
434
  ## Background
435
435
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0
@@ -1,10 +1,20 @@
1
1
  require 'webmock'
2
- require 'spec'
2
+
3
+ # RSpec 1.x and 2.x compatibility
4
+ begin
5
+ require 'rspec'
6
+ RSPEC_NAMESPACE = RSPEC_CONFIGURER = Rspec
7
+ rescue LoadError
8
+ require 'spec'
9
+ RSPEC_NAMESPACE = Spec
10
+ RSPEC_CONFIGURER = Spec::Runner
11
+ end
12
+
3
13
  require 'webmock/adapters/rspec/request_pattern_matcher'
4
14
  require 'webmock/adapters/rspec/webmock_matcher'
5
15
  require 'webmock/adapters/rspec/matchers'
6
-
7
- Spec::Runner.configure { |config|
16
+
17
+ RSPEC_CONFIGURER.configure { |config|
8
18
 
9
19
  config.include WebMock::Matchers
10
20
 
@@ -15,6 +25,6 @@ Spec::Runner.configure { |config|
15
25
 
16
26
  module WebMock
17
27
  def assertion_failure(message)
18
- raise Spec::Expectations::ExpectationNotMetError.new(message)
28
+ raise RSPEC_NAMESPACE::Expectations::ExpectationNotMetError.new(message)
19
29
  end
20
- end
30
+ end
@@ -64,7 +64,7 @@ module WebMock
64
64
  def matches?(uri)
65
65
  if @pattern.is_a?(Addressable::URI)
66
66
  ##TODO : do I need to normalize again??
67
- WebMock::Util::URI.normalize_uri(uri) === WebMock::Util::URI.normalize_uri(@pattern)
67
+ uri === @pattern
68
68
  elsif @pattern.is_a?(Regexp)
69
69
  WebMock::Util::URI.variations_of_uri_as_strings(uri).any? { |u| u.match(@pattern) }
70
70
  else
@@ -17,7 +17,7 @@ module WebMock
17
17
  uri = 'http://' + uri unless uri.match('^https?://') if uri.is_a?(String)
18
18
  normalized_uri = Addressable::URI.heuristic_parse(uri)
19
19
  normalized_uri.query_values = Hash[*normalized_uri.query_values.sort.flatten] if normalized_uri.query_values
20
- normalized_uri.normalize!
20
+ normalized_uri = normalized_uri.normalize #normalize! is slower
21
21
  normalized_uri.port = normalized_uri.inferred_port unless normalized_uri.port
22
22
  normalized_uri
23
23
  end
@@ -26,20 +26,20 @@ module WebMock
26
26
  normalized_uri = normalize_uri(uri_object.dup).freeze
27
27
  uris = [ normalized_uri ]
28
28
 
29
+ if normalized_uri.path == '/'
30
+ uris = uris_with_trailing_slash_and_without(uris)
31
+ end
32
+
33
+ uris = uris_encoded_and_unencoded(uris)
34
+
29
35
  if normalized_uri.port == Addressable::URI.port_mapping[normalized_uri.scheme]
30
36
  uris = uris_with_inferred_port_and_without(uris)
31
37
  end
32
-
38
+
33
39
  if normalized_uri.scheme == "http"
34
40
  uris = uris_with_scheme_and_without(uris)
35
41
  end
36
42
 
37
- if normalized_uri.path == '/'
38
- uris = uris_with_trailing_slash_and_without(uris)
39
- end
40
-
41
- uris = uris_encoded_and_unencoded(uris)
42
-
43
43
  uris.map {|uri| uri.to_s.gsub(/^\/\//,'') }.uniq
44
44
  end
45
45
 
@@ -58,17 +58,17 @@ module WebMock
58
58
  private
59
59
 
60
60
  def self.uris_with_inferred_port_and_without(uris)
61
- uris.map { |uri| [ uri, uri.omit(:port).freeze ] }.flatten
61
+ uris.map { |uri| [ uri, uri.gsub(%r{(:80)|(:443)}, "").freeze ] }.flatten
62
62
  end
63
63
 
64
64
  def self.uris_encoded_and_unencoded(uris)
65
65
  uris.map do |uri|
66
- [ uri, Addressable::URI.heuristic_parse(Addressable::URI.unencode(uri)).freeze ]
66
+ [ uri.to_s, Addressable::URI.unencode(uri, String).freeze ]
67
67
  end.flatten
68
68
  end
69
69
 
70
70
  def self.uris_with_scheme_and_without(uris)
71
- uris.map { |uri| [ uri, uri.omit(:scheme).freeze ] }.flatten
71
+ uris.map { |uri| [ uri, uri.gsub(%r{^https?://},"").freeze ] }.flatten
72
72
  end
73
73
 
74
74
  def self.uris_with_trailing_slash_and_without(uris)
@@ -44,7 +44,7 @@ module WebMock
44
44
  uri = WebMock::Util::URI.normalize_uri(uri)
45
45
  end
46
46
  Config.instance.allow_net_connect ||
47
- (Config.instance.allow_localhost && uri.is_a?(Addressable::URI) && uri.host == 'localhost')
47
+ (Config.instance.allow_localhost && uri.is_a?(Addressable::URI) && (uri.host == 'localhost' || uri.host == '127.0.0.1'))
48
48
  end
49
49
 
50
50
  def registered_request?(request_signature)
data/spec/benchmark.rb ADDED
@@ -0,0 +1,63 @@
1
+ require 'rubygems'
2
+ require 'benchmark'
3
+ require 'net/http'
4
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
5
+
6
+ def http_request
7
+ res = Net::HTTP.get_response(URI.parse('http://example.com'))
8
+ raise "Body should be 'Hello'" unless res.body == 'Hello'
9
+ end
10
+
11
+ # def fakeweb
12
+ # FakeWeb.register_uri(:get, 'http://example.com', :body => 'Hello')
13
+ # yield
14
+ # ensure
15
+ # FakeWeb.clean_registry
16
+ # end
17
+
18
+ def webmock
19
+ WebMock.stub_request(:get, %r{http://example.com}).to_return(:body => 'Hello')
20
+ yield
21
+ ensure
22
+ WebMock.reset_webmock
23
+ end
24
+
25
+ def perform_benchmark(name)
26
+ puts "\n\nBenchmarking #{name}:"
27
+ Benchmark.benchmark do |b|
28
+ %w(webmock).each do |type|
29
+ b.report(type) do
30
+ # this is a bit convoluted, but we want to ensure that each benchmark runs without the other library loaded,
31
+ # so we fork off a sub-process before requiring the libraries.
32
+ Process.fork do
33
+ require type
34
+ yield type
35
+ end
36
+ Process.wait
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ n = 5000 #*2*2
43
+ # uri = Addressable::URI.heuristic_parse("http://www.example.com")
44
+ perform_benchmark("Single setup/teardown") do |type|
45
+ send(type) { n.times { http_request } }
46
+ # (2*n).times { WebMock::Util::URI.normalize_uri("http://www.example.com") }
47
+ end
48
+
49
+ perform_benchmark("Setup/teardown for each http request") do |type|
50
+ n.times { send(type) { http_request } }
51
+ # WebMock::Util::URI.normalize_uri("http://www.example.com")
52
+ end
53
+
54
+ # Output on my machine:
55
+ #
56
+ # Benchmarking Single setup/teardown:
57
+ # webmock 0.000000 0.000000 18.830000 ( 19.350281)
58
+ # fakeweb 0.000000 0.000000 1.930000 ( 2.049569)
59
+ #
60
+ #
61
+ # Benchmarking Setup/teardown for each http request:
62
+ # webmock 0.000000 0.000000 21.350000 ( 21.795557)
63
+ # fakeweb 0.000000 0.000000 2.490000 ( 2.707574)
data/spec/webmock_spec.rb CHANGED
@@ -84,11 +84,17 @@ describe "WebMock", :shared => true do
84
84
  }.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string("Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/"))
85
85
  end
86
86
 
87
- it "should allow a real request localhost" do
87
+ it "should allow a real request to localhost" do
88
88
  lambda {
89
89
  http_request(:get, "http://localhost:12345/")
90
90
  }.should raise_error(connection_refused_exception_class)
91
91
  end
92
+
93
+ it "should allow a real request to 127.0.0.1" do
94
+ lambda {
95
+ http_request(:get, "http://127.0.0.1:12345/")
96
+ }.should raise_error(connection_refused_exception_class)
97
+ end
92
98
  end
93
99
  end
94
100
 
data/webmock.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{webmock}
8
- s.version = "1.1.0"
8
+ s.version = "1.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bartosz Blimke"]
12
- s.date = %q{2010-04-28}
12
+ s.date = %q{2010-05-14}
13
13
  s.description = %q{WebMock allows stubbing HTTP requests and setting expectations on HTTP requests.}
14
14
  s.email = %q{bartosz.blimke@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -83,10 +83,11 @@ Gem::Specification.new do |s|
83
83
  s.homepage = %q{http://github.com/bblimke/webmock}
84
84
  s.rdoc_options = ["--charset=UTF-8"]
85
85
  s.require_paths = ["lib"]
86
- s.rubygems_version = %q{1.3.5}
86
+ s.rubygems_version = %q{1.3.6}
87
87
  s.summary = %q{Library for stubbing HTTP requests in Ruby.}
88
88
  s.test_files = [
89
- "spec/httpclient_spec.rb",
89
+ "spec/benchmark.rb",
90
+ "spec/httpclient_spec.rb",
90
91
  "spec/httpclient_spec_helper.rb",
91
92
  "spec/net_http_spec.rb",
92
93
  "spec/net_http_spec_helper.rb",
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webmock
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 2
8
+ - 0
9
+ version: 1.2.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Bartosz Blimke
@@ -9,49 +14,66 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-04-28 00:00:00 +01:00
17
+ date: 2010-05-14 00:00:00 +01:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: addressable
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 1
30
+ - 1
23
31
  version: 2.1.1
24
- version:
32
+ type: :runtime
33
+ version_requirements: *id001
25
34
  - !ruby/object:Gem::Dependency
26
35
  name: rspec
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
30
38
  requirements:
31
39
  - - ">="
32
40
  - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 2
44
+ - 9
33
45
  version: 1.2.9
34
- version:
46
+ type: :development
47
+ version_requirements: *id002
35
48
  - !ruby/object:Gem::Dependency
36
49
  name: httpclient
37
- type: :development
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
40
52
  requirements:
41
53
  - - ">="
42
54
  - !ruby/object:Gem::Version
55
+ segments:
56
+ - 2
57
+ - 1
58
+ - 5
59
+ - 2
43
60
  version: 2.1.5.2
44
- version:
61
+ type: :development
62
+ version_requirements: *id003
45
63
  - !ruby/object:Gem::Dependency
46
64
  name: patron
47
- type: :development
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
65
+ prerelease: false
66
+ requirement: &id004 !ruby/object:Gem::Requirement
50
67
  requirements:
51
68
  - - ">="
52
69
  - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ - 4
73
+ - 5
53
74
  version: 0.4.5
54
- version:
75
+ type: :development
76
+ version_requirements: *id004
55
77
  description: WebMock allows stubbing HTTP requests and setting expectations on HTTP requests.
56
78
  email: bartosz.blimke@gmail.com
57
79
  executables: []
@@ -137,22 +159,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
159
  requirements:
138
160
  - - ">="
139
161
  - !ruby/object:Gem::Version
162
+ segments:
163
+ - 0
140
164
  version: "0"
141
- version:
142
165
  required_rubygems_version: !ruby/object:Gem::Requirement
143
166
  requirements:
144
167
  - - ">="
145
168
  - !ruby/object:Gem::Version
169
+ segments:
170
+ - 0
146
171
  version: "0"
147
- version:
148
172
  requirements: []
149
173
 
150
174
  rubyforge_project:
151
- rubygems_version: 1.3.5
175
+ rubygems_version: 1.3.6
152
176
  signing_key:
153
177
  specification_version: 3
154
178
  summary: Library for stubbing HTTP requests in Ruby.
155
179
  test_files:
180
+ - spec/benchmark.rb
156
181
  - spec/httpclient_spec.rb
157
182
  - spec/httpclient_spec_helper.rb
158
183
  - spec/net_http_spec.rb