webmock 1.9.0 → 1.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -0
- data/CHANGELOG.md +38 -0
- data/README.md +8 -1
- data/lib/webmock/http_lib_adapters/excon_adapter.rb +8 -1
- data/lib/webmock/http_lib_adapters/net_http.rb +1 -1
- data/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb +1 -1
- data/lib/webmock/minitest.rb +9 -0
- data/lib/webmock/rack_response.rb +1 -0
- data/lib/webmock/util/hash_counter.rb +8 -3
- data/lib/webmock/version.rb +1 -1
- data/minitest/test_webmock.rb +1 -0
- data/minitest/webmock_spec.rb +11 -0
- data/spec/acceptance/em_http_request/em_http_request_spec.rb +2 -2
- data/spec/acceptance/excon/excon_spec.rb +5 -1
- data/spec/acceptance/shared/callbacks.rb +2 -2
- data/spec/acceptance/shared/complex_cross_concern_behaviors.rb +1 -1
- data/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb +1 -1
- data/spec/support/my_rack_app.rb +4 -1
- data/spec/unit/rack_response_spec.rb +18 -0
- data/test/shared_test.rb +1 -1
- data/webmock.gemspec +2 -1
- metadata +10 -10
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,43 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.9.1
|
4
|
+
|
5
|
+
* Fix 'rack.errors' not being set for Rack apps
|
6
|
+
|
7
|
+
Thanks to [Alex Grant](https://github.com/grantovich)
|
8
|
+
|
9
|
+
* Added support for minitest assertions count
|
10
|
+
|
11
|
+
Thanks to [Mokevnin Kirill](https://github.com/mokevnin)
|
12
|
+
|
13
|
+
* Fixed issues with registering http requests in multi-threaded environments
|
14
|
+
|
15
|
+
Thanks to [Travis Beauvais](https://github.com/tbeauvais)
|
16
|
+
|
17
|
+
* Bumped Crack version to >=0.3.2
|
18
|
+
|
19
|
+
Thanks to [Jake Benilov](https://github.com/benilovj)
|
20
|
+
|
21
|
+
* Fixed issues in Typhoeus 0.6. Defaulted method to GET when no method specified.
|
22
|
+
|
23
|
+
Thanks to [Hans Hasselberg](https://github.com/i0rek)
|
24
|
+
|
25
|
+
* Add license information to the gemspec
|
26
|
+
|
27
|
+
Thanks to [Jordi Massaguer Pla](https://github.com/jordimassaguerpla) and [Murahashi Sanemat Kenichi](https://github.com/sanemat)
|
28
|
+
|
29
|
+
* Added support for :expects option in Excon adapter
|
30
|
+
|
31
|
+
Thanks to [Evgeniy Dolzhenko](https://github.com/dolzenko)
|
32
|
+
|
33
|
+
* Fixed Faye compatibility by treating StringIO in Net::HTTP adapter properly
|
34
|
+
|
35
|
+
Thanks to [Pavel Forkert](https://github.com/fxposter)
|
36
|
+
|
37
|
+
* Updated VCR link
|
38
|
+
|
39
|
+
Thanks to [Rex Feng](https://github.com/xta)
|
40
|
+
|
3
41
|
## 1.9.0
|
4
42
|
|
5
43
|
* Added support for Typhoeus >= 0.5.0 and removed support for Typhoeus < 0.5.0.
|
data/README.md
CHANGED
@@ -565,7 +565,7 @@ i.e the following two sets of headers are equal:
|
|
565
565
|
|
566
566
|
## Recording real requests and responses and replaying them later
|
567
567
|
|
568
|
-
To record your application's real HTTP interactions and replay them later in tests you can use [VCR](
|
568
|
+
To record your application's real HTTP interactions and replay them later in tests you can use [VCR](https://github.com/vcr/vcr) with WebMock.
|
569
569
|
|
570
570
|
## Request callbacks
|
571
571
|
|
@@ -714,6 +714,13 @@ People who submitted patches and new features or suggested improvements. Many th
|
|
714
714
|
* Hans Hasselberg
|
715
715
|
* Andrew France
|
716
716
|
* Jonathan Hyman
|
717
|
+
* Rex Feng
|
718
|
+
* Pavel Forkert
|
719
|
+
* Jordi Massaguer Pla
|
720
|
+
* Jake Benilov
|
721
|
+
* Travis Beauvais
|
722
|
+
* Mokevnin Kirill
|
723
|
+
* Alex Grant
|
717
724
|
|
718
725
|
For a full list of contributors you can visit the
|
719
726
|
[contributors](https://github.com/bblimke/webmock/contributors) page.
|
@@ -87,7 +87,14 @@ if defined?(Excon)
|
|
87
87
|
|
88
88
|
if mock_response = WebMock::StubRegistry.instance.response_for_request(mock_request)
|
89
89
|
ExconAdapter.perform_callbacks(mock_request, mock_response, :real_request => false)
|
90
|
-
ExconAdapter.real_response(mock_response)
|
90
|
+
response = ExconAdapter.real_response(mock_response)
|
91
|
+
|
92
|
+
if params.has_key?(:expects) && ![*params[:expects]].include?(response.status)
|
93
|
+
raise(Excon::Errors.status_error(params, response))
|
94
|
+
else
|
95
|
+
response
|
96
|
+
end
|
97
|
+
|
91
98
|
elsif WebMock.net_connect_allowed?(mock_request.uri)
|
92
99
|
real_response = super
|
93
100
|
ExconAdapter.perform_callbacks(mock_request, ExconAdapter.mock_response(real_response), :real_request => true)
|
data/lib/webmock/minitest.rb
CHANGED
@@ -10,6 +10,15 @@ MiniTest::Unit::TestCase.class_eval do
|
|
10
10
|
WebMock.reset!
|
11
11
|
end
|
12
12
|
alias_method :teardown, :teardown_with_webmock
|
13
|
+
|
14
|
+
[:assert_request_requested, :assert_request_not_requested].each do |name|
|
15
|
+
alias_method :"#{name}_without_assertions_count", name
|
16
|
+
define_method :"#{name}_with_assertions_count" do |*args|
|
17
|
+
self._assertions += 1
|
18
|
+
send :"#{name}_without_assertions_count", *args
|
19
|
+
end
|
20
|
+
alias_method name, :"#{name}_with_assertions_count"
|
21
|
+
end
|
13
22
|
end
|
14
23
|
|
15
24
|
WebMock::AssertionFailure.error_class = MiniTest::Assertion
|
@@ -6,13 +6,18 @@ module WebMock
|
|
6
6
|
self.hash = {}
|
7
7
|
@order = {}
|
8
8
|
@max = 0
|
9
|
+
@lock = Mutex.new
|
9
10
|
end
|
10
11
|
def put key, num=1
|
11
|
-
|
12
|
-
|
12
|
+
@lock.synchronize do
|
13
|
+
hash[key] = (hash[key] || 0) + num
|
14
|
+
@order[key] = @max = @max + 1
|
15
|
+
end
|
13
16
|
end
|
14
17
|
def get key
|
15
|
-
|
18
|
+
@lock.synchronize do
|
19
|
+
hash[key] || 0
|
20
|
+
end
|
16
21
|
end
|
17
22
|
|
18
23
|
def each(&block)
|
data/lib/webmock/version.rb
CHANGED
data/minitest/test_webmock.rb
CHANGED
data/minitest/webmock_spec.rb
CHANGED
@@ -8,6 +8,17 @@ require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
|
8
8
|
@stub_https = stub_http_request(:any, "https://www.example.com")
|
9
9
|
end
|
10
10
|
|
11
|
+
it "should update assertions count" do
|
12
|
+
assert_equal 0, _assertions
|
13
|
+
http_request(:get, "http://www.example.com/")
|
14
|
+
|
15
|
+
assert_requested(@stub_http)
|
16
|
+
assert_equal 2, _assertions
|
17
|
+
|
18
|
+
assert_not_requested(:post, "http://www.example.com")
|
19
|
+
assert_equal 4, _assertions
|
20
|
+
end
|
21
|
+
|
11
22
|
it "should raise error on non stubbed request" do
|
12
23
|
lambda { http_request(:get, "http://www.example.net/") }.must_raise(WebMock::NetConnectNotAllowedError)
|
13
24
|
end
|
@@ -13,7 +13,7 @@ unless RUBY_PLATFORM =~ /java/
|
|
13
13
|
|
14
14
|
#functionality only supported for em-http-request 1.x
|
15
15
|
if defined?(EventMachine::HttpConnection)
|
16
|
-
context 'when a real request is made and redirects are followed' do
|
16
|
+
context 'when a real request is made and redirects are followed', :net_connect => true do
|
17
17
|
before { WebMock.allow_net_connect! }
|
18
18
|
|
19
19
|
# This url redirects to the https URL.
|
@@ -116,7 +116,7 @@ unless RUBY_PLATFORM =~ /java/
|
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
|
-
context 'making a real request' do
|
119
|
+
context 'making a real request', :net_connect => true do
|
120
120
|
before { WebMock.allow_net_connect! }
|
121
121
|
include_examples "em-http-request middleware/after_request hook integration"
|
122
122
|
end
|
@@ -11,6 +11,11 @@ describe "Excon" do
|
|
11
11
|
Excon.get('http://example.com', :path => "resource/", :query => {:a => 1, :b => 2}).body.should == "abc"
|
12
12
|
end
|
13
13
|
|
14
|
+
it 'should support Excon :expects options' do
|
15
|
+
stub_request(:get, "http://example.com/").to_return(:body => 'a')
|
16
|
+
lambda { Excon.get('http://example.com', :expects => 204) }.should raise_error(Excon::Errors::OK)
|
17
|
+
end
|
18
|
+
|
14
19
|
let(:file) { File.new(__FILE__) }
|
15
20
|
let(:file_contents) { File.new(__FILE__).read }
|
16
21
|
|
@@ -27,4 +32,3 @@ describe "Excon" do
|
|
27
32
|
yielded_request_body.should eq(file_contents)
|
28
33
|
end
|
29
34
|
end
|
30
|
-
|
@@ -68,7 +68,7 @@ shared_context "callbacks" do |*adapter_info|
|
|
68
68
|
before(:each) do
|
69
69
|
stub_request(:get, "http://www.example.com").
|
70
70
|
to_return(
|
71
|
-
:status => [
|
71
|
+
:status => [200, "hello"],
|
72
72
|
:headers => {'Content-Length' => '666', 'Hello' => 'World'},
|
73
73
|
:body => "foo bar"
|
74
74
|
)
|
@@ -79,7 +79,7 @@ shared_context "callbacks" do |*adapter_info|
|
|
79
79
|
end
|
80
80
|
|
81
81
|
it "should pass response to callback with the status and message" do
|
82
|
-
@response.status.should == [
|
82
|
+
@response.status.should == [200, "hello"]
|
83
83
|
end
|
84
84
|
|
85
85
|
it "should pass response to callback with headers" do
|
@@ -20,7 +20,7 @@ shared_context "complex cross-concern behaviors" do |*adapter_info|
|
|
20
20
|
|
21
21
|
let(:no_content_url) { 'http://httpstat.us/204' }
|
22
22
|
[nil, ''].each do |stub_val|
|
23
|
-
it "returns the same value (nil or "") for a request stubbed as #{stub_val.inspect} that a real empty response has" do
|
23
|
+
it "returns the same value (nil or "") for a request stubbed as #{stub_val.inspect} that a real empty response has", :net_connect => true do
|
24
24
|
unless http_library == :curb
|
25
25
|
WebMock.allow_net_connect!
|
26
26
|
|
@@ -22,7 +22,7 @@ unless RUBY_PLATFORM =~ /java/
|
|
22
22
|
|
23
23
|
describe "when params are used" do
|
24
24
|
it "should take into account params for POST request" do
|
25
|
-
stub_request(:post, "www.example.com").with(:params => {:hello => 'world'})
|
25
|
+
stub_request(:post, "www.example.com/?hello=world").with(:params => {:hello => 'world'})
|
26
26
|
request = Typhoeus::Request.new("http://www.example.com", :method => :post, :params => {:hello => 'world'})
|
27
27
|
hydra.queue(request)
|
28
28
|
hydra.run
|
data/spec/support/my_rack_app.rb
CHANGED
@@ -2,7 +2,7 @@ require 'rack'
|
|
2
2
|
|
3
3
|
class MyRackApp
|
4
4
|
class NonArrayResponse
|
5
|
-
# The rack response body need not implement #join,
|
5
|
+
# The rack response body need not implement #join,
|
6
6
|
# but it must implement #each. It need not be an Array.
|
7
7
|
# ActionDispatch::Response, for example, exercises that fact.
|
8
8
|
# See: http://rack.rubyforge.org/doc/SPEC.html
|
@@ -32,6 +32,9 @@ class MyRackApp
|
|
32
32
|
else
|
33
33
|
[401, {}, [""]]
|
34
34
|
end
|
35
|
+
when ['GET', '/error']
|
36
|
+
env['rack.errors'].puts('Error!')
|
37
|
+
[500, {}, ['']]
|
35
38
|
else
|
36
39
|
[404, {}, ['']]
|
37
40
|
end
|
@@ -49,6 +49,24 @@ describe WebMock::RackResponse do
|
|
49
49
|
response.body.should include('Good to meet you, Jimmy!')
|
50
50
|
end
|
51
51
|
|
52
|
+
describe 'rack error output' do
|
53
|
+
before :each do
|
54
|
+
@original_stderr = $stderr
|
55
|
+
$stderr = StringIO.new
|
56
|
+
end
|
57
|
+
|
58
|
+
after :each do
|
59
|
+
$stderr = @original_stderr
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should behave correctly when an app uses rack.errors' do
|
63
|
+
request = WebMock::RequestSignature.new(:get, 'www.example.com/error')
|
64
|
+
|
65
|
+
expect { @rack_response.evaluate(request) }.to_not raise_error
|
66
|
+
expect($stderr.length).to_not eq 0
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
52
70
|
describe 'basic auth request' do
|
53
71
|
before :each do
|
54
72
|
@rack_response_with_basic_auth = WebMock::RackResponse.new(
|
data/test/shared_test.rb
CHANGED
data/webmock.gemspec
CHANGED
@@ -11,11 +11,12 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.homepage = 'http://github.com/bblimke/webmock'
|
12
12
|
s.summary = %q{Library for stubbing HTTP requests in Ruby.}
|
13
13
|
s.description = %q{WebMock allows stubbing HTTP requests and setting expectations on HTTP requests.}
|
14
|
+
s.license = "MIT"
|
14
15
|
|
15
16
|
s.rubyforge_project = 'webmock'
|
16
17
|
|
17
18
|
s.add_dependency 'addressable', '>= 2.2.7'
|
18
|
-
s.add_dependency 'crack', '>=0.
|
19
|
+
s.add_dependency 'crack', '>=0.3.2'
|
19
20
|
|
20
21
|
s.add_development_dependency 'rspec', '~> 2.10'
|
21
22
|
s.add_development_dependency 'httpclient', '>= 2.2.4'
|
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:
|
4
|
+
hash: 49
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 1.9.
|
9
|
+
- 1
|
10
|
+
version: 1.9.1
|
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:
|
18
|
+
date: 2013-02-17 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: addressable
|
@@ -40,12 +40,12 @@ dependencies:
|
|
40
40
|
requirements:
|
41
41
|
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
hash:
|
43
|
+
hash: 23
|
44
44
|
segments:
|
45
45
|
- 0
|
46
|
-
-
|
47
|
-
-
|
48
|
-
version: 0.
|
46
|
+
- 3
|
47
|
+
- 2
|
48
|
+
version: 0.3.2
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
requirement: *id002
|
@@ -318,8 +318,8 @@ files:
|
|
318
318
|
- test/test_webmock.rb
|
319
319
|
- webmock.gemspec
|
320
320
|
homepage: http://github.com/bblimke/webmock
|
321
|
-
licenses:
|
322
|
-
|
321
|
+
licenses:
|
322
|
+
- MIT
|
323
323
|
post_install_message:
|
324
324
|
rdoc_options: []
|
325
325
|
|