aeden-contacts 0.2.15
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.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +51 -0
- data/Rakefile +71 -0
- data/VERSION.yml +4 -0
- data/lib/config/contacts.yml +10 -0
- data/lib/contacts/flickr.rb +133 -0
- data/lib/contacts/google.rb +387 -0
- data/lib/contacts/google_oauth.rb +91 -0
- data/lib/contacts/version.rb +9 -0
- data/lib/contacts/windows_live.rb +164 -0
- data/lib/contacts/yahoo.rb +236 -0
- data/lib/contacts.rb +55 -0
- data/spec/contact_spec.rb +61 -0
- data/spec/feeds/contacts.yml +10 -0
- data/spec/feeds/flickr/auth.getFrob.xml +4 -0
- data/spec/feeds/flickr/auth.getToken.xml +5 -0
- data/spec/feeds/google-many.xml +48 -0
- data/spec/feeds/google-single.xml +46 -0
- data/spec/feeds/wl_contacts.xml +29 -0
- data/spec/feeds/yh_contacts.txt +119 -0
- data/spec/feeds/yh_credential.xml +28 -0
- data/spec/flickr/auth_spec.rb +80 -0
- data/spec/gmail/auth_spec.rb +70 -0
- data/spec/gmail/fetching_spec.rb +198 -0
- data/spec/rcov.opts +2 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +84 -0
- data/spec/windows_live/windows_live_spec.rb +34 -0
- data/spec/yahoo/yahoo_spec.rb +83 -0
- data/vendor/fakeweb/CHANGELOG +80 -0
- data/vendor/fakeweb/LICENSE.txt +281 -0
- data/vendor/fakeweb/README.rdoc +160 -0
- data/vendor/fakeweb/Rakefile +57 -0
- data/vendor/fakeweb/fakeweb.gemspec +13 -0
- data/vendor/fakeweb/lib/fake_web/ext/net_http.rb +58 -0
- data/vendor/fakeweb/lib/fake_web/registry.rb +78 -0
- data/vendor/fakeweb/lib/fake_web/responder.rb +88 -0
- data/vendor/fakeweb/lib/fake_web/response.rb +10 -0
- data/vendor/fakeweb/lib/fake_web/socket_delegator.rb +24 -0
- data/vendor/fakeweb/lib/fake_web.rb +152 -0
- data/vendor/fakeweb/test/fixtures/test_example.txt +1 -0
- data/vendor/fakeweb/test/fixtures/test_request +21 -0
- data/vendor/fakeweb/test/test_allow_net_connect.rb +41 -0
- data/vendor/fakeweb/test/test_fake_web.rb +453 -0
- data/vendor/fakeweb/test/test_fake_web_open_uri.rb +62 -0
- data/vendor/fakeweb/test/test_helper.rb +52 -0
- data/vendor/fakeweb/test/test_query_string.rb +37 -0
- data/vendor/windowslivelogin.rb +1151 -0
- metadata +108 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'rcov/rcovtask'
|
5
|
+
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc "Run All Tests"
|
9
|
+
Rake::TestTask.new :test do |test|
|
10
|
+
test.test_files = ["test/**/*.rb"]
|
11
|
+
test.verbose = true
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "Generate Documentation"
|
15
|
+
Rake::RDocTask.new do |rdoc|
|
16
|
+
rdoc.main = "README.rdoc"
|
17
|
+
rdoc.rdoc_dir = "doc"
|
18
|
+
rdoc.rdoc_files.include("README.rdoc", "CHANGELOG", "LICENSE.txt", "lib/*.rb")
|
19
|
+
rdoc.title = "FakeWeb API Documentation"
|
20
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
21
|
+
rdoc.options << '--charset' << 'utf-8'
|
22
|
+
end
|
23
|
+
|
24
|
+
Rcov::RcovTask.new do |t|
|
25
|
+
t.test_files = FileList['test/**/test*.rb']
|
26
|
+
t.rcov_opts << "--sort coverage"
|
27
|
+
t.rcov_opts << "--exclude gems"
|
28
|
+
t.rcov_opts << "--no-validator-links"
|
29
|
+
end
|
30
|
+
|
31
|
+
desc %{Update ".manifest" with the latest list of project filenames. Respect\
|
32
|
+
.gitignore by excluding everything that git ignores. Update `files` and\
|
33
|
+
`test_files` arrays in "*.gemspec" file if it's present.}
|
34
|
+
task :manifest do
|
35
|
+
list = Dir['**/*'].sort
|
36
|
+
spec_file = Dir['*.gemspec'].first
|
37
|
+
list -= [spec_file] if spec_file
|
38
|
+
|
39
|
+
File.read('.gitignore').each_line do |glob|
|
40
|
+
glob = glob.chomp.sub(/^\//, '')
|
41
|
+
list -= Dir[glob]
|
42
|
+
list -= Dir["#{glob}/**/*"] if File.directory?(glob) and !File.symlink?(glob)
|
43
|
+
puts "excluding #{glob}"
|
44
|
+
end
|
45
|
+
|
46
|
+
if spec_file
|
47
|
+
spec = File.read spec_file
|
48
|
+
spec.gsub! /^(\s* s.(test_)?files \s* = \s* )( \[ [^\]]* \] | %w\( [^)]* \) )/mx do
|
49
|
+
assignment = $1
|
50
|
+
bunch = $2 ? list.grep(/^test\//) : list
|
51
|
+
'%s%%w(%s)' % [assignment, bunch.join(' ')]
|
52
|
+
end
|
53
|
+
|
54
|
+
File.open(spec_file, 'w') {|f| f << spec }
|
55
|
+
end
|
56
|
+
File.open('.manifest', 'w') {|f| f << list.join("\n") }
|
57
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "fakeweb"
|
3
|
+
s.version = "1.1.2.6"
|
4
|
+
s.date = "2008-12-31"
|
5
|
+
s.summary = "A tool for faking responses to HTTP requests"
|
6
|
+
s.homepage = "http://github.com/chrisk/fakeweb"
|
7
|
+
s.has_rdoc = true
|
8
|
+
s.authors = ["Blaine Cook"]
|
9
|
+
s.files = %w(CHANGELOG LICENSE.txt README.rdoc Rakefile lib lib/fake_web lib/fake_web.rb lib/fake_web/ext lib/fake_web/ext/net_http.rb lib/fake_web/registry.rb lib/fake_web/responder.rb lib/fake_web/response.rb lib/fake_web/socket_delegator.rb test test/fixtures test/fixtures/test_example.txt test/fixtures/test_request test/test_allow_net_connect.rb test/test_fake_web.rb test/test_fake_web_open_uri.rb test/test_helper.rb test/test_query_string.rb)
|
10
|
+
s.test_files = %w(test/fixtures test/fixtures/test_example.txt test/fixtures/test_request test/test_allow_net_connect.rb test/test_fake_web.rb test/test_fake_web_open_uri.rb test/test_helper.rb test/test_query_string.rb)
|
11
|
+
s.rdoc_options = ["--main", "README.rdoc"]
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "LICENSE.txt", "README.rdoc"]
|
13
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'net/https'
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
module Net #:nodoc: all
|
6
|
+
|
7
|
+
class BufferedIO
|
8
|
+
def initialize(io, debug_output = nil)
|
9
|
+
@read_timeout = 60
|
10
|
+
@rbuf = ''
|
11
|
+
@debug_output = debug_output
|
12
|
+
|
13
|
+
@io = case io
|
14
|
+
when Socket, OpenSSL::SSL::SSLSocket, IO
|
15
|
+
io
|
16
|
+
when String
|
17
|
+
File.exists?(io) ? File.open(io, "r") : StringIO.new(io)
|
18
|
+
end
|
19
|
+
raise "Unable to create local socket" unless @io
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class HTTP
|
24
|
+
def self.socket_type
|
25
|
+
FakeWeb::SocketDelegator
|
26
|
+
end
|
27
|
+
|
28
|
+
alias :original_net_http_request :request
|
29
|
+
alias :original_net_http_connect :connect
|
30
|
+
|
31
|
+
def request(request, body = nil, &block)
|
32
|
+
protocol = use_ssl ? "https" : "http"
|
33
|
+
|
34
|
+
path = request.path
|
35
|
+
path = URI.parse(request.path).request_uri if request.path =~ /^http/
|
36
|
+
|
37
|
+
uri = "#{protocol}://#{self.address}:#{self.port}#{path}"
|
38
|
+
method = request.method.downcase.to_sym
|
39
|
+
|
40
|
+
if registered = FakeWeb::Registry.instance.registered_uri(method, uri)
|
41
|
+
responder = FakeWeb::Registry.instance.send(:pick_responder, registered)
|
42
|
+
responder.verify(request)
|
43
|
+
@socket = Net::HTTP.socket_type.new
|
44
|
+
responder.response(&block)
|
45
|
+
elsif FakeWeb.allow_net_connect?
|
46
|
+
original_net_http_connect
|
47
|
+
original_net_http_request(request, body, &block)
|
48
|
+
else
|
49
|
+
raise FakeWeb::NetConnectNotAllowedError,
|
50
|
+
"Real HTTP connections are disabled. Unregistered request: #{request.method} #{uri}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def connect
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module FakeWeb
|
2
|
+
class Registry #:nodoc:
|
3
|
+
include Singleton
|
4
|
+
|
5
|
+
attr_accessor :uri_map
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
clean_registry
|
9
|
+
end
|
10
|
+
|
11
|
+
def clean_registry
|
12
|
+
self.uri_map = Hash.new do |hash, key|
|
13
|
+
hash[key] = Hash.new(&hash.default_proc)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def register_uri(method, uri, options)
|
18
|
+
uri_map[normalize_uri(uri)][method] = [*[options]].flatten.collect do |option|
|
19
|
+
FakeWeb::Responder.new(method, uri, option, option[:times])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def registered_uri?(method, uri)
|
24
|
+
normalized_uri = normalize_uri(uri)
|
25
|
+
uri_map[normalized_uri].has_key?(method) || uri_map[normalized_uri].has_key?(:any)
|
26
|
+
end
|
27
|
+
|
28
|
+
def registered_uri(method, uri)
|
29
|
+
uri = normalize_uri(uri)
|
30
|
+
registered = registered_uri?(method, uri)
|
31
|
+
if registered && uri_map[uri].has_key?(method)
|
32
|
+
uri_map[uri][method]
|
33
|
+
elsif registered
|
34
|
+
uri_map[uri][:any]
|
35
|
+
else
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def response_for(method, uri, &block)
|
41
|
+
responders = registered_uri(method, uri)
|
42
|
+
return nil if responders.nil?
|
43
|
+
pick_responder(responders).response(&block)
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def normalize_uri(uri)
|
49
|
+
case uri
|
50
|
+
when URI then uri
|
51
|
+
else
|
52
|
+
uri = 'http://' + uri unless uri.match('^https?://')
|
53
|
+
parsed_uri = URI.parse(uri)
|
54
|
+
parsed_uri.query = sort_query_params(parsed_uri.query)
|
55
|
+
parsed_uri
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def sort_query_params(query)
|
60
|
+
if query.nil? || query.empty?
|
61
|
+
nil
|
62
|
+
else
|
63
|
+
query.split('&').sort.join('&')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def pick_responder(responders)
|
68
|
+
if next_responder = responders.find { |responder| responder.times > 0 }
|
69
|
+
next_responder.times -= 1
|
70
|
+
else
|
71
|
+
next_responder = responders.last
|
72
|
+
end
|
73
|
+
|
74
|
+
next_responder
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module FakeWeb
|
2
|
+
class Responder #:nodoc:
|
3
|
+
|
4
|
+
attr_accessor :method, :uri, :options, :times
|
5
|
+
|
6
|
+
def initialize(method, uri, options, times)
|
7
|
+
self.method = method
|
8
|
+
self.uri = uri
|
9
|
+
self.options = options
|
10
|
+
self.times = times ? times : 1
|
11
|
+
end
|
12
|
+
|
13
|
+
def response(&block)
|
14
|
+
if has_baked_response?
|
15
|
+
response = baked_response
|
16
|
+
else
|
17
|
+
code, msg = meta_information
|
18
|
+
response = Net::HTTPResponse.send(:response_class, code.to_s).new(uri, code.to_s, msg)
|
19
|
+
response.instance_variable_set(:@body, content)
|
20
|
+
end
|
21
|
+
|
22
|
+
response.instance_variable_set(:@read, true)
|
23
|
+
response.extend FakeWeb::Response
|
24
|
+
|
25
|
+
optionally_raise(response)
|
26
|
+
|
27
|
+
yield response if block_given?
|
28
|
+
|
29
|
+
response
|
30
|
+
end
|
31
|
+
|
32
|
+
def verify(request)
|
33
|
+
options[:verify].call(request) if options[:verify]
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def content
|
39
|
+
[ :file, :string ].each do |map_option|
|
40
|
+
next unless options.has_key?(map_option)
|
41
|
+
return self.send("#{map_option}_response", options[map_option])
|
42
|
+
end
|
43
|
+
|
44
|
+
return ''
|
45
|
+
end
|
46
|
+
|
47
|
+
def file_response(path)
|
48
|
+
IO.readlines(path).join("\n")
|
49
|
+
end
|
50
|
+
|
51
|
+
def string_response(string)
|
52
|
+
string
|
53
|
+
end
|
54
|
+
|
55
|
+
def baked_response
|
56
|
+
resp = case options[:response]
|
57
|
+
when Net::HTTPResponse then options[:response]
|
58
|
+
when String
|
59
|
+
socket = Net::BufferedIO.new(options[:response])
|
60
|
+
r = Net::HTTPResponse.read_new(socket)
|
61
|
+
r.instance_eval { @header['transfer-encoding'] = nil }
|
62
|
+
r.reading_body(socket, true) {}
|
63
|
+
r
|
64
|
+
else raise StandardError, "Handler unimplemented for response #{options[:response]}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def has_baked_response?
|
69
|
+
options.has_key?(:response)
|
70
|
+
end
|
71
|
+
|
72
|
+
def optionally_raise(response)
|
73
|
+
return unless options.has_key?(:exception)
|
74
|
+
ex_alloc = options[:exception].allocate
|
75
|
+
ex_instance = case ex_alloc
|
76
|
+
when Net::HTTPError, OpenURI::HTTPError
|
77
|
+
options[:exception].new('Exception from FakeWeb', response)
|
78
|
+
else options[:exception].new
|
79
|
+
end
|
80
|
+
raise ex_instance
|
81
|
+
end
|
82
|
+
|
83
|
+
def meta_information
|
84
|
+
options.has_key?(:status) ? options[:status] : [200, 'OK']
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module FakeWeb
|
2
|
+
class SocketDelegator #:nodoc:
|
3
|
+
|
4
|
+
def initialize(delegate=nil)
|
5
|
+
@delegate = nil
|
6
|
+
end
|
7
|
+
|
8
|
+
def method_missing(method, *args, &block)
|
9
|
+
if @delegate
|
10
|
+
@delegate.send(method, *args, &block)
|
11
|
+
else
|
12
|
+
self.send("my_#{method}", *args, &block)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def my_closed?
|
17
|
+
@closed ||= true
|
18
|
+
end
|
19
|
+
|
20
|
+
def my_readuntil(*args)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
require 'fake_web/ext/net_http'
|
4
|
+
require 'fake_web/registry'
|
5
|
+
require 'fake_web/response'
|
6
|
+
require 'fake_web/responder'
|
7
|
+
require 'fake_web/socket_delegator'
|
8
|
+
|
9
|
+
module FakeWeb
|
10
|
+
|
11
|
+
# Resets the FakeWeb Registry. This will force all subsequent web requests to
|
12
|
+
# behave as real requests.
|
13
|
+
def self.clean_registry
|
14
|
+
Registry.instance.clean_registry
|
15
|
+
end
|
16
|
+
|
17
|
+
# Enables or disables real HTTP connections for requests that don't match
|
18
|
+
# registered URIs.
|
19
|
+
#
|
20
|
+
# If you set <tt>FakeWeb.allow_net_connect = false</tt> and subsequently try
|
21
|
+
# to make a request to a URI you haven't registered with #register_uri, a
|
22
|
+
# NetConnectNotAllowedError will be raised. This is handy when you want to
|
23
|
+
# make sure your tests are self-contained, or want to catch the scenario
|
24
|
+
# when a URI is changed in implementation code without a corresponding test
|
25
|
+
# change.
|
26
|
+
#
|
27
|
+
# When <tt>FakeWeb.allow_net_connect = true</tt> (the default), requests to
|
28
|
+
# URIs not stubbed with FakeWeb are passed through to Net::HTTP.
|
29
|
+
def self.allow_net_connect=(allowed)
|
30
|
+
@allow_net_connect = allowed
|
31
|
+
end
|
32
|
+
|
33
|
+
# Enable pass-through to Net::HTTP by default.
|
34
|
+
self.allow_net_connect = true
|
35
|
+
|
36
|
+
# Returns +true+ if requests to URIs not registered with FakeWeb are passed
|
37
|
+
# through to Net::HTTP for normal processing (the default). Returns +false+
|
38
|
+
# if an exception is raised for these requests.
|
39
|
+
def self.allow_net_connect?
|
40
|
+
@allow_net_connect
|
41
|
+
end
|
42
|
+
|
43
|
+
# This exception is raised if you set <tt>FakeWeb.allow_net_connect =
|
44
|
+
# false</tt> and subsequently try to make a request to a URI you haven't
|
45
|
+
# stubbed.
|
46
|
+
class NetConnectNotAllowedError < StandardError; end;
|
47
|
+
|
48
|
+
# call-seq:
|
49
|
+
# FakeWeb.register_uri(method, uri, options)
|
50
|
+
# FakeWeb.register_uri(uri, options)
|
51
|
+
#
|
52
|
+
# Register requests using the HTTP method specified by the symbol +method+ for
|
53
|
+
# +uri+ to be handled according to +options+. If no +method+ is specified, or
|
54
|
+
# you explicitly specify <tt>:any</tt>, the response will be reigstered for
|
55
|
+
# any request for +uri+. +uri+ can be a +String+ or a +URI+ object. +options+
|
56
|
+
# must be either a +Hash+ or an +Array+ of +Hashes+ (see below) that must
|
57
|
+
# contain any one of the following keys:
|
58
|
+
#
|
59
|
+
# <tt>:string</tt>::
|
60
|
+
# Takes a +String+ argument that is returned as the body of the response.
|
61
|
+
# FakeWeb.register_uri(:get, 'http://example.com/', :string => "Hello World!")
|
62
|
+
# <tt>:file</tt>::
|
63
|
+
# Takes a valid filesystem path to a file that is slurped and returned as
|
64
|
+
# the body of the response.
|
65
|
+
# FakeWeb.register_uri(:post, 'http://example.com/', :file => "/tmp/my_response_body.txt")
|
66
|
+
# <tt>:response</tt>::
|
67
|
+
# Either an <tt>Net::HTTPResponse</tt>, an +IO+ or a +String+.
|
68
|
+
#
|
69
|
+
# The easier way by far is to pass the <tt>:response</tt> option to
|
70
|
+
# +register_uri+ as a +String+ or an (open for reads) +IO+ object which
|
71
|
+
# will be used as the complete HTTP response, including headers and body.
|
72
|
+
# If the string points to a readable file, this file will be used as the
|
73
|
+
# content for the request.
|
74
|
+
#
|
75
|
+
# To obtain a complete response document, you can use the +curl+ command,
|
76
|
+
# like so:
|
77
|
+
#
|
78
|
+
# curl -i http://www.example.com/ > response_for_www.example.com
|
79
|
+
#
|
80
|
+
# which can then be used in your test environment like so:
|
81
|
+
#
|
82
|
+
# FakeWeb.register_uri(:get, 'http://www.example.com/', :response => 'response_for_www.example.com')
|
83
|
+
#
|
84
|
+
# See the <tt>Net::HTTPResponse</tt>
|
85
|
+
# documentation[http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net/HTTPResponse.html]
|
86
|
+
# for more information on creating custom response objects.
|
87
|
+
#
|
88
|
+
# +options+ may also be an +Array+ containing a list of the above-described +Hash+.
|
89
|
+
# In this case, FakeWeb will rotate through each provided response, you may optionally
|
90
|
+
# provide:
|
91
|
+
#
|
92
|
+
# <tt>:times</tt>::
|
93
|
+
# The number of times this response will be used. Decremented by one each time it's called.
|
94
|
+
# FakeWeb will use the final provided request indefinitely, regardless of its :times parameter.
|
95
|
+
#
|
96
|
+
# Two optional arguments are also accepted:
|
97
|
+
#
|
98
|
+
# <tt>:status</tt>::
|
99
|
+
# Passing <tt>:status</tt> as a two-value array will set the response code
|
100
|
+
# and message. The defaults are <tt>200</tt> and <tt>OK</tt>, respectively.
|
101
|
+
# Example:
|
102
|
+
# FakeWeb.register_uri('http://www.example.com/', :response => "Go away!", :status => [ 404, "Not Found" ])
|
103
|
+
# <tt>:exception</tt>::
|
104
|
+
# The argument passed via <tt>:exception</tt> will be raised when the
|
105
|
+
# specified URL is requested. Any +Exception+ class is valid. Example:
|
106
|
+
# FakeWeb.register_uri('http://www.example.com/', :exception => Net::HTTPError)
|
107
|
+
#
|
108
|
+
def self.register_uri(*args)
|
109
|
+
options = args.last.is_a?(Hash) || args.last.is_a?(Array) ? args.pop : {}
|
110
|
+
method, uri = extract_arguments(args)
|
111
|
+
Registry.instance.register_uri(method, uri, options)
|
112
|
+
end
|
113
|
+
|
114
|
+
# call-seq:
|
115
|
+
# FakeWeb.response_for(method, uri)
|
116
|
+
# FakeWeb.response_for(uri)
|
117
|
+
#
|
118
|
+
# Returns the faked Net::HTTPResponse object associated with +uri+.
|
119
|
+
def self.response_for(*args, &block) #:nodoc: :yields: response
|
120
|
+
method, uri = extract_arguments(args)
|
121
|
+
Registry.instance.response_for(method, uri, &block)
|
122
|
+
end
|
123
|
+
|
124
|
+
# call-seq:
|
125
|
+
# FakeWeb.registered_uri?(method, uri)
|
126
|
+
# FakeWeb.registered_uri?(uri)
|
127
|
+
#
|
128
|
+
# Returns true if +uri+ is registered with FakeWeb. You can optionally
|
129
|
+
# specify +method+ to limit the search to a certain HTTP method (or use
|
130
|
+
# <tt>:any</tt> to explicitly check against any method).
|
131
|
+
def self.registered_uri?(*args)
|
132
|
+
method, uri = extract_arguments(args)
|
133
|
+
Registry.instance.registered_uri?(method, uri)
|
134
|
+
end
|
135
|
+
|
136
|
+
private
|
137
|
+
|
138
|
+
def self.extract_arguments(args)
|
139
|
+
case args.length
|
140
|
+
when 1
|
141
|
+
uri = args.first
|
142
|
+
method = :any
|
143
|
+
when 2
|
144
|
+
method, uri = *args
|
145
|
+
else
|
146
|
+
raise ArgumentError, "wrong number of arguments (expected the URI at least)"
|
147
|
+
end
|
148
|
+
|
149
|
+
[method, uri]
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
test example content
|
@@ -0,0 +1,21 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Cache-Control: private
|
3
|
+
Content-Type: text/html
|
4
|
+
Set-Cookie: PREF=ID=c1e3135f3180fabf:TM=1148188144:LM=1148188144:S=x9CJYC71XSKRA32Q; expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain=.google.com
|
5
|
+
Server: GWS/2.1
|
6
|
+
Transfer-Encoding: chunked
|
7
|
+
Date: Sun, 21 May 2006 05:09:04 GMT
|
8
|
+
|
9
|
+
<html><head><meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"><title>Google</title><style><!--
|
10
|
+
body,td,a,p,.h{font-family:arial,sans-serif;}
|
11
|
+
.h{font-size: 20px;}
|
12
|
+
.q{color:#0000cc;}
|
13
|
+
-->
|
14
|
+
</style>
|
15
|
+
<script>
|
16
|
+
<!--
|
17
|
+
function sf(){document.f.q.focus();}
|
18
|
+
// -->
|
19
|
+
</script>
|
20
|
+
</head><body bgcolor=#ffffff text=#000000 link=#0000cc vlink=#551a8b alink=#ff0000 onLoad=sf() topmargin=3 marginheight=3><center><table border=0 cellspacing=0 cellpadding=0 width=100%><tr><td align=right nowrap><font size=-1><a href="/url?sa=p&pref=ig&pval=2&q=http://www.google.com/ig%3Fhl%3Den">Personalized Home</a> | <a href="https://www.google.com/accounts/Login?continue=http://www.google.com/&hl=en">Sign in</a></font></td></tr><tr height=4><td><img alt="" width=1 height=1></td></tr></table><img src="/intl/en/images/logo.gif" width=276 height=110 alt="Google"><br><br>
|
21
|
+
<form action=/search name=f><table border=0 cellspacing=0 cellpadding=4><tr><td nowrap><font size=-1><b>Web</b> <a id=1a class=q href="/imghp?hl=en&tab=wi&ie=UTF-8">Images</a> <a id=2a class=q href="http://groups.google.com/grphp?hl=en&tab=wg&ie=UTF-8">Groups</a> <a id=4a class=q href="http://news.google.com/nwshp?hl=en&tab=wn&ie=UTF-8">News</a> <a id=5a class=q href="http://froogle.google.com/frghp?hl=en&tab=wf&ie=UTF-8">Froogle</a> <a id=7a class=q href="/maphp?hl=en&tab=wl&ie=UTF-8">Maps</a> <b><a href="/intl/en/options/" class=q>more »</a></b></font></td></tr></table><table cellspacing=0 cellpadding=0><tr><td width=25%> </td><td align=center><input type=hidden name=hl value=en><input type=hidden name=ie value="ISO-8859-1"><input maxlength=2048 size=55 name=q value="" title="Google Search"><br><input type=submit value="Google Search" name=btnG><input type=submit value="I'm Feeling Lucky" name=btnI></td><td valign=top nowrap width=25%><font size=-2> <a href=/advanced_search?hl=en>Advanced Search</a><br> <a href=/preferences?hl=en>Preferences</a><br> <a href=/language_tools?hl=en>Language Tools</a></font></td></tr></table></form><br><br><font size=-1><a href="/intl/en/ads/">Advertising Programs</a> - <a href=/services/>Business Solutions</a> - <a href=/intl/en/about.html>About Google</a></font><p><font size=-2>©2006 Google</font></p></center></body></html>
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_helper")
|
2
|
+
|
3
|
+
class TestFakeWebAllowNetConnect < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@original_allow_net_connect = FakeWeb.allow_net_connect?
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
FakeWeb.allow_net_connect = @original_allow_net_connect
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
def test_unregistered_requests_are_passed_through_when_allow_net_connect_is_true
|
15
|
+
FakeWeb.allow_net_connect = true
|
16
|
+
setup_expectations_for_real_apple_hot_news_request
|
17
|
+
Net::HTTP.get(URI.parse("http://images.apple.com/main/rss/hotnews/hotnews.rss"))
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_raises_for_unregistered_requests_when_allow_net_connect_is_false
|
21
|
+
FakeWeb.allow_net_connect = false
|
22
|
+
exception = assert_raise FakeWeb::NetConnectNotAllowedError do
|
23
|
+
Net::HTTP.get(URI.parse('http://example.com/'))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_question_mark_method_returns_true_after_setting_allow_net_connect_to_true
|
28
|
+
FakeWeb.allow_net_connect = true
|
29
|
+
assert FakeWeb.allow_net_connect?
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_question_mark_method_returns_false_after_setting_allow_net_connect_to_false
|
33
|
+
FakeWeb.allow_net_connect = false
|
34
|
+
assert !FakeWeb.allow_net_connect?
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_allow_net_connect_is_true_by_default
|
38
|
+
assert FakeWeb.allow_net_connect?
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|