corntrace-fakeweb 1.2.9
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/CHANGELOG +197 -0
- data/LICENSE.txt +281 -0
- data/README.rdoc +222 -0
- data/Rakefile +70 -0
- data/fakeweb.gemspec +123 -0
- data/lib/fake_web.rb +179 -0
- data/lib/fake_web/VERSION +1 -0
- data/lib/fake_web/ext/net_http.rb +81 -0
- data/lib/fake_web/registry.rb +114 -0
- data/lib/fake_web/responder.rb +120 -0
- data/lib/fake_web/response.rb +10 -0
- data/lib/fake_web/stub_socket.rb +15 -0
- data/lib/fake_web/utility.rb +65 -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 +553 -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_missing_pathname.rb +37 -0
- data/test/test_other_net_http_libraries.rb +36 -0
- data/test/test_precedence.rb +79 -0
- data/test/test_query_string.rb +45 -0
- data/test/test_regexes.rb +157 -0
- data/test/test_response_headers.rb +73 -0
- data/test/test_trailing_slashes.rb +53 -0
- data/test/test_utility.rb +76 -0
- data/test/vendor/right_http_connection-1.2.4/History.txt +59 -0
- data/test/vendor/right_http_connection-1.2.4/Manifest.txt +7 -0
- data/test/vendor/right_http_connection-1.2.4/README.txt +54 -0
- data/test/vendor/right_http_connection-1.2.4/Rakefile +103 -0
- data/test/vendor/right_http_connection-1.2.4/lib/net_fix.rb +160 -0
- data/test/vendor/right_http_connection-1.2.4/lib/right_http_connection.rb +435 -0
- data/test/vendor/right_http_connection-1.2.4/setup.rb +1585 -0
- data/test/vendor/samuel-0.2.1/.document +5 -0
- data/test/vendor/samuel-0.2.1/.gitignore +5 -0
- data/test/vendor/samuel-0.2.1/LICENSE +20 -0
- data/test/vendor/samuel-0.2.1/README.rdoc +70 -0
- data/test/vendor/samuel-0.2.1/Rakefile +62 -0
- data/test/vendor/samuel-0.2.1/VERSION +1 -0
- data/test/vendor/samuel-0.2.1/lib/samuel.rb +52 -0
- data/test/vendor/samuel-0.2.1/lib/samuel/net_http.rb +10 -0
- data/test/vendor/samuel-0.2.1/lib/samuel/request.rb +96 -0
- data/test/vendor/samuel-0.2.1/samuel.gemspec +69 -0
- data/test/vendor/samuel-0.2.1/test/request_test.rb +193 -0
- data/test/vendor/samuel-0.2.1/test/samuel_test.rb +42 -0
- data/test/vendor/samuel-0.2.1/test/test_helper.rb +66 -0
- data/test/vendor/samuel-0.2.1/test/thread_test.rb +32 -0
- metadata +167 -0
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class SamuelTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "logger configuration" do
|
6
|
+
setup do
|
7
|
+
Samuel.logger = nil
|
8
|
+
if Object.const_defined?(:RAILS_DEFAULT_LOGGER)
|
9
|
+
Object.send(:remove_const, :RAILS_DEFAULT_LOGGER)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
teardown do
|
14
|
+
Samuel.logger = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when Rails's logger is available" do
|
18
|
+
setup { Object.const_set(:RAILS_DEFAULT_LOGGER, :mock_logger) }
|
19
|
+
|
20
|
+
should "use the same logger" do
|
21
|
+
assert_equal :mock_logger, Samuel.logger
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "when Rails's logger is not available" do
|
26
|
+
should "use a new Logger instance pointed to STDOUT" do
|
27
|
+
assert_instance_of Logger, Samuel.logger
|
28
|
+
assert_equal STDOUT, Samuel.logger.instance_variable_get(:"@logdev").dev
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
context ".reset_config" do
|
35
|
+
should "reset the config to default vaules" do
|
36
|
+
Samuel.config = {:foo => "bar"}
|
37
|
+
Samuel.reset_config
|
38
|
+
assert_equal({:label => nil, :labels => {"" => "HTTP"}, :filtered_params => []}, Samuel.config)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'mocha'
|
5
|
+
require 'open-uri'
|
6
|
+
require 'fakeweb'
|
7
|
+
|
8
|
+
FakeWeb.allow_net_connect = false
|
9
|
+
|
10
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
11
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
12
|
+
require 'samuel'
|
13
|
+
|
14
|
+
class Test::Unit::TestCase
|
15
|
+
TEST_LOG_PATH = File.join(File.dirname(__FILE__), 'test.log')
|
16
|
+
|
17
|
+
def self.should_log_lines(expected_count)
|
18
|
+
should "log #{expected_count} line#{'s' unless expected_count == 1}" do
|
19
|
+
lines = File.readlines(TEST_LOG_PATH)
|
20
|
+
assert_equal expected_count, lines.length
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.should_log_including(what)
|
25
|
+
should "log a line including #{what.inspect}" do
|
26
|
+
contents = File.read(TEST_LOG_PATH)
|
27
|
+
if what.is_a?(Regexp)
|
28
|
+
assert_match what, contents
|
29
|
+
else
|
30
|
+
assert contents.include?(what),
|
31
|
+
"Expected #{contents.inspect} to include #{what.inspect}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.should_log_at_level(level)
|
37
|
+
level = level.to_s.upcase
|
38
|
+
should "log at the #{level} level" do
|
39
|
+
assert File.read(TEST_LOG_PATH).include?(" #{level} -- :")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.should_raise_exception(klass)
|
44
|
+
should "raise an #{klass} exception" do
|
45
|
+
assert @exception.is_a?(klass)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.should_have_config_afterwards_including(config)
|
50
|
+
config.each_pair do |key, value|
|
51
|
+
should "continue afterwards with Samuel.config[#{key.inspect}] set to #{value.inspect}" do
|
52
|
+
assert_equal value, Samuel.config[key]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def setup_test_logger
|
58
|
+
FileUtils.rm_rf TEST_LOG_PATH
|
59
|
+
FileUtils.touch TEST_LOG_PATH
|
60
|
+
Samuel.logger = Logger.new(TEST_LOG_PATH)
|
61
|
+
end
|
62
|
+
|
63
|
+
def teardown_test_logger
|
64
|
+
FileUtils.rm_rf TEST_LOG_PATH
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ThreadTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "when logging multiple requests at once" do
|
6
|
+
setup do
|
7
|
+
@log = StringIO.new
|
8
|
+
Samuel.logger = Logger.new(@log)
|
9
|
+
FakeWeb.register_uri(:get, /example\.com/, :status => [200, "OK"])
|
10
|
+
threads = []
|
11
|
+
5.times do |i|
|
12
|
+
threads << Thread.new(i) do |n|
|
13
|
+
Samuel.with_config :label => "Example #{n}" do
|
14
|
+
Thread.pass
|
15
|
+
open "http://example.com/#{n}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
threads.each { |t| t.join }
|
20
|
+
@log.rewind
|
21
|
+
end
|
22
|
+
|
23
|
+
should "not let configuration blocks interfere with eachother" do
|
24
|
+
@log.each_line do |line|
|
25
|
+
matches = %r|Example (\d+).*example\.com/(\d+)|.match(line)
|
26
|
+
assert_not_nil matches
|
27
|
+
assert_equal matches[1], matches[2]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: corntrace-fakeweb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 13
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 2
|
9
|
+
- 9
|
10
|
+
version: 1.2.9
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Kevin Fu
|
14
|
+
- Chris Kampmeier
|
15
|
+
- Blaine Cook
|
16
|
+
autorequire:
|
17
|
+
bindir: bin
|
18
|
+
cert_chain: []
|
19
|
+
|
20
|
+
date: 2010-07-13 00:00:00 +08:00
|
21
|
+
default_executable:
|
22
|
+
dependencies:
|
23
|
+
- !ruby/object:Gem::Dependency
|
24
|
+
name: mocha
|
25
|
+
prerelease: false
|
26
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
hash: 49
|
32
|
+
segments:
|
33
|
+
- 0
|
34
|
+
- 9
|
35
|
+
- 5
|
36
|
+
version: 0.9.5
|
37
|
+
type: :development
|
38
|
+
version_requirements: *id001
|
39
|
+
description: FakeWeb is a helper for faking web requests in Ruby. It works at a global level, without modifying code or writing extensive stubs.\nI added ERB template feature and regular expression matching capture feature for :body and :response options
|
40
|
+
email:
|
41
|
+
- corntrace@gmail.com
|
42
|
+
- chris@kampers.net
|
43
|
+
- romeda@gmail.com
|
44
|
+
executables: []
|
45
|
+
|
46
|
+
extensions: []
|
47
|
+
|
48
|
+
extra_rdoc_files:
|
49
|
+
- LICENSE.txt
|
50
|
+
- README.rdoc
|
51
|
+
files:
|
52
|
+
- .gitignore
|
53
|
+
- CHANGELOG
|
54
|
+
- LICENSE.txt
|
55
|
+
- README.rdoc
|
56
|
+
- Rakefile
|
57
|
+
- fakeweb.gemspec
|
58
|
+
- lib/fake_web.rb
|
59
|
+
- lib/fake_web/VERSION
|
60
|
+
- lib/fake_web/ext/net_http.rb
|
61
|
+
- lib/fake_web/registry.rb
|
62
|
+
- lib/fake_web/responder.rb
|
63
|
+
- lib/fake_web/response.rb
|
64
|
+
- lib/fake_web/stub_socket.rb
|
65
|
+
- lib/fake_web/utility.rb
|
66
|
+
- lib/fakeweb.rb
|
67
|
+
- test/fixtures/google_response_from_curl
|
68
|
+
- test/fixtures/google_response_with_transfer_encoding
|
69
|
+
- test/fixtures/google_response_without_transfer_encoding
|
70
|
+
- test/fixtures/test_example.txt
|
71
|
+
- test/fixtures/test_txt_file
|
72
|
+
- test/test_allow_net_connect.rb
|
73
|
+
- test/test_deprecations.rb
|
74
|
+
- test/test_fake_authentication.rb
|
75
|
+
- test/test_fake_web.rb
|
76
|
+
- test/test_fake_web_open_uri.rb
|
77
|
+
- test/test_helper.rb
|
78
|
+
- test/test_missing_open_uri.rb
|
79
|
+
- test/test_missing_pathname.rb
|
80
|
+
- test/test_other_net_http_libraries.rb
|
81
|
+
- test/test_precedence.rb
|
82
|
+
- test/test_query_string.rb
|
83
|
+
- test/test_regexes.rb
|
84
|
+
- test/test_response_headers.rb
|
85
|
+
- test/test_trailing_slashes.rb
|
86
|
+
- test/test_utility.rb
|
87
|
+
- test/vendor/right_http_connection-1.2.4/History.txt
|
88
|
+
- test/vendor/right_http_connection-1.2.4/Manifest.txt
|
89
|
+
- test/vendor/right_http_connection-1.2.4/README.txt
|
90
|
+
- test/vendor/right_http_connection-1.2.4/Rakefile
|
91
|
+
- test/vendor/right_http_connection-1.2.4/lib/net_fix.rb
|
92
|
+
- test/vendor/right_http_connection-1.2.4/lib/right_http_connection.rb
|
93
|
+
- test/vendor/right_http_connection-1.2.4/setup.rb
|
94
|
+
- test/vendor/samuel-0.2.1/.document
|
95
|
+
- test/vendor/samuel-0.2.1/.gitignore
|
96
|
+
- test/vendor/samuel-0.2.1/LICENSE
|
97
|
+
- test/vendor/samuel-0.2.1/README.rdoc
|
98
|
+
- test/vendor/samuel-0.2.1/Rakefile
|
99
|
+
- test/vendor/samuel-0.2.1/VERSION
|
100
|
+
- test/vendor/samuel-0.2.1/lib/samuel.rb
|
101
|
+
- test/vendor/samuel-0.2.1/lib/samuel/net_http.rb
|
102
|
+
- test/vendor/samuel-0.2.1/lib/samuel/request.rb
|
103
|
+
- test/vendor/samuel-0.2.1/samuel.gemspec
|
104
|
+
- test/vendor/samuel-0.2.1/test/request_test.rb
|
105
|
+
- test/vendor/samuel-0.2.1/test/samuel_test.rb
|
106
|
+
- test/vendor/samuel-0.2.1/test/test_helper.rb
|
107
|
+
- test/vendor/samuel-0.2.1/test/thread_test.rb
|
108
|
+
has_rdoc: true
|
109
|
+
homepage: http://github.com/corntrace/fakeweb
|
110
|
+
licenses: []
|
111
|
+
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options:
|
114
|
+
- --charset=UTF-8
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
hash: 3
|
123
|
+
segments:
|
124
|
+
- 0
|
125
|
+
version: "0"
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
hash: 3
|
132
|
+
segments:
|
133
|
+
- 0
|
134
|
+
version: "0"
|
135
|
+
requirements: []
|
136
|
+
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 1.3.7
|
139
|
+
signing_key:
|
140
|
+
specification_version: 3
|
141
|
+
summary: A tool for faking responses to HTTP requests
|
142
|
+
test_files:
|
143
|
+
- test/test_allow_net_connect.rb
|
144
|
+
- test/test_deprecations.rb
|
145
|
+
- test/test_fake_authentication.rb
|
146
|
+
- test/test_fake_web.rb
|
147
|
+
- test/test_fake_web_open_uri.rb
|
148
|
+
- test/test_helper.rb
|
149
|
+
- test/test_missing_open_uri.rb
|
150
|
+
- test/test_missing_pathname.rb
|
151
|
+
- test/test_other_net_http_libraries.rb
|
152
|
+
- test/test_precedence.rb
|
153
|
+
- test/test_query_string.rb
|
154
|
+
- test/test_regexes.rb
|
155
|
+
- test/test_response_headers.rb
|
156
|
+
- test/test_trailing_slashes.rb
|
157
|
+
- test/test_utility.rb
|
158
|
+
- test/vendor/right_http_connection-1.2.4/lib/net_fix.rb
|
159
|
+
- test/vendor/right_http_connection-1.2.4/lib/right_http_connection.rb
|
160
|
+
- test/vendor/right_http_connection-1.2.4/setup.rb
|
161
|
+
- test/vendor/samuel-0.2.1/lib/samuel/net_http.rb
|
162
|
+
- test/vendor/samuel-0.2.1/lib/samuel/request.rb
|
163
|
+
- test/vendor/samuel-0.2.1/lib/samuel.rb
|
164
|
+
- test/vendor/samuel-0.2.1/test/request_test.rb
|
165
|
+
- test/vendor/samuel-0.2.1/test/samuel_test.rb
|
166
|
+
- test/vendor/samuel-0.2.1/test/test_helper.rb
|
167
|
+
- test/vendor/samuel-0.2.1/test/thread_test.rb
|