webmock 1.9.0 → 1.9.1

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.
@@ -2,6 +2,7 @@ rvm:
2
2
  - 1.8.7
3
3
  - 1.9.2
4
4
  - 1.9.3
5
+ - 2.0.0
5
6
  - ree
6
7
  - jruby-19mode
7
8
  - jruby-18mode
@@ -9,6 +10,7 @@ rvm:
9
10
  - rbx-19mode
10
11
  matrix:
11
12
  allow_failures:
13
+ - rvm: 2.0.0
12
14
  - rvm: rbx-18mode
13
15
  - rvm: rbx-19mode
14
16
  - rvm: jruby-19mode
@@ -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](http://github.com/myronmarston/vcr) with WebMock.
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)
@@ -216,7 +216,7 @@ module Net #:nodoc: all
216
216
  @debug_output = debug_output
217
217
 
218
218
  @io = case io
219
- when Socket, OpenSSL::SSL::SSLSocket, IO
219
+ when Socket, OpenSSL::SSL::SSLSocket, IO, StringIO
220
220
  io
221
221
  when String
222
222
  StringIO.new(io)
@@ -60,7 +60,7 @@ if defined?(Typhoeus)
60
60
  body = req.options[:body]
61
61
 
62
62
  request_signature = WebMock::RequestSignature.new(
63
- req.options[:method],
63
+ req.options[:method] || :get,
64
64
  uri.to_s,
65
65
  :body => body,
66
66
  :headers => req.options[:headers]
@@ -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
@@ -44,6 +44,7 @@ module WebMock
44
44
 
45
45
  # Rack-specific variables
46
46
  env['rack.input'] = StringIO.new(body)
47
+ env['rack.errors'] = $stderr
47
48
  env['rack.version'] = Rack::VERSION
48
49
  env['rack.url_scheme'] = uri.scheme
49
50
  env['rack.run_once'] = true
@@ -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
- hash[key] = (hash[key] || 0) + num
12
- @order[key] = @max = @max + 1
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
- hash[key] || 0
18
+ @lock.synchronize do
19
+ hash[key] || 0
20
+ end
16
21
  end
17
22
 
18
23
  def each(&block)
@@ -1,3 +1,3 @@
1
1
  module WebMock
2
- VERSION = '1.9.0' unless defined?(::WebMock::VERSION)
2
+ VERSION = '1.9.1' unless defined?(::WebMock::VERSION)
3
3
  end
@@ -3,4 +3,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../test/shared_test')
3
3
 
4
4
  class MiniTestWebMock < MiniTest::Unit::TestCase
5
5
  include SharedTest
6
+
6
7
  end
@@ -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 => ["200", "hello"],
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 == ["200", "hello"]
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
@@ -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(
@@ -73,4 +73,4 @@ module SharedTest
73
73
  assert_not_requested(@stub_http)
74
74
  end
75
75
  end
76
- end
76
+ end
@@ -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.1.7'
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: 51
4
+ hash: 49
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 9
9
- - 0
10
- version: 1.9.0
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: 2012-11-07 00:00:00 Z
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: 21
43
+ hash: 23
44
44
  segments:
45
45
  - 0
46
- - 1
47
- - 7
48
- version: 0.1.7
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