webmock 1.6.4 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/.gitignore +3 -1
- data/.travis.yml +6 -0
- data/CHANGELOG.md +211 -118
- data/Gemfile +16 -1
- data/Guardfile +24 -0
- data/LICENSE +1 -1
- data/README.md +64 -15
- data/Rakefile +19 -6
- data/lib/webmock.rb +9 -4
- data/lib/webmock/api.rb +5 -4
- data/lib/webmock/assertion_failure.rb +1 -1
- data/lib/webmock/callback_registry.rb +1 -1
- data/lib/webmock/config.rb +2 -2
- data/lib/webmock/cucumber.rb +1 -1
- data/lib/webmock/errors.rb +17 -5
- data/lib/webmock/http_lib_adapters/{curb.rb → curb_adapter.rb} +79 -49
- data/lib/webmock/http_lib_adapters/{em_http_request.rb → em_http_request/em_http_request_0_x.rb} +20 -15
- data/lib/webmock/http_lib_adapters/em_http_request/em_http_request_1_x.rb +201 -0
- data/lib/webmock/http_lib_adapters/em_http_request_adapter.rb +11 -0
- data/lib/webmock/http_lib_adapters/http_lib_adapter.rb +7 -0
- data/lib/webmock/http_lib_adapters/http_lib_adapter_registry.rb +19 -0
- data/lib/webmock/http_lib_adapters/{httpclient.rb → httpclient_adapter.rb} +35 -8
- data/lib/webmock/http_lib_adapters/net_http.rb +84 -25
- data/lib/webmock/http_lib_adapters/net_http_response.rb +17 -17
- data/lib/webmock/http_lib_adapters/patron_adapter.rb +124 -0
- data/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb +166 -0
- data/lib/webmock/minitest.rb +15 -0
- data/lib/webmock/rack_response.rb +52 -0
- data/lib/webmock/request_pattern.rb +4 -2
- data/lib/webmock/request_signature.rb +4 -0
- data/lib/webmock/request_stub.rb +35 -2
- data/lib/webmock/responses_sequence.rb +2 -2
- data/lib/webmock/rspec.rb +2 -2
- data/lib/webmock/rspec/matchers.rb +9 -4
- data/lib/webmock/rspec/matchers/webmock_matcher.rb +1 -1
- data/lib/webmock/stub_registry.rb +1 -1
- data/lib/webmock/stub_request_snippet.rb +14 -11
- data/lib/webmock/util/hash_keys_stringifier.rb +4 -4
- data/lib/webmock/util/headers.rb +3 -3
- data/lib/webmock/util/json.rb +54 -0
- data/lib/webmock/util/uri.rb +1 -1
- data/lib/webmock/version.rb +1 -1
- data/lib/webmock/webmock.rb +20 -3
- data/minitest/test_helper.rb +29 -0
- data/minitest/test_webmock.rb +6 -0
- data/minitest/webmock_spec.rb +30 -0
- data/spec/curb_spec.rb +26 -8
- data/spec/curb_spec_helper.rb +6 -6
- data/spec/em_http_request_spec.rb +95 -1
- data/spec/em_http_request_spec_helper.rb +16 -16
- data/spec/errors_spec.rb +19 -4
- data/spec/example_curl_output.txt +22 -22
- data/spec/http_lib_adapters/http_lib_adapter_registry_spec.rb +17 -0
- data/spec/http_lib_adapters/http_lib_adapter_spec.rb +12 -0
- data/spec/httpclient_spec.rb +1 -1
- data/spec/httpclient_spec_helper.rb +3 -38
- data/spec/my_rack_app.rb +18 -0
- data/spec/net_http_shared.rb +125 -0
- data/spec/net_http_spec.rb +27 -31
- data/spec/net_http_spec_helper.rb +4 -34
- data/spec/network_connection.rb +1 -1
- data/spec/patron_spec_helper.rb +4 -7
- data/spec/quality_spec.rb +60 -0
- data/spec/rack_response_spec.rb +33 -0
- data/spec/real_net_http_spec.rb +20 -0
- data/spec/request_execution_verifier_spec.rb +8 -8
- data/spec/request_pattern_spec.rb +3 -3
- data/spec/request_stub_spec.rb +19 -19
- data/spec/response_spec.rb +8 -8
- data/spec/spec_helper.rb +14 -11
- data/spec/stub_request_snippet_spec.rb +85 -37
- data/spec/support/webmock_server.rb +62 -0
- data/spec/typhoeus_hydra_spec.rb +53 -0
- data/spec/typhoeus_hydra_spec_helper.rb +50 -0
- data/spec/util/headers_spec.rb +5 -5
- data/spec/util/json_spec.rb +7 -0
- data/spec/util/uri_spec.rb +1 -1
- data/spec/vendor/addressable/lib/uri.rb +1 -0
- data/spec/vendor/crack/lib/crack.rb +1 -0
- data/spec/vendor/right_http_connection-1.2.4/History.txt +4 -4
- data/spec/vendor/right_http_connection-1.2.4/README.txt +4 -4
- data/spec/vendor/right_http_connection-1.2.4/Rakefile +3 -3
- data/spec/vendor/right_http_connection-1.2.4/lib/net_fix.rb +4 -4
- data/spec/vendor/right_http_connection-1.2.4/setup.rb +4 -4
- data/spec/webmock_shared.rb +375 -143
- data/spec/webmock_spec.rb +7 -0
- data/test/http_request.rb +24 -0
- data/test/shared_test.rb +47 -0
- data/test/test_helper.rb +6 -3
- data/test/test_webmock.rb +2 -67
- data/webmock.gemspec +8 -7
- metadata +153 -88
- data/lib/webmock/http_lib_adapters/patron.rb +0 -100
- data/spec/other_net_http_libs_spec.rb +0 -30
data/spec/net_http_spec.rb
CHANGED
@@ -2,13 +2,15 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
2
|
require 'webmock_shared'
|
3
3
|
require 'ostruct'
|
4
4
|
require 'net_http_spec_helper'
|
5
|
+
require 'net_http_shared'
|
5
6
|
|
6
7
|
include NetHTTPSpecHelper
|
7
8
|
|
8
9
|
describe "Webmock with Net:HTTP" do
|
9
|
-
|
10
10
|
it_should_behave_like "WebMock"
|
11
11
|
|
12
|
+
let(:port){ WebMockServer.instance.port }
|
13
|
+
|
12
14
|
it "should work with block provided" do
|
13
15
|
stub_http_request(:get, "www.example.com").to_return(:body => "abc"*100000)
|
14
16
|
Net::HTTP.start("www.example.com") { |query| query.get("/") }.body.should == "abc"*100000
|
@@ -52,38 +54,18 @@ describe "Webmock with Net:HTTP" do
|
|
52
54
|
}.should raise_error("both of body argument and HTTPRequest#body set")
|
53
55
|
end
|
54
56
|
|
55
|
-
it "should handle real requests with readable body", :net_connect => true do
|
56
|
-
WebMock.allow_net_connect!
|
57
|
-
req = Net::HTTP::Post.new("/")
|
58
|
-
Net::HTTP.start("www.example.com") {|http|
|
59
|
-
http.request(req, StringIO.new("my_params"))
|
60
|
-
}.body.should =~ /^$/
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should handle requests with block passed to read_body", :net_connect => true do
|
64
|
-
body = ""
|
65
|
-
WebMock.allow_net_connect!
|
66
|
-
req = Net::HTTP::Get.new("/")
|
67
|
-
Net::HTTP.start("www.example.com") do |http|
|
68
|
-
http.request(req) do |res|
|
69
|
-
res.read_body do |str|
|
70
|
-
body << str
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
body.should =~ /^$/
|
75
|
-
end
|
76
|
-
|
77
57
|
it "should return a Net::ReadAdapter from response.body when a stubbed request is made with a block and #read_body" do
|
78
58
|
WebMock.stub_request(:get, 'http://example.com/').to_return(:body => "the body")
|
79
59
|
response = Net::HTTP.new('example.com', 80).request_get('/') { |r| r.read_body { } }
|
80
60
|
response.body.should be_a(Net::ReadAdapter)
|
81
61
|
end
|
82
62
|
|
83
|
-
it "should
|
63
|
+
it "should have request 1 time executed in registry after 1 real request", :net_connect => true do
|
84
64
|
WebMock.allow_net_connect!
|
85
|
-
|
86
|
-
|
65
|
+
http = Net::HTTP.new('localhost', port)
|
66
|
+
http.get('/') {}
|
67
|
+
WebMock::RequestRegistry.instance.requested_signatures.hash.size.should == 1
|
68
|
+
WebMock::RequestRegistry.instance.requested_signatures.hash.values.first.should == 1
|
87
69
|
end
|
88
70
|
|
89
71
|
describe "connecting on Net::HTTP.start" do
|
@@ -107,6 +89,7 @@ describe "Webmock with Net:HTTP" do
|
|
107
89
|
cert.should be_a(OpenSSL::X509::Certificate)
|
108
90
|
}
|
109
91
|
end
|
92
|
+
|
110
93
|
end
|
111
94
|
|
112
95
|
describe "when net http is disabled and allowed only for some hosts" do
|
@@ -127,8 +110,22 @@ describe "Webmock with Net:HTTP" do
|
|
127
110
|
end
|
128
111
|
end
|
129
112
|
|
113
|
+
describe "when net_http_connect_on_start is true" do
|
114
|
+
before(:each) do
|
115
|
+
WebMock.allow_net_connect!(:net_http_connect_on_start => true)
|
116
|
+
end
|
117
|
+
it_should_behave_like "Net::HTTP"
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "when net_http_connect_on_start is false" do
|
121
|
+
before(:each) do
|
122
|
+
WebMock.allow_net_connect!(:net_http_connect_on_start => false)
|
123
|
+
end
|
124
|
+
it_should_behave_like "Net::HTTP"
|
125
|
+
end
|
126
|
+
|
130
127
|
describe 'after_request callback support', :net_connect => true do
|
131
|
-
let(:expected_body_regex) {
|
128
|
+
let(:expected_body_regex) { /hello world/ }
|
132
129
|
|
133
130
|
before(:each) do
|
134
131
|
WebMock.allow_net_connect!
|
@@ -144,14 +141,14 @@ describe "Webmock with Net:HTTP" do
|
|
144
141
|
end
|
145
142
|
|
146
143
|
def perform_get_with_returning_block
|
147
|
-
http_request(:get, "http://
|
144
|
+
http_request(:get, "http://localhost:#{port}/") do |response|
|
148
145
|
return response.body
|
149
146
|
end
|
150
147
|
end
|
151
148
|
|
152
149
|
it "should support the after_request callback on an request with block and read_body" do
|
153
150
|
response_body = ''
|
154
|
-
http_request(:get, "http://
|
151
|
+
http_request(:get, "http://localhost:#{port}/") do |response|
|
155
152
|
response.read_body { |fragment| response_body << fragment }
|
156
153
|
end
|
157
154
|
response_body.should =~ expected_body_regex
|
@@ -167,9 +164,8 @@ describe "Webmock with Net:HTTP" do
|
|
167
164
|
end
|
168
165
|
|
169
166
|
it "should only invoke the after_request callback once, even for a recursive post request" do
|
170
|
-
Net::HTTP.new('
|
167
|
+
Net::HTTP.new('localhost', port).post('/', nil)
|
171
168
|
@callback_invocation_count.should == 1
|
172
169
|
end
|
173
170
|
end
|
174
|
-
|
175
171
|
end
|
@@ -8,14 +8,14 @@ module NetHTTPSpecHelper
|
|
8
8
|
response = nil
|
9
9
|
clazz = Net::HTTP.const_get("#{method.to_s.capitalize}")
|
10
10
|
req = clazz.new("#{uri.path}#{uri.query ? '?' : ''}#{uri.query}", nil)
|
11
|
-
options[:headers].each do |k,v|
|
11
|
+
options[:headers].each do |k,v|
|
12
12
|
if v.is_a?(Array)
|
13
13
|
v.each_with_index do |v,i|
|
14
14
|
i == 0 ? (req[k] = v) : req.add_field(k, v)
|
15
15
|
end
|
16
16
|
else
|
17
17
|
req[k] = v
|
18
|
-
end
|
18
|
+
end
|
19
19
|
end if options[:headers]
|
20
20
|
|
21
21
|
req.basic_auth uri.user, uri.password if uri.user
|
@@ -34,11 +34,11 @@ module NetHTTPSpecHelper
|
|
34
34
|
OpenStruct.new({
|
35
35
|
:body => response.body,
|
36
36
|
:headers => WebMock::Util::Headers.normalize_headers(headers),
|
37
|
-
:status => response.code,
|
37
|
+
:status => response.code,
|
38
38
|
:message => response.message
|
39
39
|
})
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
def client_timeout_exception_class
|
43
43
|
Timeout::Error
|
44
44
|
end
|
@@ -47,36 +47,6 @@ module NetHTTPSpecHelper
|
|
47
47
|
Errno::ECONNREFUSED
|
48
48
|
end
|
49
49
|
|
50
|
-
# Sets several expectations that a real HTTP request makes it
|
51
|
-
# past WebMock to the socket layer. You can use this when you need to check
|
52
|
-
# that a request isn't handled by WebMock
|
53
|
-
#This solution is copied from FakeWeb project
|
54
|
-
def setup_expectations_for_real_request(options = {})
|
55
|
-
# Socket handling
|
56
|
-
if options[:port] == 443
|
57
|
-
socket = mock("SSLSocket")
|
58
|
-
OpenSSL::SSL::SSLSocket.should_receive(:===).with(socket).at_least(:once).and_return(true)
|
59
|
-
OpenSSL::SSL::SSLSocket.should_receive(:new).with(socket, instance_of(OpenSSL::SSL::SSLContext)).at_least(:once).and_return(socket)
|
60
|
-
socket.stub!(:sync_close=).and_return(true)
|
61
|
-
socket.should_receive(:connect).at_least(:once).with()
|
62
|
-
else
|
63
|
-
socket = mock("TCPSocket")
|
64
|
-
Socket.should_receive(:===).with(socket).at_least(:once).and_return(true)
|
65
|
-
end
|
66
|
-
|
67
|
-
TCPSocket.should_receive(:open).with(options[:host], options[:port]).at_least(:once).and_return(socket)
|
68
|
-
socket.stub!(:closed?).and_return(false)
|
69
|
-
socket.stub!(:close).and_return(true)
|
70
|
-
|
71
|
-
# Request/response handling
|
72
|
-
request_parts = ["#{options[:method]} #{options[:path]} HTTP/1.1", "Host: #{options[:host]}"]
|
73
|
-
socket.should_receive(:write).with(/#{request_parts[0]}.*#{request_parts[1]}.*/m).and_return(100)
|
74
|
-
|
75
|
-
read_method = RUBY_VERSION >= "1.9.2" ? :read_nonblock : :sysread
|
76
|
-
socket.should_receive(read_method).once.and_return("HTTP/1.1 #{options[:response_code]} #{options[:response_message]}\nContent-Length: #{options[:response_body].length}\n\n#{options[:response_body]}")
|
77
|
-
socket.should_receive(read_method).any_number_of_times.and_raise(EOFError)
|
78
|
-
end
|
79
|
-
|
80
50
|
def http_library
|
81
51
|
:net_http
|
82
52
|
end
|
data/spec/network_connection.rb
CHANGED
data/spec/patron_spec_helper.rb
CHANGED
@@ -11,15 +11,16 @@ module PatronSpecHelper
|
|
11
11
|
sess.connect_timeout = 10
|
12
12
|
sess.timeout = 10
|
13
13
|
sess.max_redirects = 0
|
14
|
-
|
15
|
-
|
14
|
+
uri = "#{uri.path}#{uri.query ? '?' : ''}#{uri.query}"
|
15
|
+
uri.gsub!(' ','+')
|
16
|
+
response = sess.request(method, uri, options[:headers] || {}, {
|
16
17
|
:data => options[:body]
|
17
18
|
})
|
18
19
|
headers = {}
|
19
20
|
if response.headers
|
20
21
|
response.headers.each do |k,v|
|
21
22
|
v = v.join(", ") if v.is_a?(Array)
|
22
|
-
headers[k] = v
|
23
|
+
headers[k] = v
|
23
24
|
end
|
24
25
|
end
|
25
26
|
OpenStruct.new({
|
@@ -38,10 +39,6 @@ module PatronSpecHelper
|
|
38
39
|
Patron::ConnectionFailed
|
39
40
|
end
|
40
41
|
|
41
|
-
def setup_expectations_for_real_request(options = {})
|
42
|
-
#TODO
|
43
|
-
end
|
44
|
-
|
45
42
|
def http_library
|
46
43
|
:patron
|
47
44
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
# Borrowed from Bundler
|
4
|
+
# https://github.com/carlhuda/bundler/blob/1-0-stable/spec/quality_spec.rb
|
5
|
+
describe "The library itself" do
|
6
|
+
def check_for_tab_characters(filename)
|
7
|
+
failing_lines = []
|
8
|
+
File.readlines(filename).each_with_index do |line,number|
|
9
|
+
failing_lines << number + 1 if line =~ /\t/
|
10
|
+
end
|
11
|
+
|
12
|
+
unless failing_lines.empty?
|
13
|
+
"#{filename} has tab characters on lines #{failing_lines.join(', ')}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def check_for_extra_spaces(filename)
|
18
|
+
failing_lines = []
|
19
|
+
File.readlines(filename).each_with_index do |line,number|
|
20
|
+
next if line =~ /^\s+#.*\s+\n$/
|
21
|
+
failing_lines << number + 1 if line =~ /\s+\n$/
|
22
|
+
end
|
23
|
+
|
24
|
+
unless failing_lines.empty?
|
25
|
+
"#{filename} has spaces on the EOL on lines #{failing_lines.join(', ')}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
RSpec::Matchers.define :be_well_formed do
|
30
|
+
failure_message_for_should do |actual|
|
31
|
+
actual.join("\n")
|
32
|
+
end
|
33
|
+
|
34
|
+
match do |actual|
|
35
|
+
actual.empty?
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it "has no malformed whitespace" do
|
40
|
+
error_messages = []
|
41
|
+
Dir.chdir(File.expand_path("../..", __FILE__)) do
|
42
|
+
`git ls-files`.split("\n").each do |filename|
|
43
|
+
next if filename =~ /\.gitmodules|fixtures/
|
44
|
+
error_messages << check_for_tab_characters(filename)
|
45
|
+
error_messages << check_for_extra_spaces(filename)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
error_messages.compact.should be_well_formed
|
49
|
+
end
|
50
|
+
|
51
|
+
it "can still be built" do
|
52
|
+
Dir.chdir(File.expand_path('../../', __FILE__)) do
|
53
|
+
`gem build webmock.gemspec`
|
54
|
+
$?.should == 0
|
55
|
+
|
56
|
+
# clean up the .gem generated
|
57
|
+
system("rm webmock-#{WebMock.version}.gem")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe WebMock::RackResponse do
|
4
|
+
before :each do
|
5
|
+
@rack_response = WebMock::RackResponse.new(MyRackApp)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should hook up to a rack appliance" do
|
9
|
+
request = WebMock::RequestSignature.new(:get, 'www.example.com')
|
10
|
+
response = @rack_response.evaluate(request)
|
11
|
+
|
12
|
+
response.status.first.should == 200
|
13
|
+
response.body.should include('This is my root!')
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should send along params" do
|
17
|
+
request = WebMock::RequestSignature.new(:get, 'www.example.com/greet?name=Johnny')
|
18
|
+
|
19
|
+
response = @rack_response.evaluate(request)
|
20
|
+
|
21
|
+
response.status.first.should == 200
|
22
|
+
response.body.should include('Hello, Johnny')
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should send along POST params" do
|
26
|
+
request = WebMock::RequestSignature.new(:post, 'www.example.com/greet',
|
27
|
+
:body => 'name=Jimmy'
|
28
|
+
)
|
29
|
+
|
30
|
+
response = @rack_response.evaluate(request)
|
31
|
+
response.body.should include('Good to meet you, Jimmy!')
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rspec'
|
3
|
+
require 'net/http'
|
4
|
+
require 'net_http_shared'
|
5
|
+
require 'net/https'
|
6
|
+
require 'stringio'
|
7
|
+
require 'support/webmock_server'
|
8
|
+
|
9
|
+
describe "Real Net:HTTP without webmock", :without_webmock => true do
|
10
|
+
before(:all) do
|
11
|
+
raise "WebMock has no access here!!!" if defined?(WebMock::NetHTTPUtility)
|
12
|
+
WebMockServer.instance.start
|
13
|
+
end
|
14
|
+
|
15
|
+
after(:all) do
|
16
|
+
WebMockServer.instance.stop
|
17
|
+
end
|
18
|
+
|
19
|
+
it_should_behave_like "Net::HTTP"
|
20
|
+
end
|
@@ -17,7 +17,7 @@ describe WebMock::RequestExecutionVerifier do
|
|
17
17
|
@verifier.expected_times_executed = 2
|
18
18
|
expected_text = "The request www.example.com was expected to execute 2 times but it executed 0 times"
|
19
19
|
expected_text << @executed_requests_info
|
20
|
-
@verifier.failure_message.should == expected_text
|
20
|
+
@verifier.failure_message.should == expected_text
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should report failure message correctly when executed times is one" do
|
@@ -29,7 +29,7 @@ describe WebMock::RequestExecutionVerifier do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
describe "negative failure message" do
|
34
34
|
|
35
35
|
it "should report failure message if it executed number of times specified" do
|
@@ -66,26 +66,26 @@ describe WebMock::RequestExecutionVerifier do
|
|
66
66
|
end
|
67
67
|
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
describe "does_not_match?" do
|
71
71
|
|
72
72
|
it "should fail if request executed expected number of times" do
|
73
73
|
WebMock::RequestRegistry.instance.
|
74
74
|
should_receive(:times_executed).with(@request_pattern).and_return(10)
|
75
75
|
@verifier.expected_times_executed = 10
|
76
|
-
@verifier.does_not_match?.should be_false
|
76
|
+
@verifier.does_not_match?.should be_false
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
it "should succeed if request was not executed at all and expected number of times was not set" do
|
80
80
|
WebMock::RequestRegistry.instance.
|
81
81
|
should_receive(:times_executed).with(@request_pattern).and_return(0)
|
82
|
-
@verifier.does_not_match?.should be_true
|
82
|
+
@verifier.does_not_match?.should be_true
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
it "should fail if request was executed and expected number of times was not set" do
|
86
86
|
WebMock::RequestRegistry.instance.
|
87
87
|
should_receive(:times_executed).with(@request_pattern).and_return(1)
|
88
|
-
@verifier.does_not_match?.should be_false
|
88
|
+
@verifier.does_not_match?.should be_false
|
89
89
|
end
|
90
90
|
|
91
91
|
it "should succeed if request was not executed expected number of times" do
|
@@ -13,7 +13,7 @@ describe WebMock::RequestPattern do
|
|
13
13
|
:body => "abc", :headers => {'A' => 'a', 'B' => 'b'}).with {|req| true}.to_s.should ==
|
14
14
|
"GET http://www.example.com/ with body \"abc\" with headers {'A'=>'a', 'B'=>'b'} with given block"
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it "should report string describing itself with query params" do
|
18
18
|
WebMock::RequestPattern.new(:get, /.*example.*/, :query => {'a' => ['b', 'c']}).to_s.should ==
|
19
19
|
"GET /.*example.*/ with query params {\"a\"=>[\"b\", \"c\"]}"
|
@@ -140,12 +140,12 @@ describe WebMock::RequestPattern do
|
|
140
140
|
WebMock::RequestPattern.new(:get, "www.example.com", :query => {"a" => ["b", "c"]}).
|
141
141
|
should match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
|
142
142
|
end
|
143
|
-
|
143
|
+
|
144
144
|
it "should not match for query params are different than the declared in hash" do
|
145
145
|
WebMock::RequestPattern.new(:get, "www.example.com", :query => {"a" => ["b", "c"]}).
|
146
146
|
should_not match(WebMock::RequestSignature.new(:get, "www.example.com?x[]=b&a[]=c"))
|
147
147
|
end
|
148
|
-
|
148
|
+
|
149
149
|
it "should match for query params are the same as declared as string" do
|
150
150
|
WebMock::RequestPattern.new(:get, "www.example.com", :query => "a[]=b&a[]=c").
|
151
151
|
should match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
|
data/spec/request_stub_spec.rb
CHANGED
@@ -23,7 +23,7 @@ describe WebMock::RequestStub do
|
|
23
23
|
|
24
24
|
it "should assign normalized headers to request pattern" do
|
25
25
|
@request_stub.with(:headers => {'A' => 'a'})
|
26
|
-
@request_stub.request_pattern.to_s.should ==
|
26
|
+
@request_stub.request_pattern.to_s.should ==
|
27
27
|
WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'A' => 'a'}).to_s
|
28
28
|
end
|
29
29
|
|
@@ -69,13 +69,13 @@ describe WebMock::RequestStub do
|
|
69
69
|
@request_stub.response
|
70
70
|
@request_stub.response.body.should == "def"
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
it "should return responses in a sequence passed as comma separated params" do
|
74
74
|
@request_stub.to_return({:body => "abc"}, {:body => "def"})
|
75
75
|
@request_stub.response.body.should == "abc"
|
76
76
|
@request_stub.response.body.should == "def"
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
it "should return responses declared in multiple to_return declarations" do
|
80
80
|
@request_stub.to_return({:body => "abc"}).to_return({:body => "def"})
|
81
81
|
@request_stub.response.body.should == "abc"
|
@@ -92,7 +92,7 @@ describe WebMock::RequestStub do
|
|
92
92
|
@request_stub.response.raise_error_if_any
|
93
93
|
}.should raise_error(ArgumentError, "Exception from WebMock")
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
it "should assign sequence of responses with response with exception to be thrown" do
|
97
97
|
@request_stub.to_return(:body => "abc").then.to_raise(ArgumentError)
|
98
98
|
@request_stub.response.body.should == "abc"
|
@@ -110,7 +110,7 @@ describe WebMock::RequestStub do
|
|
110
110
|
@request_stub.response.raise_error_if_any
|
111
111
|
}.should raise_error(IndexError, "Exception from WebMock")
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
it "should raise exceptions declared in multiple to_raise declarations" do
|
115
115
|
@request_stub.to_raise(ArgumentError).then.to_raise(IndexError)
|
116
116
|
lambda {
|
@@ -122,7 +122,7 @@ describe WebMock::RequestStub do
|
|
122
122
|
end
|
123
123
|
|
124
124
|
end
|
125
|
-
|
125
|
+
|
126
126
|
describe "to_timeout" do
|
127
127
|
|
128
128
|
it "should assign response with timeout" do
|
@@ -144,30 +144,30 @@ describe WebMock::RequestStub do
|
|
144
144
|
end
|
145
145
|
|
146
146
|
end
|
147
|
-
|
148
|
-
|
147
|
+
|
148
|
+
|
149
149
|
describe "times" do
|
150
|
-
|
150
|
+
|
151
151
|
it "should give error if declared before any response declaration is declared" do
|
152
152
|
lambda {
|
153
153
|
@request_stub.times(3)
|
154
|
-
}.should raise_error("Invalid WebMock stub declaration. times(N) can be declared only after response declaration.")
|
154
|
+
}.should raise_error("Invalid WebMock stub declaration. times(N) can be declared only after response declaration.")
|
155
155
|
end
|
156
|
-
|
156
|
+
|
157
157
|
it "should repeat returning last declared response declared number of times" do
|
158
158
|
@request_stub.to_return({:body => "abc"}).times(2).then.to_return({:body => "def"})
|
159
159
|
@request_stub.response.body.should == "abc"
|
160
160
|
@request_stub.response.body.should == "abc"
|
161
161
|
@request_stub.response.body.should == "def"
|
162
162
|
end
|
163
|
-
|
163
|
+
|
164
164
|
it "should repeat raising last declared exception declared number of times" do
|
165
165
|
@request_stub.to_return({:body => "abc"}).times(2).then.to_return({:body => "def"})
|
166
166
|
@request_stub.response.body.should == "abc"
|
167
167
|
@request_stub.response.body.should == "abc"
|
168
168
|
@request_stub.response.body.should == "def"
|
169
169
|
end
|
170
|
-
|
170
|
+
|
171
171
|
it "should repeat returning last declared sequence of responses declared number of times" do
|
172
172
|
@request_stub.to_return({:body => "abc"}, {:body => "def"}).times(2).then.to_return({:body => "ghj"})
|
173
173
|
@request_stub.response.body.should == "abc"
|
@@ -176,23 +176,23 @@ describe WebMock::RequestStub do
|
|
176
176
|
@request_stub.response.body.should == "def"
|
177
177
|
@request_stub.response.body.should == "ghj"
|
178
178
|
end
|
179
|
-
|
179
|
+
|
180
180
|
it "should return self" do
|
181
181
|
@request_stub.to_return({:body => "abc"}).times(1).should == @request_stub
|
182
182
|
end
|
183
|
-
|
183
|
+
|
184
184
|
it "should raise error if argument is not integer" do
|
185
185
|
lambda {
|
186
186
|
@request_stub.to_return({:body => "abc"}).times("not number")
|
187
|
-
}.should raise_error("times(N) accepts integers >= 1 only")
|
187
|
+
}.should raise_error("times(N) accepts integers >= 1 only")
|
188
188
|
end
|
189
|
-
|
189
|
+
|
190
190
|
it "should raise error if argument is < 1" do
|
191
191
|
lambda {
|
192
192
|
@request_stub.to_return({:body => "abc"}).times(0)
|
193
|
-
}.should raise_error("times(N) accepts integers >= 1 only")
|
193
|
+
}.should raise_error("times(N) accepts integers >= 1 only")
|
194
194
|
end
|
195
|
-
|
195
|
+
|
196
196
|
end
|
197
197
|
|
198
198
|
end
|