sandro-fakeweb 1.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +163 -0
- data/LICENSE.txt +281 -0
- data/README.rdoc +216 -0
- data/Rakefile +78 -0
- data/lib/fake_web.rb +204 -0
- data/lib/fake_web/ext/net_http.rb +76 -0
- data/lib/fake_web/fixture.rb +60 -0
- data/lib/fake_web/registry.rb +127 -0
- data/lib/fake_web/responder.rb +113 -0
- data/lib/fake_web/response.rb +10 -0
- data/lib/fake_web/stub_socket.rb +15 -0
- data/lib/fake_web/utility.rb +44 -0
- data/lib/fakeweb.rb +2 -0
- data/test/fixtures/google_response_from_curl +12 -0
- data/test/fixtures/google_response_with_transfer_encoding +17 -0
- data/test/fixtures/google_response_without_transfer_encoding +11 -0
- data/test/fixtures/test_example.txt +1 -0
- data/test/fixtures/test_txt_file +3 -0
- data/test/test_allow_net_connect.rb +85 -0
- data/test/test_deprecations.rb +54 -0
- data/test/test_fake_authentication.rb +92 -0
- data/test/test_fake_web.rb +535 -0
- data/test/test_fake_web_fixture.rb +64 -0
- data/test/test_fake_web_generate_fixtures.rb +71 -0
- data/test/test_fake_web_open_uri.rb +58 -0
- data/test/test_helper.rb +87 -0
- data/test/test_missing_open_uri.rb +25 -0
- data/test/test_precedence.rb +79 -0
- data/test/test_query_string.rb +45 -0
- data/test/test_regexes.rb +152 -0
- data/test/test_response_headers.rb +73 -0
- data/test/test_trailing_slashes.rb +53 -0
- data/test/test_utility.rb +91 -0
- metadata +127 -0
@@ -0,0 +1,73 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_helper")
|
2
|
+
|
3
|
+
class TestResponseHeaders < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_content_type_when_registering_with_string_and_content_type_header_as_symbol_option
|
6
|
+
FakeWeb.register_uri(:get, "http://example.com/users.json", :body => '[{"username": "chrisk"}]', :content_type => "application/json")
|
7
|
+
response = Net::HTTP.start("example.com") { |query| query.get("/users.json") }
|
8
|
+
assert_equal '[{"username": "chrisk"}]', response.body
|
9
|
+
assert_equal "application/json", response['Content-Type']
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_content_type_when_registering_with_string_and_content_type_header_as_string_option
|
13
|
+
FakeWeb.register_uri(:get, "http://example.com/users.json", :body => '[{"username": "chrisk"}]', 'Content-Type' => "application/json")
|
14
|
+
response = Net::HTTP.start("example.com") { |query| query.get("/users.json") }
|
15
|
+
assert_equal "application/json", response['Content-Type']
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_content_type_when_registering_with_string_only
|
19
|
+
FakeWeb.register_uri(:get, "http://example.com/users.json", :body => '[{"username": "chrisk"}]')
|
20
|
+
response = Net::HTTP.start("example.com") { |query| query.get("/users.json") }
|
21
|
+
assert_equal '[{"username": "chrisk"}]', response.body
|
22
|
+
assert_nil response['Content-Type']
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_cookies_when_registering_with_file_and_set_cookie_header
|
26
|
+
FakeWeb.register_uri(:get, "http://example.com/", :body => File.dirname(__FILE__) + '/fixtures/test_example.txt',
|
27
|
+
:set_cookie => "user_id=1; example=yes")
|
28
|
+
response = Net::HTTP.start("example.com") { |query| query.get("/") }
|
29
|
+
assert_equal "test example content", response.body
|
30
|
+
assert_equal "user_id=1; example=yes", response['Set-Cookie']
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_registering_with_baked_response_ignores_header_options
|
34
|
+
fake_response = Net::HTTPOK.new('1.1', '200', 'OK')
|
35
|
+
fake_response["Server"] = "Apache/1.3.27 (Unix)"
|
36
|
+
FakeWeb.register_uri(:get, "http://example.com/", :response => fake_response,
|
37
|
+
:server => "FakeWeb/1.2.3 (Ruby)")
|
38
|
+
response = Net::HTTP.start("example.com") { |query| query.get("/") }
|
39
|
+
assert_equal "200", response.code
|
40
|
+
assert_equal "OK", response.message
|
41
|
+
assert_equal "Apache/1.3.27 (Unix)", response["Server"]
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_headers_are_rotated_when_registering_with_response_rotation
|
45
|
+
FakeWeb.register_uri(:get, "http://example.com",
|
46
|
+
[{:body => 'test1', :expires => "Thu, 14 Jun 2009 16:00:00 GMT",
|
47
|
+
:content_type => "text/plain"},
|
48
|
+
{:body => 'test2', :expires => "Thu, 14 Jun 2009 16:00:01 GMT"}])
|
49
|
+
|
50
|
+
first_response = second_response = nil
|
51
|
+
Net::HTTP.start("example.com") do |query|
|
52
|
+
first_response = query.get("/")
|
53
|
+
second_response = query.get("/")
|
54
|
+
end
|
55
|
+
assert_equal 'test1', first_response.body
|
56
|
+
assert_equal "Thu, 14 Jun 2009 16:00:00 GMT", first_response['Expires']
|
57
|
+
assert_equal "text/plain", first_response['Content-Type']
|
58
|
+
assert_equal 'test2', second_response.body
|
59
|
+
assert_equal "Thu, 14 Jun 2009 16:00:01 GMT", second_response['Expires']
|
60
|
+
assert_nil second_response['Content-Type']
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_registering_with_status_option_and_response_headers
|
64
|
+
FakeWeb.register_uri(:get, "http://example.com", :status => ["301", "Moved Permanently"],
|
65
|
+
:location => "http://www.example.com")
|
66
|
+
|
67
|
+
response = Net::HTTP.start("example.com") { |query| query.get("/") }
|
68
|
+
assert_equal "301", response.code
|
69
|
+
assert_equal "Moved Permanently", response.message
|
70
|
+
assert_equal "http://www.example.com", response["Location"]
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_helper")
|
2
|
+
|
3
|
+
class TestFakeWebTrailingSlashes < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_registering_root_without_slash_and_ask_predicate_method_with_slash
|
6
|
+
FakeWeb.register_uri(:get, "http://www.example.com", :body => "root")
|
7
|
+
assert FakeWeb.registered_uri?(:get, "http://www.example.com/")
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_registering_root_without_slash_and_request
|
11
|
+
FakeWeb.register_uri(:get, "http://www.example.com", :body => "root")
|
12
|
+
response = Net::HTTP.start("www.example.com") { |query| query.get('/') }
|
13
|
+
assert_equal "root", response.body
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_registering_root_with_slash_and_ask_predicate_method_without_slash
|
17
|
+
FakeWeb.register_uri(:get, "http://www.example.com/", :body => "root")
|
18
|
+
assert FakeWeb.registered_uri?(:get, "http://www.example.com")
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_registering_root_with_slash_and_request
|
22
|
+
FakeWeb.register_uri(:get, "http://www.example.com/", :body => "root")
|
23
|
+
response = Net::HTTP.start("www.example.com") { |query| query.get('/') }
|
24
|
+
assert_equal "root", response.body
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_registering_path_without_slash_and_ask_predicate_method_with_slash
|
28
|
+
FakeWeb.register_uri(:get, "http://www.example.com/users", :body => "User list")
|
29
|
+
assert !FakeWeb.registered_uri?(:get, "http://www.example.com/users/")
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_registering_path_without_slash_and_request_with_slash
|
33
|
+
FakeWeb.allow_net_connect = false
|
34
|
+
FakeWeb.register_uri(:get, "http://www.example.com/users", :body => "User list")
|
35
|
+
assert_raise FakeWeb::NetConnectNotAllowedError do
|
36
|
+
response = Net::HTTP.start("www.example.com") { |query| query.get('/users/') }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_registering_path_with_slash_and_ask_predicate_method_without_slash
|
41
|
+
FakeWeb.register_uri(:get, "http://www.example.com/users/", :body => "User list")
|
42
|
+
assert !FakeWeb.registered_uri?(:get, "http://www.example.com/users")
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_registering_path_with_slash_and_request_without_slash
|
46
|
+
FakeWeb.allow_net_connect = false
|
47
|
+
FakeWeb.register_uri(:get, "http://www.example.com/users/", :body => "User list")
|
48
|
+
assert_raise FakeWeb::NetConnectNotAllowedError do
|
49
|
+
response = Net::HTTP.start("www.example.com") { |query| query.get('/users') }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_helper")
|
2
|
+
|
3
|
+
class TestUtility < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_decode_userinfo_from_header_handles_basic_auth
|
6
|
+
authorization_header = "Basic dXNlcm5hbWU6c2VjcmV0"
|
7
|
+
userinfo = FakeWeb::Utility.decode_userinfo_from_header(authorization_header)
|
8
|
+
assert_equal "username:secret", userinfo
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_encode_unsafe_chars_in_userinfo_does_not_encode_userinfo_safe_punctuation
|
12
|
+
userinfo = "user;&=+$,:secret"
|
13
|
+
assert_equal userinfo, FakeWeb::Utility.encode_unsafe_chars_in_userinfo(userinfo)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_encode_unsafe_chars_in_userinfo_does_not_encode_rfc_3986_unreserved_characters
|
17
|
+
userinfo = "-_.!~*'()abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:secret"
|
18
|
+
assert_equal userinfo, FakeWeb::Utility.encode_unsafe_chars_in_userinfo(userinfo)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_encode_unsafe_chars_in_userinfo_does_encode_other_characters
|
22
|
+
userinfo, safe_userinfo = 'us#rn@me:sec//ret?"', 'us%23rn%40me:sec%2F%2Fret%3F%22'
|
23
|
+
assert_equal safe_userinfo, FakeWeb::Utility.encode_unsafe_chars_in_userinfo(userinfo)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_strip_default_port_from_uri_strips_80_from_http_with_path
|
27
|
+
uri = "http://example.com:80/foo/bar"
|
28
|
+
stripped_uri = FakeWeb::Utility.strip_default_port_from_uri(uri)
|
29
|
+
assert_equal "http://example.com/foo/bar", stripped_uri
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_strip_default_port_from_uri_strips_80_from_http_without_path
|
33
|
+
uri = "http://example.com:80"
|
34
|
+
stripped_uri = FakeWeb::Utility.strip_default_port_from_uri(uri)
|
35
|
+
assert_equal "http://example.com", stripped_uri
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_strip_default_port_from_uri_strips_443_from_https_without_path
|
39
|
+
uri = "https://example.com:443"
|
40
|
+
stripped_uri = FakeWeb::Utility.strip_default_port_from_uri(uri)
|
41
|
+
assert_equal "https://example.com", stripped_uri
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_strip_default_port_from_uri_strips_443_from_https
|
45
|
+
uri = "https://example.com:443/foo/bar"
|
46
|
+
stripped_uri = FakeWeb::Utility.strip_default_port_from_uri(uri)
|
47
|
+
assert_equal "https://example.com/foo/bar", stripped_uri
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_strip_default_port_from_uri_does_not_strip_8080_from_http
|
51
|
+
uri = "http://example.com:8080/foo/bar"
|
52
|
+
assert_equal uri, FakeWeb::Utility.strip_default_port_from_uri(uri)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_strip_default_port_from_uri_does_not_strip_443_from_http
|
56
|
+
uri = "http://example.com:443/foo/bar"
|
57
|
+
assert_equal uri, FakeWeb::Utility.strip_default_port_from_uri(uri)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_strip_default_port_from_uri_does_not_strip_80_from_query_string
|
61
|
+
uri = "http://example.com/?a=:80&b=c"
|
62
|
+
assert_equal uri, FakeWeb::Utility.strip_default_port_from_uri(uri)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_strip_default_port_from_uri_does_not_modify_strings_that_do_not_start_with_http_or_https
|
66
|
+
uri = "httpz://example.com:80/"
|
67
|
+
assert_equal uri, FakeWeb::Utility.strip_default_port_from_uri(uri)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_simple_array_permutation_with_one_element
|
71
|
+
array, permutations = [1], [[1]]
|
72
|
+
FakeWeb::Utility.simple_array_permutation(array) do |permutation|
|
73
|
+
permutations.delete(permutation)
|
74
|
+
end
|
75
|
+
assert permutations.empty?
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_simple_array_permutation_with_three_elements
|
79
|
+
array = [1, 2, 3]
|
80
|
+
permutations = [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
|
81
|
+
FakeWeb::Utility.simple_array_permutation(array) do |permutation|
|
82
|
+
permutations.delete(permutation)
|
83
|
+
end
|
84
|
+
assert permutations.empty?
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_simple_array_permutation_return_value
|
88
|
+
array = [1, 2, 3]
|
89
|
+
assert array, FakeWeb::Utility.simple_array_permutation(array) { }
|
90
|
+
end
|
91
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sandro-fakeweb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Kampmeier
|
8
|
+
- Blaine Cook
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-07-08 00:00:00 -04:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: mocha
|
18
|
+
type: :development
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.9.5
|
25
|
+
version:
|
26
|
+
description: FakeWeb is a helper for faking web requests in Ruby. It works at a global level, without modifying code or writing extensive stubs.
|
27
|
+
email:
|
28
|
+
- chris@kampers.net
|
29
|
+
- romeda@gmail.com
|
30
|
+
executables: []
|
31
|
+
|
32
|
+
extensions: []
|
33
|
+
|
34
|
+
extra_rdoc_files:
|
35
|
+
- CHANGELOG
|
36
|
+
- LICENSE.txt
|
37
|
+
- README.rdoc
|
38
|
+
files:
|
39
|
+
- CHANGELOG
|
40
|
+
- LICENSE.txt
|
41
|
+
- README.rdoc
|
42
|
+
- Rakefile
|
43
|
+
- lib/fake_web.rb
|
44
|
+
- lib/fake_web/ext/net_http.rb
|
45
|
+
- lib/fake_web/fixture.rb
|
46
|
+
- lib/fake_web/registry.rb
|
47
|
+
- lib/fake_web/responder.rb
|
48
|
+
- lib/fake_web/response.rb
|
49
|
+
- lib/fake_web/stub_socket.rb
|
50
|
+
- lib/fake_web/utility.rb
|
51
|
+
- lib/fakeweb.rb
|
52
|
+
- test/fixtures/google_response_from_curl
|
53
|
+
- test/fixtures/google_response_with_transfer_encoding
|
54
|
+
- test/fixtures/google_response_without_transfer_encoding
|
55
|
+
- test/fixtures/test_example.txt
|
56
|
+
- test/fixtures/test_txt_file
|
57
|
+
- test/test_allow_net_connect.rb
|
58
|
+
- test/test_deprecations.rb
|
59
|
+
- test/test_fake_authentication.rb
|
60
|
+
- test/test_fake_web.rb
|
61
|
+
- test/test_fake_web_fixture.rb
|
62
|
+
- test/test_fake_web_generate_fixtures.rb
|
63
|
+
- test/test_fake_web_open_uri.rb
|
64
|
+
- test/test_helper.rb
|
65
|
+
- test/test_missing_open_uri.rb
|
66
|
+
- test/test_precedence.rb
|
67
|
+
- test/test_query_string.rb
|
68
|
+
- test/test_regexes.rb
|
69
|
+
- test/test_response_headers.rb
|
70
|
+
- test/test_trailing_slashes.rb
|
71
|
+
- test/test_utility.rb
|
72
|
+
has_rdoc: true
|
73
|
+
homepage: http://github.com/chrisk/fakeweb
|
74
|
+
licenses: []
|
75
|
+
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options:
|
78
|
+
- --main
|
79
|
+
- README.rdoc
|
80
|
+
- --title
|
81
|
+
- FakeWeb API Documentation
|
82
|
+
- --charset
|
83
|
+
- utf-8
|
84
|
+
- --line-numbers
|
85
|
+
- --inline-source
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: "0"
|
93
|
+
version:
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: "0"
|
99
|
+
version:
|
100
|
+
requirements: []
|
101
|
+
|
102
|
+
rubyforge_project: fakeweb
|
103
|
+
rubygems_version: 1.3.5
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: A tool for faking responses to HTTP requests
|
107
|
+
test_files:
|
108
|
+
- test/fixtures/google_response_from_curl
|
109
|
+
- test/fixtures/google_response_with_transfer_encoding
|
110
|
+
- test/fixtures/google_response_without_transfer_encoding
|
111
|
+
- test/fixtures/test_example.txt
|
112
|
+
- test/fixtures/test_txt_file
|
113
|
+
- test/test_allow_net_connect.rb
|
114
|
+
- test/test_deprecations.rb
|
115
|
+
- test/test_fake_authentication.rb
|
116
|
+
- test/test_fake_web.rb
|
117
|
+
- test/test_fake_web_fixture.rb
|
118
|
+
- test/test_fake_web_generate_fixtures.rb
|
119
|
+
- test/test_fake_web_open_uri.rb
|
120
|
+
- test/test_helper.rb
|
121
|
+
- test/test_missing_open_uri.rb
|
122
|
+
- test/test_precedence.rb
|
123
|
+
- test/test_query_string.rb
|
124
|
+
- test/test_regexes.rb
|
125
|
+
- test/test_response_headers.rb
|
126
|
+
- test/test_trailing_slashes.rb
|
127
|
+
- test/test_utility.rb
|