webmock 1.12.3 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.13.0
4
+
5
+ * Net::HTTP::Persistent compatibility.
6
+ WebMock doesn't disconnect previously started connections upon a request anymore.
7
+
8
+
3
9
  ## 1.12.3
4
10
 
5
11
  * Fixed issue with handling Addressable::URI with query params passed to `Net::HTTP.get_response`
@@ -93,15 +93,22 @@ module WebMock
93
93
  block.call response if block
94
94
  response
95
95
  end
96
- response = if (started? && !WebMock::Config.instance.net_http_connect_on_start) || !started?
97
- @started = false #otherwise start_with_connect wouldn't execute and connect
98
- start_with_connect {
99
- response = super(request, nil, &nil)
100
- after_request.call(response)
101
- }
102
- else
96
+ super_with_after_request = lambda {
103
97
  response = super(request, nil, &nil)
104
98
  after_request.call(response)
99
+ }
100
+ response = if started?
101
+ if WebMock::Config.instance.net_http_connect_on_start
102
+ super_with_after_request.call
103
+ else
104
+ start_with_connect_without_finish {
105
+ super_with_after_request.call
106
+ }
107
+ end
108
+ else
109
+ start_with_connect {
110
+ super_with_after_request.call
111
+ }
105
112
  end
106
113
  else
107
114
  raise WebMock::NetConnectNotAllowedError.new(request_signature)
@@ -122,6 +129,18 @@ module WebMock
122
129
  self
123
130
  end
124
131
 
132
+
133
+ def start_with_connect_without_finish # :yield: http
134
+ if block_given?
135
+ begin
136
+ do_start
137
+ return yield(self)
138
+ end
139
+ end
140
+ do_start
141
+ self
142
+ end
143
+
125
144
  alias_method :start_with_connect, :start
126
145
 
127
146
  def start(&block)
@@ -1,3 +1,3 @@
1
1
  module WebMock
2
- VERSION = '1.12.3' unless defined?(::WebMock::VERSION)
2
+ VERSION = '1.13.0' unless defined?(::WebMock::VERSION)
3
3
  end
@@ -61,7 +61,7 @@ describe "HTTPClient" do
61
61
  }
62
62
  ]}
63
63
 
64
- let(:make_request) {HTTPClient.new.post("http://www.example.com", body: body, header: header)}
64
+ let(:make_request) {HTTPClient.new.post("http://www.example.com", :body => body, :header => header)}
65
65
 
66
66
  before do
67
67
  stub_request(:post, "www.example.com")
@@ -32,8 +32,15 @@ shared_examples_for "Net::HTTP" do
32
32
  conn.request(Net::HTTP::Get.new("/"))
33
33
  socket_id_after_request = conn.instance_variable_get(:@socket).object_id
34
34
  }
35
- socket_id_after_request.should_not be_nil
36
- socket_id_after_request.should == socket_id_before_request
35
+
36
+ if !defined?(WebMock::Config) || WebMock::Config.instance.net_http_connect_on_start
37
+ socket_id_before_request.should_not == nil.object_id
38
+ socket_id_after_request.should_not == nil.object_id
39
+ socket_id_after_request.should == socket_id_before_request
40
+ else
41
+ socket_id_before_request.should == nil.object_id
42
+ socket_id_after_request.should_not == nil.object_id
43
+ end
37
44
  end
38
45
 
39
46
  describe "without start" do
@@ -121,5 +128,15 @@ shared_examples_for "Net::HTTP" do
121
128
  @http.started?.should == false
122
129
  end
123
130
  end
131
+
132
+ describe "with start without a block and finish" do
133
+ it "should gracefully start and close connection" do
134
+ @http.start
135
+ @http.get("/")
136
+ @http.should be_started
137
+ @http.finish
138
+ @http.should_not be_started
139
+ end
140
+ end
124
141
  end
125
- end
142
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webmock
3
3
  version: !ruby/object:Gem::Version
4
- hash: 33
4
+ hash: 35
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 12
9
- - 3
10
- version: 1.12.3
8
+ - 13
9
+ - 0
10
+ version: 1.13.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bartosz Blimke
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-06-28 00:00:00 Z
18
+ date: 2013-07-05 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: addressable