diff --git a/fakeweb-1.2.5/.specification b/fakeweb-1.2.5/.specification
new file mode 100644
index 0000000..8d4c75e
--- /dev/null
+++ b/fakeweb-1.2.5/.specification
@@ -0,0 +1,122 @@
+--- !ruby/object:Gem::Specification
+name: fakeweb
+version: !ruby/object:Gem::Version
+ version: 1.2.5
+platform: ruby
+authors:
+- Chris Kampmeier
+- Blaine Cook
+autorequire:
+bindir: bin
+cert_chain: []
+
+date: 2009-07-08 00:00:00 -04:00
+default_executable:
+dependencies:
+- !ruby/object:Gem::Dependency
+ name: mocha
+ type: :development
+ version_requirement:
+ version_requirements: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: 0.9.5
+ version:
+description: FakeWeb is a helper for faking web requests in Ruby. It works at a global level, without modifying code or writing extensive stubs.
+email:
+- chris@kampers.net
+- romeda@gmail.com
+executables: []
+
+extensions: []
+
+extra_rdoc_files:
+- CHANGELOG
+- LICENSE.txt
+- README.rdoc
+files:
+- CHANGELOG
+- LICENSE.txt
+- README.rdoc
+- Rakefile
+- lib/fake_web.rb
+- 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/stub_socket.rb
+- lib/fake_web/utility.rb
+- lib/fakeweb.rb
+- test/fixtures/google_response_from_curl
+- test/fixtures/google_response_with_transfer_encoding
+- test/fixtures/google_response_without_transfer_encoding
+- test/fixtures/test_example.txt
+- test/fixtures/test_txt_file
+- test/test_allow_net_connect.rb
+- test/test_deprecations.rb
+- test/test_fake_authentication.rb
+- test/test_fake_web.rb
+- test/test_fake_web_open_uri.rb
+- test/test_helper.rb
+- test/test_missing_open_uri.rb
+- test/test_precedence.rb
+- test/test_query_string.rb
+- test/test_regexes.rb
+- test/test_response_headers.rb
+- test/test_trailing_slashes.rb
+- test/test_utility.rb
+has_rdoc: true
+homepage: http://github.com/chrisk/fakeweb
+licenses: []
+
+post_install_message:
+rdoc_options:
+- --main
+- README.rdoc
+- --title
+- FakeWeb API Documentation
+- --charset
+- utf-8
+- --line-numbers
+- --inline-source
+require_paths:
+- lib
+required_ruby_version: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: "0"
+ version:
+required_rubygems_version: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: "0"
+ version:
+requirements: []
+
+rubyforge_project: fakeweb
+rubygems_version: 1.3.4
+signing_key:
+specification_version: 3
+summary: A tool for faking responses to HTTP requests
+test_files:
+- test/fixtures/google_response_from_curl
+- test/fixtures/google_response_with_transfer_encoding
+- test/fixtures/google_response_without_transfer_encoding
+- test/fixtures/test_example.txt
+- test/fixtures/test_txt_file
+- test/test_allow_net_connect.rb
+- test/test_deprecations.rb
+- test/test_fake_authentication.rb
+- test/test_fake_web.rb
+- test/test_fake_web_open_uri.rb
+- test/test_helper.rb
+- test/test_missing_open_uri.rb
+- test/test_precedence.rb
+- test/test_query_string.rb
+- test/test_regexes.rb
+- test/test_response_headers.rb
+- test/test_trailing_slashes.rb
+- test/test_utility.rb
diff --git a/fakeweb-1.2.5/CHANGELOG b/fakeweb-1.2.5/CHANGELOG
new file mode 100644
index 0000000..097a9d0
--- /dev/null
+++ b/fakeweb-1.2.5/CHANGELOG
@@ -0,0 +1,163 @@
+fakeweb (1.2.5)
+
+* fix handling of userinfo strings that contain percent-encoded unsafe
+ characters [Chris Kampmeier, Ken Mayer]
+
+* fix that exact matches against strings/URIs with the :any method had a lower
+ precedence than regex matches using a real HTTP method (exact matches now
+ always take precedence) [Chris Kampmeier]
+
+* change request handling to raise an exception when more than one registered
+ regex matches a request URI [Chris Kampmeier]
+
+
+fakeweb (1.2.4)
+
+* add experimental support for matching URIs via regular expressions
+ [Jacqui Maher, Tiago Albineli Motta, Peter Wagene]
+
+* fix an exception when registering with the :response option and a string that
+ is the same as the name of a directory in the current path [Chris Kampmeier]
+
+* DEPRECATION: Calling FakeWeb.register_uri with a :string or :file option is
+ now deprecated. Both options have been replaced with a unified :body option,
+ since they supply the response body (as opposed to :response, which supplies
+ the full response including headers) [Chris Kampmeier]
+
+* add support for specifying HTTP headers as options to FakeWeb.register_uri
+ when using the :string or :file response types, since those methods only
+ specify a response body [David Michael, Chris Kampmeier]
+
+* DEPRECATION: Calling FakeWeb.register_uri and FakeWeb.registered_uri? without
+ an HTTP method as the first argument is now deprecated. To match against any
+ HTTP method (the pre-1.2.0 behavior), use :any [Chris Kampmeier]
+
+
+fakeweb (1.2.3)
+
+* fix the #http_version of :file and :string responses, which was returning the
+ request URI instead of something sensible like "1.0" [Chris Kampmeier]
+
+* add method aliases in the Net::HTTP patch to eliminate warnings when running
+ with -w [Joshua Clingenpeel]
+
+* fix that removing the redefinition of OpenURI::HTTPError in 1.2.0 caused
+ :exception responses to raise when OpenURI isn't available [Chris Kampmeier]
+
+* fix registering an :exception response with classes that require arguments for
+ instantiation, like Interrupt's subclasses [Chris Kampmeier]
+
+
+fakeweb (1.2.2)
+
+* fix that HTTP Digest and OAuth requests could raise URI::InvalidURIErrors
+ [Bill Kocik, Chris Kampmeier]
+
+
+fakeweb (1.2.1)
+
+* fix that query parameters are handled correctly when registering with a URI
+ object [Anselmo Alves, Chris Kampmeier]
+
+* fix an exception when registering with the :response option and a string
+ containing "\0" [Jonathan Baudanza, Chris Kampmeier]
+
+* fix that trailing slashes were considered significant for requests to the root
+ of a domain [Chris Kampmeier]
+
+* add support for HTTP basic authentication via userinfo strings in URIs
+ [Michael Bleigh]
+
+
+fakeweb (1.2.0)
+
+* add lib/fakeweb.rb so you can require "fakeweb" as well [Chris Kampmeier]
+
+* fix compatibility with Ruby 1.9.1 [Chris Kampmeier]
+
+* fix that newlines in file-based responses could be doubled in the response
+ object's body [Mark Menard, Chris Kampmeier]
+
+* fix unnecessary munging of the transfer-encoding header, which improves
+ compatibility with mechanize [Mark Menard]
+
+* fix a test and the RCov dependency to be compatible with JRuby [Mark Menard]
+
+* remove an unnecessary redefinition of OpenURI::HTTPError [Josh Nichols]
+
+* rearrange implementation code into separate files, one per class [Josh Nichols]
+
+* fix a bug where FakeWeb.response_for would raise if the request wasn't
+ registered [Chris Kampmeier]
+
+* add HTTP method support, so FakeWeb takes both the URI and method into
+ account for registration, requests, and responses. Backwards-compatible with
+ the old method signatures, which didn't have a method param. [Chris Kampmeier]
+
+* start work on Ruby 1.9 compatibility [Chris Kampmeier]
+
+* add FakeWeb.allow_net_connect= to enable/disable the pass-through to
+ Net::HTTP for unregistered URIs [Mislav Marohnić, Chris Kampmeier]
+
+* remove setup.rb, since most people use RubyGems [Mislav Marohnić]
+
+* fix that 'http://example.com/?' (empty query) matches a registered
+ 'http://example.com/', and vice-versa [Mislav Marohnić]
+
+* improve the test suite to not rely on an internet connection [Chris Kampmeier]
+
+* use `rake test` instead of `rake tests` [Josh Nichols]
+
+* fix an incompatibility with Ruby 1.8.6 p36 where you'd get "Errno::EINTR:
+ Interrupted system call" exceptions in Socket#sysread for any non-faked
+ request [Chris Kampmeier]
+
+* response rotation: you can now optionally call FakeWeb.register_uri with an
+ array of options hashes; these are used, in order, to respond to
+ repeated requests (to repeat a response more than once before rotating, use
+ the :times option). Once you run out of responses, further requests always
+ receive the last response. [Michael Shapiro]
+
+* add support for Net::HTTP's undocumented full-URI request style (fixes
+ URI::InvalidURIErrors that you might see in older libraries) [Chris Kampmeier]
+
+* sort query params before storing internally, so that
+ http://example.com/?a=1&b=2 and http://example.com/?b=2&a=1 are considered the
+ same URL (although this is technically incorrect, it's much more
+ convenient--most web apps work that way, and Net::HTTP's use of a hash to pass
+ query params means that the order in which FakeWeb stores them can be
+ unpredictable) [Chris Kampmeier]
+
+* add support for ports in URLs, so that http://example.com/ and
+ http://example.com:3000/ are not the same [Chris Kampmeier]
+
+* fix for non-faked SSL requests failing with "Unable to create local socket"
+ [Chris Kampmeier]
+
+* update Rakefile to fix warning about deprecated code [Chris Kampmeier]
+
+
+fakeweb (1.1.2)
+
+* add required dependencies to GemSpec to ensure that tests pass in firebrigade
+ (http://firebrigade.seattlerb.org/) [Blaine Cook]
+
+
+fakeweb (1.1.1)
+
+* fix for non-existence of :string method on File as presented by open-uri
+ [Blaine Cook]
+
+* fix for curl example test - google redirects to ccTLDs for those outside US
+ [Blaine Cook]
+
+
+fakeweb (1.1.0)
+
+* update code to correspond to ruby 1.8.4 (breaks compatibility with ruby 1.8.2)
+ [Blaine Cook]
+
+
+fakeweb (1.0.0)
+
+ * initial import [Blaine Cook]
diff --git a/fakeweb-1.2.5/LICENSE.txt b/fakeweb-1.2.5/LICENSE.txt
new file mode 100644
index 0000000..84e4948
--- /dev/null
+++ b/fakeweb-1.2.5/LICENSE.txt
@@ -0,0 +1,281 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
diff --git a/fakeweb-1.2.5/README.rdoc b/fakeweb-1.2.5/README.rdoc
new file mode 100644
index 0000000..eeea95a
--- /dev/null
+++ b/fakeweb-1.2.5/README.rdoc
@@ -0,0 +1,193 @@
+= FakeWeb
+
+FakeWeb is a helper for faking web requests in Ruby. It works at a global
+level, without modifying code or writing extensive stubs.
+
+
+== Installation
+
+The latest release of FakeWeb is once again available from your friendly
+RubyForge mirror. Just install the gem:
+
+ sudo gem install fakeweb
+
+Note: the gem was previously available as +FakeWeb+ (capital letters), but now
+all versions are simply registered as +fakeweb+. If you have any old +FakeWeb+
+gems lying around, remove them: sudo gem uninstall FakeWeb
+
+
+== Help and discussion
+
+RDocs for the current release are available at http://fakeweb.rubyforge.org.
+
+There's a mailing list for questions and discussion at
+http://groups.google.com/group/fakeweb-users.
+
+The main source repository is http://github.com/chrisk/fakeweb.
+
+== Examples
+
+Start by requiring FakeWeb:
+
+ require 'rubygems'
+ require 'fakeweb'
+
+=== Registering basic string responses
+
+ FakeWeb.register_uri(:get, "http://example.com/test1", :body => "Hello World!")
+
+ Net::HTTP.get(URI.parse("http://example.com/test1"))
+ => "Hello World!"
+
+ Net::HTTP.get(URI.parse("http://example.com/test2"))
+ => FakeWeb is bypassed and the response from a real request is returned
+
+You can also call register_uri with a regular expression, to match
+more than one URI.
+
+=== Replaying a recorded response
+
+ page = `curl -is http://www.google.com/`
+ FakeWeb.register_uri(:get, "http://www.google.com/", :response => page)
+
+ Net::HTTP.get(URI.parse("http://www.google.com/"))
+ # => Full response, including headers
+
+=== Adding a custom status to the response
+
+ FakeWeb.register_uri(:get, "http://example.com/", :body => "Nothing to be found 'round here",
+ :status => ["404", "Not Found"])
+
+ Net::HTTP.start("example.com") do |req|
+ response = req.get("/")
+ response.code # => "404"
+ response.message # => "Not Found"
+ response.body # => "Nothing to be found 'round here"
+ end
+
+=== Responding to any HTTP method
+
+ FakeWeb.register_uri(:any, "http://example.com", :body => "response for any HTTP method")
+
+If you use the :any symbol, the URI you specify will be completely
+stubbed out (regardless of the HTTP method of the request). This can be useful
+for RPC-like services, where the HTTP method isn't significant. (Older
+versions of FakeWeb always behaved like this, and didn't accept the first
++method+ argument above; this syntax is now deprecated.)
+
+=== Rotating responses
+
+You can optionally call FakeWeb.register_uri with an array of options hashes;
+these are used, in order, to respond to repeated requests. Once you run out of
+responses, further requests always receive the last response. (You can also send
+a response more than once before rotating, by specifying a :times
+option for that response.)
+
+ FakeWeb.register_uri(:delete, "http://example.com/posts/1",
+ [{:body => "Post 1 deleted.", :status => ["200", "OK"]},
+ {:body => "Post not found", :status => ["404", "Not Found"]}])
+
+ Net::HTTP.start("example.com") do |req|
+ req.delete("/posts/1").body # => "Post 1 deleted"
+ req.delete("/posts/1").body # => "Post not found"
+ req.delete("/posts/1").body # => "Post not found"
+ end
+
+=== Using HTTP basic authentication
+
+You can stub requests that use basic authentication with +userinfo+ strings in
+the URIs:
+
+ FakeWeb.register_uri(:get, "http://example.com/secret", :body => "Unauthorized", :status => ["401", "Unauthorized"])
+ FakeWeb.register_uri(:get, "http://user:pass@example.com/secret", :body => "Authorized")
+
+ Net::HTTP.start("example.com") do |http|
+ req = Net::HTTP::Get.new("/secret")
+ http.request(req) # => "Unauthorized"
+ req.basic_auth("user", "pass")
+ http.request(req) # => "Authorized"
+ end
+
+=== Clearing registered URIs
+
+The FakeWeb registry is a singleton that lasts for the duration of your
+program, maintaining every fake response you register. If needed, you
+can clean out the registry and remove all registered URIs:
+
+ FakeWeb.clean_registry
+
+=== Blocking all real requests
+
+When you're using FakeWeb to replace _all_ of your requests, it's useful to
+catch when requests are made for unregistered URIs (unlike the default
+behavior, which is to pass those requests through to Net::HTTP as usual).
+
+ FakeWeb.allow_net_connect = false
+ Net::HTTP.get(URI.parse("http://example.com/"))
+ => raises FakeWeb::NetConnectNotAllowedError
+
+ FakeWeb.allow_net_connect = true
+ Net::HTTP.get(URI.parse("http://example.com/"))
+ => FakeWeb is bypassed and the response from a real request is returned
+
+This is handy when you want to make sure your tests are self-contained, or you
+want to catch the scenario when a URI is changed in implementation code
+without a corresponding test change.
+
+=== Specifying HTTP response headers
+
+When you register a response using the :body option, you're only
+setting the body of the response. If you want to add headers to these responses,
+simply add the header as an option to +register_uri+:
+
+ FakeWeb.register_uri(:get, "http://example.com/hello.txt", :body => "Hello", :content_type => "text/plain")
+
+This sets the "Content-Type" header in the response.
+
+== More info
+
+FakeWeb lets you decouple your test environment from live services without
+modifying code or writing extensive stubs.
+
+In addition to the conceptual advantage of having idempotent request
+behaviour, FakeWeb makes tests run faster than if they were made to remote (or
+even local) web servers. It also makes it possible to run tests without a
+network connection or in situations where the server is behind a firewall or
+has host-based access controls.
+
+FakeWeb works with anything based on Net::HTTP--both higher-level wrappers,
+like OpenURI, as well as a ton of libraries for popular web services.
+
+
+== Known Issues
+
+* Request bodies are ignored, including PUT and POST parameters. If you need
+ different responses for different request bodies, you need to request
+ different URLs, and register different responses for each. (Query strings are
+ fully supported, though.) We're currently considering how the API should
+ change to add support for request bodies in 1.3.0. Your input would be really
+ helpful: see http://groups.google.com/group/fakeweb-users/browse_thread/thread/44d190a6b12e4273
+ for a discussion of some different options. Thanks!
+
+
+== Copyright
+
+Copyright 2006-2007 Blaine Cook
+
+Copyright 2008-2009 various contributors
+
+ FakeWeb is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 2 of the License, or (at your option) any later
+ version.
+
+ FakeWeb is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ details.
+
+ You should have received a copy of the GNU General Public License along
+ with FakeWeb; if not, write to the Free Software Foundation, Inc., 51
+ Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+See LICENSE.txt for the full terms.
diff --git a/fakeweb-1.2.5/Rakefile b/fakeweb-1.2.5/Rakefile
new file mode 100644
index 0000000..97a32b8
--- /dev/null
+++ b/fakeweb-1.2.5/Rakefile
@@ -0,0 +1,76 @@
+puts "Using ruby #{RUBY_VERSION}p#{RUBY_PATCHLEVEL}"
+
+require 'rubygems'
+require 'rake/gempackagetask'
+require 'rake/testtask'
+begin
+ require 'rdoc/task'
+rescue LoadError
+ puts "\nIt looks like you're using an old version of RDoc, but FakeWeb requires a newer one."
+ puts "You can try upgrading with `sudo gem install rdoc`.\n\n"
+ raise
+end
+
+task :default => :test
+
+desc "Run All Tests"
+Rake::TestTask.new :test do |test|
+ test.test_files = ["test/**/*.rb"]
+ test.verbose = false
+end
+
+desc "Generate Documentation"
+RDoc::Task.new do |rdoc|
+ rdoc.main = "README.rdoc"
+ rdoc.rdoc_dir = "doc"
+ rdoc.rdoc_files.include("README.rdoc", "CHANGELOG", "LICENSE.txt", "lib/*.rb")
+ rdoc.title = "FakeWeb API Documentation"
+ rdoc.options << '--line-numbers' << '--charset' << 'utf-8'
+end
+
+desc %{Update ".manifest" with the latest list of project filenames. Respect\
+.gitignore by excluding everything that git ignores. Update `files` and\
+`test_files` arrays in "*.gemspec" file if it's present.}
+task :manifest do
+ list = Dir['**/*'].sort
+ spec_file = Dir['*.gemspec'].first
+ list -= [spec_file] if spec_file
+
+ File.read('.gitignore').each_line do |glob|
+ glob = glob.chomp.sub(/^\//, '')
+ list -= Dir[glob]
+ list -= Dir["#{glob}/**/*"] if File.directory?(glob) and !File.symlink?(glob)
+ puts "excluding #{glob}"
+ end
+
+ if spec_file
+ spec = File.read spec_file
+ spec.gsub!(/^(\s* s.(test_)?files \s* = \s* )( \[ [^\]]* \] | %w\( [^)]* \) )/mx) do
+ assignment = $1
+ bunch = $2 ? list.grep(/^test\//) : list
+ '%s%%w(%s)' % [assignment, bunch.join(' ')]
+ end
+
+ File.open(spec_file, 'w') {|f| f << spec }
+ end
+ File.open('.manifest', 'w') {|f| f << list.join("\n") }
+end
+
+if RUBY_PLATFORM =~ /java/
+ puts "rcov support disabled (running under JRuby)."
+elsif RUBY_VERSION =~ /^1\.9/
+ puts "rcov support disabled (running under Ruby 1.9)"
+else
+ require 'rcov/rcovtask'
+ Rcov::RcovTask.new do |t|
+ t.test_files = FileList['test/**/test*.rb']
+ t.rcov_opts << "--sort coverage"
+ t.rcov_opts << "--exclude gems"
+ end
+end
+
+spec = eval(File.read(File.join(File.dirname(__FILE__), "fakeweb.gemspec")))
+Rake::GemPackageTask.new(spec) do |pkg|
+ pkg.need_tar_gz = true
+ pkg.need_zip = true
+end
diff --git a/fakeweb-1.2.5/lib/fake_web.rb b/fakeweb-1.2.5/lib/fake_web.rb
new file mode 100644
index 0000000..9428eca
--- /dev/null
+++ b/fakeweb-1.2.5/lib/fake_web.rb
@@ -0,0 +1,172 @@
+require 'singleton'
+
+require 'fake_web/ext/net_http'
+require 'fake_web/registry'
+require 'fake_web/response'
+require 'fake_web/responder'
+require 'fake_web/stub_socket'
+require 'fake_web/utility'
+
+module FakeWeb
+
+ # Resets the FakeWeb Registry. This will force all subsequent web requests to
+ # behave as real requests.
+ def self.clean_registry
+ Registry.instance.clean_registry
+ end
+
+ # Enables or disables real HTTP connections for requests that don't match
+ # registered URIs.
+ #
+ # If you set FakeWeb.allow_net_connect = false and subsequently try
+ # to make a request to a URI you haven't registered with #register_uri, a
+ # NetConnectNotAllowedError will be raised. This is handy when you want to
+ # make sure your tests are self-contained, or want to catch the scenario
+ # when a URI is changed in implementation code without a corresponding test
+ # change.
+ #
+ # When FakeWeb.allow_net_connect = true (the default), requests to
+ # URIs not stubbed with FakeWeb are passed through to Net::HTTP.
+ def self.allow_net_connect=(allowed)
+ @allow_net_connect = allowed
+ end
+
+ # Enable pass-through to Net::HTTP by default.
+ self.allow_net_connect = true
+
+ # Returns +true+ if requests to URIs not registered with FakeWeb are passed
+ # through to Net::HTTP for normal processing (the default). Returns +false+
+ # if an exception is raised for these requests.
+ def self.allow_net_connect?
+ @allow_net_connect
+ end
+
+ # This exception is raised if you set FakeWeb.allow_net_connect =
+ # false and subsequently try to make a request to a URI you haven't
+ # stubbed.
+ class NetConnectNotAllowedError < StandardError; end;
+
+ # This exception is raised if a Net::HTTP request matches more than one of
+ # the regular expression-based stubs you've registered. To fix the problem,
+ # disambiguate the regular expressions by making them more specific.
+ class MultipleMatchingRegexpsError < StandardError; end;
+
+ # call-seq:
+ # FakeWeb.register_uri(method, uri, options)
+ #
+ # Register requests using the HTTP method specified by the symbol +method+
+ # for +uri+ to be handled according to +options+. If you specify the method
+ # :any, the response will be reigstered for any request for +uri+.
+ # +uri+ can be a +String+, +URI+, or +Regexp+ object. +options+ must be either
+ # a +Hash+ or an +Array+ of +Hashes+ (see below), which must contain one of
+ # these two keys:
+ #
+ # :body::
+ # A string which is used as the body of the response. If the string refers
+ # to a valid filesystem path, the contents of that file will be read and used
+ # as the body of the response instead. (This used to be two options,
+ # :string and :file, respectively. These are now deprecated.)
+ # :response::
+ # Either an Net::HTTPResponse, an +IO+, or a +String+ which is used
+ # as the full response for the request.
+ #
+ # The easier way by far is to pass the :response option to
+ # +register_uri+ as a +String+ or an (open for reads) +IO+ object which
+ # will be used as the complete HTTP response, including headers and body.
+ # If the string points to a readable file, this file will be used as the
+ # content for the request.
+ #
+ # To obtain a complete response document, you can use the +curl+ command,
+ # like so:
+ #
+ # curl -i http://www.example.com/ > response_for_www.example.com
+ #
+ # which can then be used in your test environment like so:
+ #
+ # FakeWeb.register_uri(:get, 'http://www.example.com/', :response => 'response_for_www.example.com')
+ #
+ # See the Net::HTTPResponse
+ # documentation[http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net/HTTPResponse.html]
+ # for more information on creating custom response objects.
+ #
+ # +options+ may also be an +Array+ containing a list of the above-described
+ # +Hash+. In this case, FakeWeb will rotate through each provided response,
+ # you may optionally provide:
+ #
+ # :times::
+ # The number of times this response will be used. Decremented by one each time it's called.
+ # FakeWeb will use the final provided request indefinitely, regardless of its :times parameter.
+ #
+ # Two optional arguments are also accepted:
+ #
+ # :status::
+ # Passing :status as a two-value array will set the response code
+ # and message. The defaults are 200 and OK, respectively.
+ # Example:
+ # FakeWeb.register_uri("http://www.example.com/", :body => "Go away!", :status => [404, "Not Found"])
+ # :exception::
+ # The argument passed via :exception will be raised when the
+ # specified URL is requested. Any +Exception+ class is valid. Example:
+ # FakeWeb.register_uri('http://www.example.com/', :exception => Net::HTTPError)
+ #
+ # If you're using the :body response type, you can pass additional
+ # options to specify the HTTP headers to be used in the response. Example:
+ #
+ # FakeWeb.register_uri(:get, "http://example.com/index.txt", :body => "Hello", :content_type => "text/plain")
+ def self.register_uri(*args)
+ case args.length
+ when 3
+ Registry.instance.register_uri(*args)
+ when 2
+ print_missing_http_method_deprecation_warning(*args)
+ Registry.instance.register_uri(:any, *args)
+ else
+ raise ArgumentError.new("wrong number of arguments (#{args.length} for 3)")
+ end
+ end
+
+ # call-seq:
+ # FakeWeb.response_for(method, uri)
+ #
+ # Returns the faked Net::HTTPResponse object associated with +method+ and +uri+.
+ def self.response_for(*args, &block) #:nodoc: :yields: response
+ case args.length
+ when 2
+ Registry.instance.response_for(*args, &block)
+ when 1
+ print_missing_http_method_deprecation_warning(*args)
+ Registry.instance.response_for(:any, *args, &block)
+ else
+ raise ArgumentError.new("wrong number of arguments (#{args.length} for 2)")
+ end
+ end
+
+ # call-seq:
+ # FakeWeb.registered_uri?(method, uri)
+ #
+ # Returns true if a +method+ request for +uri+ is registered with FakeWeb.
+ # Specify a method of :any to check for against all HTTP methods.
+ def self.registered_uri?(*args)
+ case args.length
+ when 2
+ Registry.instance.registered_uri?(*args)
+ when 1
+ print_missing_http_method_deprecation_warning(*args)
+ Registry.instance.registered_uri?(:any, *args)
+ else
+ raise ArgumentError.new("wrong number of arguments (#{args.length} for 2)")
+ end
+ end
+
+ private
+
+ def self.print_missing_http_method_deprecation_warning(*args)
+ method = caller.first.match(/`(.*?)'/)[1]
+ new_args = args.map { |a| a.inspect }.unshift(":any")
+ new_args.last.gsub!(/^\{|\}$/, "").gsub!("=>", " => ") if args.last.is_a?(Hash)
+ $stderr.puts
+ $stderr.puts "Deprecation warning: FakeWeb requires an HTTP method argument (or use :any). Try this:"
+ $stderr.puts " FakeWeb.#{method}(#{new_args.join(', ')})"
+ $stderr.puts "Called at #{caller[1]}"
+ end
+end
diff --git a/fakeweb-1.2.5/lib/fake_web/ext/net_http.rb b/fakeweb-1.2.5/lib/fake_web/ext/net_http.rb
new file mode 100644
index 0000000..13ea666
--- /dev/null
+++ b/fakeweb-1.2.5/lib/fake_web/ext/net_http.rb
@@ -0,0 +1,71 @@
+require 'net/http'
+require 'net/https'
+require 'stringio'
+
+module Net #:nodoc: all
+
+ class BufferedIO
+ alias initialize_without_fakeweb initialize
+ def initialize(io, debug_output = nil)
+ @read_timeout = 60
+ @rbuf = ''
+ @debug_output = debug_output
+
+ @io = case io
+ when Socket, OpenSSL::SSL::SSLSocket, IO
+ io
+ when String
+ if !io.include?("\0") && File.exists?(io) && !File.directory?(io)
+ File.open(io, "r")
+ else
+ StringIO.new(io)
+ end
+ end
+ raise "Unable to create local socket" unless @io
+ end
+ end
+
+ class HTTP
+ class << self
+ alias socket_type_without_fakeweb socket_type
+ def socket_type
+ FakeWeb::StubSocket
+ end
+ end
+
+ alias request_without_fakeweb request
+ def request(request, body = nil, &block)
+ protocol = use_ssl? ? "https" : "http"
+
+ path = request.path
+ path = URI.parse(request.path).request_uri if request.path =~ /^http/
+
+ if request["authorization"] =~ /^Basic /
+ userinfo = FakeWeb::Utility.decode_userinfo_from_header(request["authorization"])
+ userinfo = FakeWeb::Utility.encode_unsafe_chars_in_userinfo(userinfo) + "@"
+ else
+ userinfo = ""
+ end
+
+ uri = "#{protocol}://#{userinfo}#{self.address}:#{self.port}#{path}"
+ method = request.method.downcase.to_sym
+
+ if FakeWeb.registered_uri?(method, uri)
+ @socket = Net::HTTP.socket_type.new
+ FakeWeb.response_for(method, uri, &block)
+ elsif FakeWeb.allow_net_connect?
+ connect_without_fakeweb
+ request_without_fakeweb(request, body, &block)
+ else
+ uri = FakeWeb::Utility.strip_default_port_from_uri(uri)
+ raise FakeWeb::NetConnectNotAllowedError,
+ "Real HTTP connections are disabled. Unregistered request: #{request.method} #{uri}"
+ end
+ end
+
+ alias connect_without_fakeweb connect
+ def connect
+ end
+ end
+
+end
diff --git a/fakeweb-1.2.5/lib/fake_web/registry.rb b/fakeweb-1.2.5/lib/fake_web/registry.rb
new file mode 100644
index 0000000..ed59524
--- /dev/null
+++ b/fakeweb-1.2.5/lib/fake_web/registry.rb
@@ -0,0 +1,103 @@
+module FakeWeb
+ class Registry #:nodoc:
+ include Singleton
+
+ attr_accessor :uri_map
+
+ def initialize
+ clean_registry
+ end
+
+ def clean_registry
+ self.uri_map = Hash.new { |hash, key| hash[key] = {} }
+ end
+
+ def register_uri(method, uri, options)
+ uri_map[normalize_uri(uri)][method] = [*[options]].flatten.collect do |option|
+ FakeWeb::Responder.new(method, uri, option, option[:times])
+ end
+ end
+
+ def registered_uri?(method, uri)
+ normalized_uri = normalize_uri(uri)
+ !responses_for(method, uri).empty?
+ end
+
+ def response_for(method, uri, &block)
+ responses = responses_for(method, uri)
+ return nil if responses.empty?
+
+ next_response = responses.last
+ responses.each do |response|
+ if response.times and response.times > 0
+ response.times -= 1
+ next_response = response
+ break
+ end
+ end
+
+ next_response.response(&block)
+ end
+
+
+ private
+
+ def responses_for(method, uri)
+ uri = normalize_uri(uri)
+
+ if uri_map[uri].has_key?(method)
+ uri_map[uri][method]
+ elsif uri_map[uri].has_key?(:any)
+ uri_map[uri][:any]
+ elsif uri_map_matches?(method, uri)
+ uri_map_matches(method, uri)
+ elsif uri_map_matches(:any, uri)
+ uri_map_matches(:any, uri)
+ else
+ []
+ end
+ end
+
+ def uri_map_matches?(method, uri)
+ !uri_map_matches(method, uri).nil?
+ end
+
+ def uri_map_matches(method, uri)
+ uri = normalize_uri(uri.to_s).to_s
+ uri = Utility.strip_default_port_from_uri(uri)
+
+ matches = uri_map.select { |registered_uri, method_hash|
+ registered_uri.is_a?(Regexp) && uri.match(registered_uri) && method_hash.has_key?(method)
+ }
+
+ if matches.size > 1
+ raise MultipleMatchingRegexpsError,
+ "More than one regular expression matched this request: #{method.to_s.upcase} #{uri}"
+ end
+
+ matches.map { |_, method_hash| method_hash[method] }.first
+ end
+
+ def normalize_uri(uri)
+ return uri if uri.is_a?(Regexp)
+ normalized_uri =
+ case uri
+ when URI then uri
+ when String
+ uri = 'http://' + uri unless uri.match('^https?://')
+ URI.parse(uri)
+ end
+ normalized_uri.query = sort_query_params(normalized_uri.query)
+ normalized_uri.normalize
+ end
+
+ def sort_query_params(query)
+ if query.nil? || query.empty?
+ nil
+ else
+ query.split('&').sort.join('&')
+ end
+ end
+
+ end
+end
diff --git a/fakeweb-1.2.5/lib/fake_web/responder.rb b/fakeweb-1.2.5/lib/fake_web/responder.rb
new file mode 100644
index 0000000..e7b0ede
--- /dev/null
+++ b/fakeweb-1.2.5/lib/fake_web/responder.rb
@@ -0,0 +1,113 @@
+module FakeWeb
+ class Responder #:nodoc:
+
+ attr_accessor :method, :uri, :options, :times
+ KNOWN_OPTIONS = [:body, :exception, :response, :status].freeze
+
+ def initialize(method, uri, options, times)
+ self.method = method
+ self.uri = uri
+ self.options = options
+ self.times = times ? times : 1
+
+ if options.has_key?(:file) || options.has_key?(:string)
+ print_file_string_options_deprecation_warning
+ options[:body] = options.delete(:file) || options.delete(:string)
+ end
+ end
+
+ def response(&block)
+ if has_baked_response?
+ response = baked_response
+ else
+ code, msg = meta_information
+ response = Net::HTTPResponse.send(:response_class, code.to_s).new("1.0", code.to_s, msg)
+ response.instance_variable_set(:@body, body)
+ headers_extracted_from_options.each { |name, value| response[name] = value }
+ end
+
+ response.instance_variable_set(:@read, true)
+ response.extend FakeWeb::Response
+
+ optionally_raise(response)
+
+ yield response if block_given?
+
+ response
+ end
+
+ private
+
+ def headers_extracted_from_options
+ options.reject {|name, _| KNOWN_OPTIONS.include?(name) }.map { |name, value|
+ [name.to_s.split("_").map { |segment| segment.capitalize }.join("-"), value]
+ }
+ end
+
+ def body
+ return '' unless options.has_key?(:body)
+
+ if !options[:body].include?("\0") && File.exists?(options[:body]) && !File.directory?(options[:body])
+ File.read(options[:body])
+ else
+ options[:body]
+ end
+ end
+
+ def baked_response
+ resp = case options[:response]
+ when Net::HTTPResponse then options[:response]
+ when String
+ socket = Net::BufferedIO.new(options[:response])
+ r = Net::HTTPResponse.read_new(socket)
+
+ # Store the oiriginal transfer-encoding
+ saved_transfer_encoding = r.instance_eval {
+ @header['transfer-encoding'] if @header.key?('transfer-encoding')
+ }
+
+ # read the body of response.
+ r.instance_eval { @header['transfer-encoding'] = nil }
+ r.reading_body(socket, true) {}
+
+ # Delete the transfer-encoding key from r.@header if there wasn't one,
+ # else restore the saved_transfer_encoding.
+ if saved_transfer_encoding.nil?
+ r.instance_eval { @header.delete('transfer-encoding') }
+ else
+ r.instance_eval { @header['transfer-encoding'] = saved_transfer_encoding }
+ end
+ r
+ else raise StandardError, "Handler unimplemented for response #{options[:response]}"
+ end
+ end
+
+ def has_baked_response?
+ options.has_key?(:response)
+ end
+
+ def optionally_raise(response)
+ return unless options.has_key?(:exception)
+
+ case options[:exception].to_s
+ when "Net::HTTPError", "OpenURI::HTTPError"
+ raise options[:exception].new('Exception from FakeWeb', response)
+ else
+ raise options[:exception].new('Exception from FakeWeb')
+ end
+ end
+
+ def meta_information
+ options.has_key?(:status) ? options[:status] : [200, 'OK']
+ end
+
+ def print_file_string_options_deprecation_warning
+ which = options.has_key?(:file) ? :file : :string
+ $stderr.puts
+ $stderr.puts "Deprecation warning: FakeWeb's :#{which} option has been renamed to :body."
+ $stderr.puts "Just replace :#{which} with :body in your FakeWeb.register_uri calls."
+ $stderr.puts "Called at #{caller[6]}"
+ end
+
+ end
+end
\ No newline at end of file
diff --git a/fakeweb-1.2.5/lib/fake_web/response.rb b/fakeweb-1.2.5/lib/fake_web/response.rb
new file mode 100644
index 0000000..41ba255
--- /dev/null
+++ b/fakeweb-1.2.5/lib/fake_web/response.rb
@@ -0,0 +1,10 @@
+module FakeWeb
+ module Response #:nodoc:
+
+ def read_body(*args, &block)
+ yield @body if block_given?
+ @body
+ end
+
+ end
+end
\ No newline at end of file
diff --git a/fakeweb-1.2.5/lib/fake_web/stub_socket.rb b/fakeweb-1.2.5/lib/fake_web/stub_socket.rb
new file mode 100644
index 0000000..008681c
--- /dev/null
+++ b/fakeweb-1.2.5/lib/fake_web/stub_socket.rb
@@ -0,0 +1,15 @@
+module FakeWeb
+ class StubSocket #:nodoc:
+
+ def initialize(*args)
+ end
+
+ def closed?
+ @closed ||= true
+ end
+
+ def readuntil(*args)
+ end
+
+ end
+end
\ No newline at end of file
diff --git a/fakeweb-1.2.5/lib/fake_web/utility.rb b/fakeweb-1.2.5/lib/fake_web/utility.rb
new file mode 100644
index 0000000..c3c0d52
--- /dev/null
+++ b/fakeweb-1.2.5/lib/fake_web/utility.rb
@@ -0,0 +1,22 @@
+module FakeWeb
+ module Utility #:nodoc:
+
+ def self.decode_userinfo_from_header(header)
+ header.sub(/^Basic /, "").unpack("m").first
+ end
+
+ def self.encode_unsafe_chars_in_userinfo(userinfo)
+ unsafe_in_userinfo = /[^#{URI::REGEXP::PATTERN::UNRESERVED};&=+$,]|^(#{URI::REGEXP::PATTERN::ESCAPED})/
+ userinfo.split(":").map { |part| URI.escape(part, unsafe_in_userinfo) }.join(":")
+ end
+
+ def self.strip_default_port_from_uri(uri)
+ case uri
+ when %r{^http://} then uri.sub(%r{:80(/|$)}, '\1')
+ when %r{^https://} then uri.sub(%r{:443(/|$)}, '\1')
+ else uri
+ end
+ end
+
+ end
+end
diff --git a/fakeweb-1.2.5/lib/fakeweb.rb b/fakeweb-1.2.5/lib/fakeweb.rb
new file mode 100644
index 0000000..6982966
--- /dev/null
+++ b/fakeweb-1.2.5/lib/fakeweb.rb
@@ -0,0 +1,2 @@
+# So you can require "fakeweb" instead of "fake_web"
+require "fake_web"
\ No newline at end of file
diff --git a/fakeweb-1.2.5/test/fixtures/google_response_from_curl b/fakeweb-1.2.5/test/fixtures/google_response_from_curl
new file mode 100644
index 0000000..fe2fe39
--- /dev/null
+++ b/fakeweb-1.2.5/test/fixtures/google_response_from_curl
@@ -0,0 +1,12 @@
+HTTP/1.1 200 OK
+Cache-Control: private, max-age=0
+Date: Sun, 01 Feb 2009 02:16:24 GMT
+Expires: -1
+Content-Type: text/html; charset=ISO-8859-1
+Set-Cookie: PREF=ID=a6d9b5f5a4056dfe:TM=1233454584:LM=1233454584:S=U9pSwSu4eQwOPenX; expires=Tue, 01-Feb-2011 02:16:24 GMT; path=/; domain=.google.com
+Server: gws
+Transfer-Encoding: chunked
+
+
Google

Share what you know. Write a Knol.
Advertising Programs - Business Solutions - About Google©2009 - Privacy
\ No newline at end of file
diff --git a/fakeweb-1.2.5/test/fixtures/google_response_with_transfer_encoding b/fakeweb-1.2.5/test/fixtures/google_response_with_transfer_encoding
new file mode 100644
index 0000000..82025d3
--- /dev/null
+++ b/fakeweb-1.2.5/test/fixtures/google_response_with_transfer_encoding
@@ -0,0 +1,17 @@
+HTTP/1.1 200 OK
+Cache-Control: private, max-age=0
+Date: Sun, 01 Feb 2009 01:54:36 GMT
+Expires: -1
+Content-Type: text/html; charset=ISO-8859-1
+Set-Cookie: PREF=ID=4320bcaa30d097de:TM=1233453276:LM=1233453276:S=Eio39bg_nIabTxzL; expires=Tue, 01-Feb-2011 01:54:36 GMT; path=/; domain=.google.com
+Server: gws
+Transfer-Encoding: chunked
+
+fef
+Google

Share what you know. Write a Knol.
Advertising Programs - Business Solutions - About Google©2009 - Privacy
+0
+
diff --git a/fakeweb-1.2.5/test/fixtures/google_response_without_transfer_encoding b/fakeweb-1.2.5/test/fixtures/google_response_without_transfer_encoding
new file mode 100644
index 0000000..51433c9
--- /dev/null
+++ b/fakeweb-1.2.5/test/fixtures/google_response_without_transfer_encoding
@@ -0,0 +1,11 @@
+HTTP/1.0 200 OK
+Cache-Control: private, max-age=0
+Date: Sun, 01 Feb 2009 01:55:33 GMT
+Expires: -1
+Content-Type: text/html; charset=ISO-8859-1
+Set-Cookie: PREF=ID=3c140c3eb4c4f516:TM=1233453333:LM=1233453333:S=OH7sElk2hOWkb9ot; expires=Tue, 01-Feb-2011 01:55:33 GMT; path=/; domain=.google.com
+Server: gws
+
+Google

Share what you know. Write a Knol.
Advertising Programs - Business Solutions - About Google©2009 - Privacy
\ No newline at end of file
diff --git a/fakeweb-1.2.5/test/fixtures/test_example.txt b/fakeweb-1.2.5/test/fixtures/test_example.txt
new file mode 100644
index 0000000..6310da9
--- /dev/null
+++ b/fakeweb-1.2.5/test/fixtures/test_example.txt
@@ -0,0 +1 @@
+test example content
\ No newline at end of file
diff --git a/fakeweb-1.2.5/test/fixtures/test_txt_file b/fakeweb-1.2.5/test/fixtures/test_txt_file
new file mode 100644
index 0000000..8cf2f17
--- /dev/null
+++ b/fakeweb-1.2.5/test/fixtures/test_txt_file
@@ -0,0 +1,3 @@
+line 1
+line 2
+line 3
\ No newline at end of file
diff --git a/fakeweb-1.2.5/test/test_allow_net_connect.rb b/fakeweb-1.2.5/test/test_allow_net_connect.rb
new file mode 100644
index 0000000..6f118fa
--- /dev/null
+++ b/fakeweb-1.2.5/test/test_allow_net_connect.rb
@@ -0,0 +1,85 @@
+require File.join(File.dirname(__FILE__), "test_helper")
+
+class TestFakeWebAllowNetConnect < Test::Unit::TestCase
+
+ def test_unregistered_requests_are_passed_through_when_allow_net_connect_is_true
+ FakeWeb.allow_net_connect = true
+ setup_expectations_for_real_apple_hot_news_request
+ Net::HTTP.get(URI.parse("http://images.apple.com/main/rss/hotnews/hotnews.rss"))
+ end
+
+ def test_raises_for_unregistered_requests_when_allow_net_connect_is_false
+ FakeWeb.allow_net_connect = false
+ exception = assert_raise FakeWeb::NetConnectNotAllowedError do
+ Net::HTTP.get(URI.parse("http://example.com/"))
+ end
+ end
+
+ def test_exception_message_includes_unregistered_request_method_and_uri_but_no_default_port
+ FakeWeb.allow_net_connect = false
+ exception = assert_raise FakeWeb::NetConnectNotAllowedError do
+ Net::HTTP.get(URI.parse("http://example.com/"))
+ end
+ assert exception.message.include?("GET http://example.com/")
+
+ exception = assert_raise FakeWeb::NetConnectNotAllowedError do
+ http = Net::HTTP.new("example.com", 443)
+ http.use_ssl = true
+ http.get("/")
+ end
+ assert exception.message.include?("GET https://example.com/")
+ end
+
+ def test_exception_message_includes_unregistered_request_port_when_not_default
+ FakeWeb.allow_net_connect = false
+ exception = assert_raise FakeWeb::NetConnectNotAllowedError do
+ Net::HTTP.start("example.com", 8000) { |http| http.get("/") }
+ end
+ assert exception.message.include?("GET http://example.com:8000/")
+
+ exception = assert_raise FakeWeb::NetConnectNotAllowedError do
+ http = Net::HTTP.new("example.com", 4433)
+ http.use_ssl = true
+ http.get("/")
+ end
+ assert exception.message.include?("GET https://example.com:4433/")
+ end
+
+ def test_exception_message_includes_unregistered_request_port_when_not_default_with_path
+ FakeWeb.allow_net_connect = false
+ exception = assert_raise FakeWeb::NetConnectNotAllowedError do
+ Net::HTTP.start("example.com", 8000) { |http| http.get("/test") }
+ end
+ assert exception.message.include?("GET http://example.com:8000/test")
+
+ exception = assert_raise FakeWeb::NetConnectNotAllowedError do
+ http = Net::HTTP.new("example.com", 4433)
+ http.use_ssl = true
+ http.get("/test")
+ end
+ assert exception.message.include?("GET https://example.com:4433/test")
+ end
+
+ def test_question_mark_method_returns_true_after_setting_allow_net_connect_to_true
+ FakeWeb.allow_net_connect = true
+ assert FakeWeb.allow_net_connect?
+ end
+
+ def test_question_mark_method_returns_false_after_setting_allow_net_connect_to_false
+ FakeWeb.allow_net_connect = false
+ assert !FakeWeb.allow_net_connect?
+ end
+
+end
+
+
+class TestFakeWebAllowNetConnectWithCleanState < Test::Unit::TestCase
+ # Our test_helper.rb sets allow_net_connect = false in an inherited #setup
+ # method. Disable that here to test the default setting.
+ def setup; end
+ def teardown; end
+
+ def test_allow_net_connect_is_true_by_default
+ assert FakeWeb.allow_net_connect?
+ end
+end
diff --git a/fakeweb-1.2.5/test/test_deprecations.rb b/fakeweb-1.2.5/test/test_deprecations.rb
new file mode 100644
index 0000000..1addc01
--- /dev/null
+++ b/fakeweb-1.2.5/test/test_deprecations.rb
@@ -0,0 +1,54 @@
+require File.join(File.dirname(__FILE__), "test_helper")
+
+class TestDeprecations < Test::Unit::TestCase
+
+ def test_register_uri_without_method_argument_prints_deprecation_warning
+ warning = capture_stderr do
+ FakeWeb.register_uri("http://example.com", :body => "test")
+ end
+ assert_match /deprecation warning: fakeweb/i, warning
+ end
+
+ def test_registered_uri_without_method_argument_prints_deprecation_warning
+ warning = capture_stderr do
+ FakeWeb.registered_uri?("http://example.com")
+ end
+ assert_match /deprecation warning: fakeweb/i, warning
+ end
+
+ def test_response_for_without_method_argument_prints_deprecation_warning
+ warning = capture_stderr do
+ FakeWeb.response_for("http://example.com")
+ end
+ assert_match /deprecation warning: fakeweb/i, warning
+ end
+
+ def test_register_uri_without_method_argument_prints_deprecation_warning_with_correct_caller
+ warning = capture_stderr do
+ FakeWeb.register_uri("http://example.com", :body => "test")
+ end
+ assert_match /Called at.*?test_deprecations\.rb/i, warning
+ end
+
+ def test_register_uri_with_string_option_prints_deprecation_warning
+ warning = capture_stderr do
+ FakeWeb.register_uri(:get, "http://example.com", :string => "test")
+ end
+ assert_match /deprecation warning: fakeweb's :string option/i, warning
+ end
+
+ def test_register_uri_with_file_option_prints_deprecation_warning
+ warning = capture_stderr do
+ FakeWeb.register_uri(:get, "http://example.com", :file => File.dirname(__FILE__) + '/fixtures/test_example.txt')
+ end
+ assert_match /deprecation warning: fakeweb's :file option/i, warning
+ end
+
+ def test_register_uri_with_string_option_prints_deprecation_warning_with_correct_caller
+ warning = capture_stderr do
+ FakeWeb.register_uri(:get, "http://example.com", :string => "test")
+ end
+ assert_match /Called at.*?test_deprecations\.rb/i, warning
+ end
+
+end
diff --git a/fakeweb-1.2.5/test/test_fake_authentication.rb b/fakeweb-1.2.5/test/test_fake_authentication.rb
new file mode 100644
index 0000000..8490b4b
--- /dev/null
+++ b/fakeweb-1.2.5/test/test_fake_authentication.rb
@@ -0,0 +1,92 @@
+require File.join(File.dirname(__FILE__), "test_helper")
+
+class TestFakeAuthentication < Test::Unit::TestCase
+
+ def test_register_uri_with_authentication
+ FakeWeb.register_uri(:get, 'http://user:pass@mock/test_example.txt', :body => "example")
+ assert FakeWeb.registered_uri?(:get, 'http://user:pass@mock/test_example.txt')
+ end
+
+ def test_register_uri_with_authentication_doesnt_trigger_without
+ FakeWeb.register_uri(:get, 'http://user:pass@mock/test_example.txt', :body => "example")
+ assert !FakeWeb.registered_uri?(:get, 'http://mock/test_example.txt')
+ end
+
+ def test_register_uri_with_authentication_doesnt_trigger_with_incorrect_credentials
+ FakeWeb.register_uri(:get, 'http://user:pass@mock/test_example.txt', :body => "example")
+ assert !FakeWeb.registered_uri?(:get, 'http://user:wrong@mock/test_example.txt')
+ end
+
+ def test_unauthenticated_request
+ FakeWeb.register_uri(:get, 'http://mock/auth.txt', :body => 'unauthorized')
+ http = Net::HTTP.new('mock', 80)
+ req = Net::HTTP::Get.new('/auth.txt')
+ assert_equal 'unauthorized', http.request(req).body
+ end
+
+ def test_authenticated_request
+ FakeWeb.register_uri(:get, 'http://user:pass@mock/auth.txt', :body => 'authorized')
+ http = Net::HTTP.new('mock',80)
+ req = Net::HTTP::Get.new('/auth.txt')
+ req.basic_auth 'user', 'pass'
+ assert_equal 'authorized', http.request(req).body
+ end
+
+ def test_authenticated_request_where_only_userinfo_differs
+ FakeWeb.register_uri(:get, 'http://user:pass@mock/auth.txt', :body => 'first user')
+ FakeWeb.register_uri(:get, 'http://user2:pass@mock/auth.txt', :body => 'second user')
+ http = Net::HTTP.new('mock')
+ req = Net::HTTP::Get.new('/auth.txt')
+ req.basic_auth 'user2', 'pass'
+ assert_equal 'second user', http.request(req).body
+ end
+
+ def test_basic_auth_support_is_transparent_to_oauth
+ FakeWeb.register_uri(:get, "http://sp.example.com/protected", :body => "secret")
+
+ # from http://oauth.net/core/1.0/#auth_header
+ auth_header = <<-HEADER
+ OAuth realm="http://sp.example.com/",
+ oauth_consumer_key="0685bd9184jfhq22",
+ oauth_token="ad180jjd733klru7",
+ oauth_signature_method="HMAC-SHA1",
+ oauth_signature="wOJIO9A2W5mFwDgiDvZbTSMK%2FPY%3D",
+ oauth_timestamp="137131200",
+ oauth_nonce="4572616e48616d6d65724c61686176",
+ oauth_version="1.0"
+ HEADER
+ auth_header.gsub!(/\s+/, " ").strip!
+
+ http = Net::HTTP.new("sp.example.com", 80)
+ response = nil
+ http.start do |request|
+ response = request.get("/protected", {"authorization" => auth_header})
+ end
+ assert_equal "secret", response.body
+ end
+
+ def test_basic_auth_when_userinfo_contains_allowed_unencoded_characters
+ FakeWeb.register_uri(:get, "http://roses&hel1o,(+$):so;longs=@example.com", :body => "authorized")
+ http = Net::HTTP.new("example.com")
+ request = Net::HTTP::Get.new("/")
+ request.basic_auth("roses&hel1o,(+$)", "so;longs=")
+ assert_equal "authorized", http.request(request).body
+ end
+
+ def test_basic_auth_when_userinfo_contains_encoded_at_sign
+ FakeWeb.register_uri(:get, "http://user%40example.com:secret@example.com", :body => "authorized")
+ http = Net::HTTP.new("example.com")
+ request = Net::HTTP::Get.new("/")
+ request.basic_auth("user@example.com", "secret")
+ assert_equal "authorized", http.request(request).body
+ end
+
+ def test_basic_auth_when_userinfo_contains_allowed_encoded_characters
+ FakeWeb.register_uri(:get, "http://us%20er:sec%20%2F%2Fret%3F@example.com", :body => "authorized")
+ http = Net::HTTP.new("example.com")
+ request = Net::HTTP::Get.new("/")
+ request.basic_auth("us er", "sec //ret?")
+ assert_equal "authorized", http.request(request).body
+ end
+
+end
diff --git a/fakeweb-1.2.5/test/test_fake_web.rb b/fakeweb-1.2.5/test/test_fake_web.rb
new file mode 100644
index 0000000..8f2a451
--- /dev/null
+++ b/fakeweb-1.2.5/test/test_fake_web.rb
@@ -0,0 +1,518 @@
+require File.join(File.dirname(__FILE__), "test_helper")
+
+class TestFakeWeb < Test::Unit::TestCase
+
+ def test_register_uri
+ FakeWeb.register_uri(:get, 'http://mock/test_example.txt', :body => "example")
+ assert FakeWeb.registered_uri?(:get, 'http://mock/test_example.txt')
+ end
+
+ def test_register_uri_with_wrong_number_of_arguments
+ assert_raises ArgumentError do
+ FakeWeb.register_uri("http://example.com")
+ end
+ assert_raises ArgumentError do
+ FakeWeb.register_uri(:get, "http://example.com", "/example", :body => "example")
+ end
+ end
+
+ def test_registered_uri_with_wrong_number_of_arguments
+ assert_raises ArgumentError do
+ FakeWeb.registered_uri?
+ end
+ assert_raises ArgumentError do
+ FakeWeb.registered_uri?(:get, "http://example.com", "/example")
+ end
+ end
+
+ def test_response_for_with_wrong_number_of_arguments
+ assert_raises ArgumentError do
+ FakeWeb.response_for
+ end
+ assert_raises ArgumentError do
+ FakeWeb.response_for(:get, "http://example.com", "/example")
+ end
+ end
+
+ def test_register_uri_without_domain_name
+ assert_raises URI::InvalidURIError do
+ FakeWeb.register_uri(:get, 'test_example2.txt', File.dirname(__FILE__) + '/fixtures/test_example.txt')
+ end
+ end
+
+ def test_register_uri_with_port_and_check_with_port
+ FakeWeb.register_uri(:get, 'http://example.com:3000/', :body => 'foo')
+ assert FakeWeb.registered_uri?(:get, 'http://example.com:3000/')
+ end
+
+ def test_register_uri_with_port_and_check_without_port
+ FakeWeb.register_uri(:get, 'http://example.com:3000/', :body => 'foo')
+ assert !FakeWeb.registered_uri?(:get, 'http://example.com/')
+ end
+
+ def test_register_uri_with_default_port_for_http_and_check_without_port
+ FakeWeb.register_uri(:get, 'http://example.com:80/', :body => 'foo')
+ assert FakeWeb.registered_uri?(:get, 'http://example.com/')
+ end
+
+ def test_register_uri_with_default_port_for_https_and_check_without_port
+ FakeWeb.register_uri(:get, 'https://example.com:443/', :body => 'foo')
+ assert FakeWeb.registered_uri?(:get, 'https://example.com/')
+ end
+
+ def test_register_uri_with_no_port_for_http_and_check_with_default_port
+ FakeWeb.register_uri(:get, 'http://example.com/', :body => 'foo')
+ assert FakeWeb.registered_uri?(:get, 'http://example.com:80/')
+ end
+
+ def test_register_uri_with_no_port_for_https_and_check_with_default_port
+ FakeWeb.register_uri(:get, 'https://example.com/', :body => 'foo')
+ assert FakeWeb.registered_uri?(:get, 'https://example.com:443/')
+ end
+
+ def test_register_uri_with_no_port_for_https_and_check_with_443_on_http
+ FakeWeb.register_uri(:get, 'https://example.com/', :body => 'foo')
+ assert !FakeWeb.registered_uri?(:get, 'http://example.com:443/')
+ end
+
+ def test_register_uri_with_no_port_for_http_and_check_with_80_on_https
+ FakeWeb.register_uri(:get, 'http://example.com/', :body => 'foo')
+ assert !FakeWeb.registered_uri?(:get, 'https://example.com:80/')
+ end
+
+ def test_register_uri_for_any_method_explicitly
+ FakeWeb.register_uri(:any, "http://example.com/rpc_endpoint", :body => "OK")
+ assert FakeWeb.registered_uri?(:get, "http://example.com/rpc_endpoint")
+ assert FakeWeb.registered_uri?(:post, "http://example.com/rpc_endpoint")
+ assert FakeWeb.registered_uri?(:put, "http://example.com/rpc_endpoint")
+ assert FakeWeb.registered_uri?(:delete, "http://example.com/rpc_endpoint")
+ assert FakeWeb.registered_uri?(:any, "http://example.com/rpc_endpoint")
+ capture_stderr do # silence deprecation warning
+ assert FakeWeb.registered_uri?("http://example.com/rpc_endpoint")
+ end
+ end
+
+ def test_register_uri_for_get_method_only
+ FakeWeb.register_uri(:get, "http://example.com/users", :body => "User list")
+ assert FakeWeb.registered_uri?(:get, "http://example.com/users")
+ assert !FakeWeb.registered_uri?(:post, "http://example.com/users")
+ assert !FakeWeb.registered_uri?(:put, "http://example.com/users")
+ assert !FakeWeb.registered_uri?(:delete, "http://example.com/users")
+ assert !FakeWeb.registered_uri?(:any, "http://example.com/users")
+ capture_stderr do # silence deprecation warning
+ assert !FakeWeb.registered_uri?("http://example.com/users")
+ end
+ end
+
+ def test_response_for_with_registered_uri
+ FakeWeb.register_uri(:get, 'http://mock/test_example.txt', :body => File.dirname(__FILE__) + '/fixtures/test_example.txt')
+ assert_equal 'test example content', FakeWeb.response_for(:get, 'http://mock/test_example.txt').body
+ end
+
+ def test_response_for_with_unknown_uri
+ assert_nil FakeWeb.response_for(:get, 'http://example.com/')
+ end
+
+ def test_response_for_with_put_method
+ FakeWeb.register_uri(:put, "http://example.com", :body => "response")
+ assert_equal 'response', FakeWeb.response_for(:put, "http://example.com").body
+ end
+
+ def test_response_for_with_any_method_explicitly
+ FakeWeb.register_uri(:any, "http://example.com", :body => "response")
+ assert_equal 'response', FakeWeb.response_for(:get, "http://example.com").body
+ assert_equal 'response', FakeWeb.response_for(:any, "http://example.com").body
+ end
+
+ def test_content_for_registered_uri_with_port_and_request_with_port
+ FakeWeb.register_uri(:get, 'http://example.com:3000/', :body => 'test example content')
+ response = Net::HTTP.start('example.com', 3000) { |http| http.get('/') }
+ assert_equal 'test example content', response.body
+ end
+
+ def test_content_for_registered_uri_with_default_port_for_http_and_request_without_port
+ FakeWeb.register_uri(:get, 'http://example.com:80/', :body => 'test example content')
+ response = Net::HTTP.start('example.com') { |http| http.get('/') }
+ assert_equal 'test example content', response.body
+ end
+
+ def test_content_for_registered_uri_with_no_port_for_http_and_request_with_default_port
+ FakeWeb.register_uri(:get, 'http://example.com/', :body => 'test example content')
+ response = Net::HTTP.start('example.com', 80) { |http| http.get('/') }
+ assert_equal 'test example content', response.body
+ end
+
+ def test_content_for_registered_uri_with_default_port_for_https_and_request_with_default_port
+ FakeWeb.register_uri(:get, 'https://example.com:443/', :body => 'test example content')
+ http = Net::HTTP.new('example.com', 443)
+ http.use_ssl = true
+ response = http.get('/')
+ assert_equal 'test example content', response.body
+ end
+
+ def test_content_for_registered_uri_with_no_port_for_https_and_request_with_default_port
+ FakeWeb.register_uri(:get, 'https://example.com/', :body => 'test example content')
+ http = Net::HTTP.new('example.com', 443)
+ http.use_ssl = true
+ response = http.get('/')
+ assert_equal 'test example content', response.body
+ end
+
+ def test_content_for_registered_uris_with_ports_on_same_domain_and_request_without_port
+ FakeWeb.register_uri(:get, 'http://example.com:3000/', :body => 'port 3000')
+ FakeWeb.register_uri(:get, 'http://example.com/', :body => 'port 80')
+ response = Net::HTTP.start('example.com') { |http| http.get('/') }
+ assert_equal 'port 80', response.body
+ end
+
+ def test_content_for_registered_uris_with_ports_on_same_domain_and_request_with_port
+ FakeWeb.register_uri(:get, 'http://example.com:3000/', :body => 'port 3000')
+ FakeWeb.register_uri(:get, 'http://example.com/', :body => 'port 80')
+ response = Net::HTTP.start('example.com', 3000) { |http| http.get('/') }
+ assert_equal 'port 3000', response.body
+ end
+
+ def test_content_for_registered_uri_with_get_method_only
+ FakeWeb.allow_net_connect = false
+ FakeWeb.register_uri(:get, "http://example.com/", :body => "test example content")
+ http = Net::HTTP.new('example.com')
+ assert_equal 'test example content', http.get('/').body
+ assert_raises(FakeWeb::NetConnectNotAllowedError) { http.post('/', nil) }
+ assert_raises(FakeWeb::NetConnectNotAllowedError) { http.put('/', nil) }
+ assert_raises(FakeWeb::NetConnectNotAllowedError) { http.delete('/') }
+ end
+
+ def test_content_for_registered_uri_with_any_method_explicitly
+ FakeWeb.allow_net_connect = false
+ FakeWeb.register_uri(:any, "http://example.com/", :body => "test example content")
+ http = Net::HTTP.new('example.com')
+ assert_equal 'test example content', http.get('/').body
+ assert_equal 'test example content', http.post('/', nil).body
+ assert_equal 'test example content', http.put('/', nil).body
+ assert_equal 'test example content', http.delete('/').body
+ end
+
+ def test_content_for_registered_uri_with_any_method_implicitly
+ FakeWeb.allow_net_connect = false
+ capture_stderr do # silence deprecation warning
+ FakeWeb.register_uri("http://example.com/", :body => "test example content")
+ end
+
+ http = Net::HTTP.new('example.com')
+ assert_equal 'test example content', http.get('/').body
+ assert_equal 'test example content', http.post('/', nil).body
+ assert_equal 'test example content', http.put('/', nil).body
+ assert_equal 'test example content', http.delete('/').body
+ end
+
+ def test_mock_request_with_block
+ FakeWeb.register_uri(:get, 'http://mock/test_example.txt', :body => File.dirname(__FILE__) + '/fixtures/test_example.txt')
+ response = Net::HTTP.start('mock') { |http| http.get('/test_example.txt') }
+ assert_equal 'test example content', response.body
+ end
+
+ def test_request_with_registered_body_yields_the_response_body_to_a_request_block
+ FakeWeb.register_uri(:get, "http://example.com", :body => "content")
+ body = nil
+ Net::HTTP.start("example.com") do |http|
+ http.get("/") do |response_body|
+ body = response_body
+ end
+ end
+ assert_equal "content", body
+ end
+
+ def test_request_with_registered_response_yields_the_response_body_to_a_request_block
+ fake_response = Net::HTTPOK.new('1.1', '200', 'OK')
+ fake_response.instance_variable_set(:@body, "content")
+ FakeWeb.register_uri(:get, 'http://example.com', :response => fake_response)
+ body = nil
+ Net::HTTP.start("example.com") do |http|
+ http.get("/") do |response_body|
+ body = response_body
+ end
+ end
+ assert_equal "content", body
+ end
+
+ def test_mock_request_with_undocumented_full_uri_argument_style
+ FakeWeb.register_uri(:get, 'http://mock/test_example.txt', :body => File.dirname(__FILE__) + '/fixtures/test_example.txt')
+ response = Net::HTTP.start('mock') { |query| query.get('http://mock/test_example.txt') }
+ assert_equal 'test example content', response.body
+ end
+
+ def test_mock_request_with_undocumented_full_uri_argument_style_and_query
+ FakeWeb.register_uri(:get, 'http://mock/test_example.txt?a=b', :body => 'test query content')
+ response = Net::HTTP.start('mock') { |query| query.get('http://mock/test_example.txt?a=b') }
+ assert_equal 'test query content', response.body
+ end
+
+ def test_mock_post
+ FakeWeb.register_uri(:post, 'http://mock/test_example.txt', :body => File.dirname(__FILE__) + '/fixtures/test_example.txt')
+ response = Net::HTTP.start('mock') { |query| query.post('/test_example.txt', '') }
+ assert_equal 'test example content', response.body
+ end
+
+ def test_mock_post_with_string_as_registered_uri
+ FakeWeb.register_uri(:post, 'http://mock/test_string.txt', :body => 'foo')
+ response = Net::HTTP.start('mock') { |query| query.post('/test_string.txt', '') }
+ assert_equal 'foo', response.body
+ end
+
+ def test_mock_get_with_request_as_registered_uri
+ fake_response = Net::HTTPOK.new('1.1', '200', 'OK')
+ FakeWeb.register_uri(:get, 'http://mock/test_response', :response => fake_response)
+ response = Net::HTTP.start('mock') { |query| query.get('/test_response') }
+ assert_equal fake_response, response
+ end
+
+ def test_mock_get_with_request_from_file_as_registered_uri
+ FakeWeb.register_uri(:get, 'http://www.google.com/', :response => File.dirname(__FILE__) + '/fixtures/google_response_without_transfer_encoding')
+ response = Net::HTTP.start('www.google.com') { |query| query.get('/') }
+ assert_equal '200', response.code
+ assert response.body.include?('Google')
+ end
+
+ def test_mock_post_with_request_from_file_as_registered_uri
+ FakeWeb.register_uri(:post, 'http://www.google.com/', :response => File.dirname(__FILE__) + '/fixtures/google_response_without_transfer_encoding')
+ response = Net::HTTP.start('www.google.com') { |query| query.post('/', '') }
+ assert_equal "200", response.code
+ assert response.body.include?('Google')
+ end
+
+ def test_proxy_request
+ FakeWeb.register_uri(:get, 'http://www.example.com/', :body => "hello world")
+ FakeWeb.register_uri(:get, 'http://your.proxy.host/', :body => "lala")
+
+ response = nil
+ Net::HTTP::Proxy('your.proxy.host', 8080).start('www.example.com') do |http|
+ response = http.get('/')
+ end
+ assert_equal "hello world", response.body
+ end
+
+ def test_https_request
+ FakeWeb.register_uri(:get, 'https://www.example.com/', :body => "Hello World")
+ http = Net::HTTP.new('www.example.com', 443)
+ http.use_ssl = true
+ response = http.get('/')
+ assert_equal "Hello World", response.body
+ end
+
+ def test_register_unimplemented_response
+ FakeWeb.register_uri(:get, 'http://mock/unimplemented', :response => 1)
+ assert_raises StandardError do
+ Net::HTTP.start('mock') { |q| q.get('/unimplemented') }
+ end
+ end
+
+ def test_real_http_request
+ FakeWeb.allow_net_connect = true
+ setup_expectations_for_real_apple_hot_news_request
+
+ resp = nil
+ Net::HTTP.start('images.apple.com') do |query|
+ resp = query.get('/main/rss/hotnews/hotnews.rss')
+ end
+ assert resp.body.include?('Apple')
+ assert resp.body.include?('News')
+ end
+
+ def test_real_http_request_with_undocumented_full_uri_argument_style
+ FakeWeb.allow_net_connect = true
+ setup_expectations_for_real_apple_hot_news_request(:path => 'http://images.apple.com/main/rss/hotnews/hotnews.rss')
+
+ resp = nil
+ Net::HTTP.start('images.apple.com') do |query|
+ resp = query.get('http://images.apple.com/main/rss/hotnews/hotnews.rss')
+ end
+ assert resp.body.include?('Apple')
+ assert resp.body.include?('News')
+ end
+
+ def test_real_https_request
+ FakeWeb.allow_net_connect = true
+ setup_expectations_for_real_apple_hot_news_request(:port => 443)
+
+ http = Net::HTTP.new('images.apple.com', 443)
+ http.use_ssl = true
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE # silence certificate warning
+ response = http.get('/main/rss/hotnews/hotnews.rss')
+ assert response.body.include?('Apple')
+ assert response.body.include?('News')
+ end
+
+ def test_real_request_on_same_domain_as_mock
+ FakeWeb.allow_net_connect = true
+ setup_expectations_for_real_apple_hot_news_request
+
+ FakeWeb.register_uri(:get, 'http://images.apple.com/test_string.txt', :body => 'foo')
+
+ resp = nil
+ Net::HTTP.start('images.apple.com') do |query|
+ resp = query.get('/main/rss/hotnews/hotnews.rss')
+ end
+ assert resp.body.include?('Apple')
+ assert resp.body.include?('News')
+ end
+
+ def test_mock_request_on_real_domain
+ FakeWeb.register_uri(:get, 'http://images.apple.com/test_string.txt', :body => 'foo')
+ resp = nil
+ Net::HTTP.start('images.apple.com') do |query|
+ resp = query.get('/test_string.txt')
+ end
+ assert_equal 'foo', resp.body
+ end
+
+ def test_mock_post_that_raises_exception
+ FakeWeb.register_uri(:post, 'http://mock/raising_exception.txt', :exception => StandardError)
+ assert_raises(StandardError) do
+ Net::HTTP.start('mock') do |query|
+ query.post('/raising_exception.txt', 'some data')
+ end
+ end
+ end
+
+ def test_mock_post_that_raises_an_http_error
+ FakeWeb.register_uri(:post, 'http://mock/raising_exception.txt', :exception => Net::HTTPError)
+ assert_raises(Net::HTTPError) do
+ Net::HTTP.start('mock') do |query|
+ query.post('/raising_exception.txt', '')
+ end
+ end
+ end
+
+ def test_raising_an_exception_that_requires_an_argument_to_instantiate
+ FakeWeb.register_uri(:get, "http://example.com/timeout.txt", :exception => Timeout::Error)
+ assert_raises(Timeout::Error) do
+ Net::HTTP.get(URI.parse("http://example.com/timeout.txt"))
+ end
+ end
+
+ def test_mock_instance_syntax
+ FakeWeb.register_uri(:get, 'http://mock/test_example.txt', :body => File.dirname(__FILE__) + '/fixtures/test_example.txt')
+ response = nil
+ uri = URI.parse('http://mock/test_example.txt')
+ http = Net::HTTP.new(uri.host, uri.port)
+ response = http.start do
+ http.get(uri.path)
+ end
+
+ assert_equal 'test example content', response.body
+ end
+
+ def test_mock_via_nil_proxy
+ response = nil
+ proxy_address = nil
+ proxy_port = nil
+ FakeWeb.register_uri(:get, 'http://mock/test_example.txt', :body => File.dirname(__FILE__) + '/fixtures/test_example.txt')
+ uri = URI.parse('http://mock/test_example.txt')
+ http = Net::HTTP::Proxy(proxy_address, proxy_port).new(
+ uri.host, (uri.port or 80))
+ response = http.start do
+ http.get(uri.path)
+ end
+
+ assert_equal 'test example content', response.body
+ end
+
+ def test_response_type
+ FakeWeb.register_uri(:get, 'http://mock/test_example.txt', :body => "test")
+ response = Net::HTTP.start('mock') { |http| http.get('/test_example.txt') }
+ assert_kind_of Net::HTTPSuccess, response
+ end
+
+ def test_mock_request_that_raises_an_http_error_with_a_specific_status
+ FakeWeb.register_uri(:get, 'http://mock/raising_exception.txt', :exception => Net::HTTPError, :status => ['404', 'Not Found'])
+ exception = assert_raises(Net::HTTPError) do
+ Net::HTTP.start('mock') { |http| http.get('/raising_exception.txt') }
+ end
+ assert_equal '404', exception.response.code
+ assert_equal 'Not Found', exception.response.msg
+ end
+
+ def test_mock_rotate_responses
+ FakeWeb.register_uri(:get, 'http://mock/multiple_test_example.txt',
+ [ {:body => File.dirname(__FILE__) + '/fixtures/test_example.txt', :times => 2},
+ {:body => "thrice", :times => 3},
+ {:body => "ever_more"} ])
+
+ uri = URI.parse('http://mock/multiple_test_example.txt')
+ 2.times { assert_equal 'test example content', Net::HTTP.get(uri) }
+ 3.times { assert_equal 'thrice', Net::HTTP.get(uri) }
+ 4.times { assert_equal 'ever_more', Net::HTTP.get(uri) }
+ end
+
+ def test_mock_request_using_response_with_transfer_encoding_header_has_valid_transfer_encoding_header
+ FakeWeb.register_uri(:get, 'http://www.google.com/', :response => File.dirname(__FILE__) + '/fixtures/google_response_with_transfer_encoding')
+ response = Net::HTTP.start('www.google.com') { |query| query.get('/') }
+ assert_not_nil response['transfer-encoding']
+ assert response['transfer-encoding'] == 'chunked'
+ end
+
+ def test_mock_request_using_response_without_transfer_encoding_header_does_not_have_a_transfer_encoding_header
+ FakeWeb.register_uri(:get, 'http://www.google.com/', :response => File.dirname(__FILE__) + '/fixtures/google_response_without_transfer_encoding')
+ response = nil
+ response = Net::HTTP.start('www.google.com') { |query| query.get('/') }
+ assert !response.key?('transfer-encoding')
+ end
+
+ def test_mock_request_using_response_from_curl_has_original_transfer_encoding_header
+ FakeWeb.register_uri(:get, 'http://www.google.com/', :response => File.dirname(__FILE__) + '/fixtures/google_response_from_curl')
+ response = Net::HTTP.start('www.google.com') { |query| query.get('/') }
+ assert_not_nil response['transfer-encoding']
+ assert response['transfer-encoding'] == 'chunked'
+ end
+
+ def test_txt_file_should_have_three_lines
+ FakeWeb.register_uri(:get, 'http://www.google.com/', :body => File.dirname(__FILE__) + '/fixtures/test_txt_file')
+ response = Net::HTTP.start('www.google.com') { |query| query.get('/') }
+ assert response.body.split(/\n/).size == 3, "response has #{response.body.split(/\n/).size} lines should have 3"
+ end
+
+ def test_requiring_fakeweb_instead_of_fake_web
+ require "fakeweb"
+ end
+
+ def test_registering_with_string_containing_null_byte
+ # Regression test for File.exists? raising an ArgumentError ("string
+ # contains null byte") since :response first tries to find by filename.
+ # The string should be treated as a response body, instead, and an
+ # EOFError is raised when the byte is encountered.
+ FakeWeb.register_uri(:get, "http://example.com", :response => "test\0test")
+ assert_raise EOFError do
+ Net::HTTP.get(URI.parse("http://example.com"))
+ end
+
+ FakeWeb.register_uri(:get, "http://example.com", :body => "test\0test")
+ body = Net::HTTP.get(URI.parse("http://example.com"))
+ assert_equal "test\0test", body
+ end
+
+ def test_registering_with_string_that_is_a_directory_name
+ # Similar to above, but for Errno::EISDIR being raised since File.exists?
+ # returns true for directories
+ FakeWeb.register_uri(:get, "http://example.com", :response => File.dirname(__FILE__))
+ assert_raise EOFError do
+ body = Net::HTTP.get(URI.parse("http://example.com"))
+ end
+
+ FakeWeb.register_uri(:get, "http://example.com", :body => File.dirname(__FILE__))
+ body = Net::HTTP.get(URI.parse("http://example.com"))
+ assert_equal File.dirname(__FILE__), body
+ end
+
+ def test_http_version_from_string_response
+ FakeWeb.register_uri(:get, "http://example.com", :body => "example")
+ response = Net::HTTP.start("example.com") { |http| http.get("/") }
+ assert_equal "1.0", response.http_version
+ end
+
+ def test_http_version_from_file_response
+ FakeWeb.register_uri(:get, "http://example.com", :body => File.dirname(__FILE__) + '/fixtures/test_example.txt')
+ response = Net::HTTP.start("example.com") { |http| http.get("/") }
+ assert_equal "1.0", response.http_version
+ end
+
+end
diff --git a/fakeweb-1.2.5/test/test_fake_web_open_uri.rb b/fakeweb-1.2.5/test/test_fake_web_open_uri.rb
new file mode 100644
index 0000000..60a3e78
--- /dev/null
+++ b/fakeweb-1.2.5/test/test_fake_web_open_uri.rb
@@ -0,0 +1,58 @@
+require File.join(File.dirname(__FILE__), "test_helper")
+
+class TestFakeWebOpenURI < Test::Unit::TestCase
+
+ def test_content_for_registered_uri
+ FakeWeb.register_uri(:get, 'http://mock/test_example.txt', :body => File.dirname(__FILE__) + '/fixtures/test_example.txt')
+ assert_equal 'test example content', FakeWeb.response_for(:get, 'http://mock/test_example.txt').body
+ end
+
+ def test_mock_open
+ FakeWeb.register_uri(:get, 'http://mock/test_example.txt', :body => File.dirname(__FILE__) + '/fixtures/test_example.txt')
+ assert_equal 'test example content', open('http://mock/test_example.txt').read
+ end
+
+ def test_mock_open_with_string_as_registered_uri
+ FakeWeb.register_uri(:get, 'http://mock/test_string.txt', :body => 'foo')
+ assert_equal 'foo', open('http://mock/test_string.txt').string
+ end
+
+ def test_real_open
+ FakeWeb.allow_net_connect = true
+ setup_expectations_for_real_apple_hot_news_request
+ resp = open('http://images.apple.com/main/rss/hotnews/hotnews.rss')
+ assert_equal "200", resp.status.first
+ body = resp.read
+ assert body.include?('Apple')
+ assert body.include?('News')
+ end
+
+ def test_mock_open_that_raises_exception
+ FakeWeb.register_uri(:get, 'http://mock/raising_exception.txt', :exception => StandardError)
+ assert_raises(StandardError) do
+ open('http://mock/raising_exception.txt')
+ end
+ end
+
+ def test_mock_open_that_raises_an_http_error
+ FakeWeb.register_uri(:get, 'http://mock/raising_exception.txt', :exception => OpenURI::HTTPError)
+ assert_raises(OpenURI::HTTPError) do
+ open('http://mock/raising_exception.txt')
+ end
+ end
+
+ def test_mock_open_that_raises_an_http_error_with_a_specific_status
+ FakeWeb.register_uri(:get, 'http://mock/raising_exception.txt', :exception => OpenURI::HTTPError, :status => ['123', 'jodel'])
+ exception = assert_raises(OpenURI::HTTPError) do
+ open('http://mock/raising_exception.txt')
+ end
+ assert_equal '123', exception.io.code
+ assert_equal 'jodel', exception.io.message
+ end
+
+ def test_mock_open_with_block
+ FakeWeb.register_uri(:get, 'http://mock/test_example.txt', :body => File.dirname(__FILE__) + '/fixtures/test_example.txt')
+ body = open('http://mock/test_example.txt') { |f| f.readlines }
+ assert_equal 'test example content', body.first
+ end
+end
diff --git a/fakeweb-1.2.5/test/test_helper.rb b/fakeweb-1.2.5/test/test_helper.rb
new file mode 100644
index 0000000..7eb2548
--- /dev/null
+++ b/fakeweb-1.2.5/test/test_helper.rb
@@ -0,0 +1,74 @@
+$:.unshift "#{File.dirname(__FILE__)}/../lib"
+
+require 'test/unit'
+require 'open-uri'
+require 'fake_web'
+require 'rubygems'
+require 'mocha'
+
+
+# Give all tests a common setup and teardown that prevents shared state
+class Test::Unit::TestCase
+ def setup
+ FakeWeb.clean_registry
+ @original_allow_net_connect = FakeWeb.allow_net_connect?
+ FakeWeb.allow_net_connect = false
+ end
+
+ def teardown
+ FakeWeb.allow_net_connect = @original_allow_net_connect
+ end
+end
+
+
+module FakeWebTestHelper
+
+ def capture_stderr
+ $stderr = StringIO.new
+ yield
+ $stderr.rewind && $stderr.read
+ ensure
+ $stderr = STDERR
+ end
+
+ # Sets several expectations (using Mocha) that a real HTTP request makes it
+ # past FakeWeb to the socket layer. You can use this when you need to check
+ # that a request isn't handled by FakeWeb.
+ def setup_expectations_for_real_request(options = {})
+ # Socket handling
+ if options[:port] == 443
+ socket = mock("SSLSocket")
+ OpenSSL::SSL::SSLSocket.expects(:===).with(socket).returns(true).at_least_once
+ OpenSSL::SSL::SSLSocket.expects(:new).with(socket, instance_of(OpenSSL::SSL::SSLContext)).returns(socket).at_least_once
+ socket.stubs(:sync_close=).returns(true)
+ socket.expects(:connect).with().at_least_once
+ else
+ socket = mock("TCPSocket")
+ Socket.expects(:===).with(socket).returns(true)
+ end
+
+ TCPSocket.expects(:open).with(options[:host], options[:port]).returns(socket).at_least_once
+ socket.stubs(:closed?).returns(false)
+ socket.stubs(:close).returns(true)
+
+ # Request/response handling
+ request_parts = ["#{options[:method]} #{options[:path]} HTTP/1.1", "Host: #{options[:host]}"]
+ socket.expects(:write).with(all_of(includes(request_parts[0]), includes(request_parts[1]))).returns(100)
+
+ socket.expects(:sysread).at_least_once.returns("HTTP/1.1 #{options[:response_code]} #{options[:response_message]}\nContent-Length: #{options[:response_body].length}\n\n#{options[:response_body]}").then.raises(EOFError)
+ end
+
+
+ # A helper that calls #setup_expectations_for_real_request for you, using
+ # defaults for our commonly used test request to images.apple.com.
+ def setup_expectations_for_real_apple_hot_news_request(options = {})
+ defaults = { :host => "images.apple.com", :port => 80, :method => "GET",
+ :path => "/main/rss/hotnews/hotnews.rss",
+ :response_code => 200, :response_message => "OK",
+ :response_body => "Apple Hot News" }
+ setup_expectations_for_real_request(defaults.merge(options))
+ end
+
+end
+
+Test::Unit::TestCase.send(:include, FakeWebTestHelper)
diff --git a/fakeweb-1.2.5/test/test_missing_open_uri.rb b/fakeweb-1.2.5/test/test_missing_open_uri.rb
new file mode 100644
index 0000000..2758d90
--- /dev/null
+++ b/fakeweb-1.2.5/test/test_missing_open_uri.rb
@@ -0,0 +1,25 @@
+require File.join(File.dirname(__FILE__), "test_helper")
+
+class TestMissingOpenURI < Test::Unit::TestCase
+
+ def setup
+ super
+ @saved_open_uri = OpenURI
+ Object.send(:remove_const, :OpenURI)
+ end
+
+ def teardown
+ super
+ Object.const_set(:OpenURI, @saved_open_uri)
+ end
+
+
+ def test_register_using_exception_without_open_uri
+ # regression test for Responder needing OpenURI::HTTPError to be defined
+ FakeWeb.register_uri(:get, "http://example.com/", :exception => StandardError)
+ assert_raises(StandardError) do
+ Net::HTTP.start("example.com") { |http| http.get("/") }
+ end
+ end
+
+end
diff --git a/fakeweb-1.2.5/test/test_precedence.rb b/fakeweb-1.2.5/test/test_precedence.rb
new file mode 100644
index 0000000..8b3f965
--- /dev/null
+++ b/fakeweb-1.2.5/test/test_precedence.rb
@@ -0,0 +1,51 @@
+require File.join(File.dirname(__FILE__), "test_helper")
+
+class TestPrecedence < Test::Unit::TestCase
+
+ def test_matching_get_strings_have_precedence_over_matching_get_regexes
+ FakeWeb.register_uri(:get, "http://example.com/test", :body => "string")
+ FakeWeb.register_uri(:get, %r|http://example\.com/test|, :body => "regex")
+ response = Net::HTTP.start("example.com") { |query| query.get('/test') }
+ assert_equal "string", response.body
+ end
+
+ def test_matching_any_strings_have_precedence_over_matching_any_regexes
+ FakeWeb.register_uri(:any, "http://example.com/test", :body => "string")
+ FakeWeb.register_uri(:any, %r|http://example\.com/test|, :body => "regex")
+ response = Net::HTTP.start("example.com") { |query| query.get('/test') }
+ assert_equal "string", response.body
+ end
+
+ def test_matching_get_strings_have_precedence_over_matching_any_strings
+ FakeWeb.register_uri(:get, "http://example.com/test", :body => "get method")
+ FakeWeb.register_uri(:any, "http://example.com/test", :body => "any method")
+ response = Net::HTTP.start("example.com") { |query| query.get('/test') }
+ assert_equal "get method", response.body
+
+ # registration order should not matter
+ FakeWeb.register_uri(:any, "http://example.com/test2", :body => "any method")
+ FakeWeb.register_uri(:get, "http://example.com/test2", :body => "get method")
+ response = Net::HTTP.start("example.com") { |query| query.get('/test2') }
+ assert_equal "get method", response.body
+ end
+
+ def test_matching_any_strings_have_precedence_over_matching_get_regexes
+ FakeWeb.register_uri(:any, "http://example.com/test", :body => "any string")
+ FakeWeb.register_uri(:get, %r|http://example\.com/test|, :body => "get regex")
+ response = Net::HTTP.start("example.com") { |query| query.get('/test') }
+ assert_equal "any string", response.body
+ end
+
+ def test_registered_strings_and_uris_are_equivalent_so_second_takes_precedence
+ FakeWeb.register_uri(:get, "http://example.com/test", :body => "string")
+ FakeWeb.register_uri(:get, URI.parse("http://example.com/test"), :body => "uri")
+ response = Net::HTTP.start("example.com") { |query| query.get('/test') }
+ assert_equal "uri", response.body
+
+ FakeWeb.register_uri(:get, URI.parse("http://example.com/test2"), :body => "uri")
+ FakeWeb.register_uri(:get, "http://example.com/test2", :body => "string")
+ response = Net::HTTP.start("example.com") { |query| query.get('/test2') }
+ assert_equal "string", response.body
+ end
+
+end
diff --git a/fakeweb-1.2.5/test/test_query_string.rb b/fakeweb-1.2.5/test/test_query_string.rb
new file mode 100644
index 0000000..4361ffd
--- /dev/null
+++ b/fakeweb-1.2.5/test/test_query_string.rb
@@ -0,0 +1,45 @@
+require File.join(File.dirname(__FILE__), "test_helper")
+
+class TestFakeWebQueryString < Test::Unit::TestCase
+
+ def test_register_uri_string_with_query_params
+ FakeWeb.register_uri(:get, 'http://example.com/?a=1&b=1', :body => 'foo')
+ assert FakeWeb.registered_uri?(:get, 'http://example.com/?a=1&b=1')
+
+ FakeWeb.register_uri(:post, URI.parse("http://example.org/?a=1&b=1"), :body => "foo")
+ assert FakeWeb.registered_uri?(:post, "http://example.org/?a=1&b=1")
+ end
+
+ def test_register_uri_with_query_params_and_check_in_different_order
+ FakeWeb.register_uri(:get, 'http://example.com/?a=1&b=1', :body => 'foo')
+ assert FakeWeb.registered_uri?(:get, 'http://example.com/?b=1&a=1')
+
+ FakeWeb.register_uri(:post, URI.parse('http://example.org/?a=1&b=1'), :body => 'foo')
+ assert FakeWeb.registered_uri?(:post, 'http://example.org/?b=1&a=1')
+ end
+
+ def test_registered_uri_gets_recognized_with_empty_query_params
+ FakeWeb.register_uri(:get, 'http://example.com/', :body => 'foo')
+ assert FakeWeb.registered_uri?(:get, 'http://example.com/?')
+
+ FakeWeb.register_uri(:post, URI.parse('http://example.org/'), :body => 'foo')
+ assert FakeWeb.registered_uri?(:post, 'http://example.org/?')
+ end
+
+ def test_register_uri_with_empty_query_params_and_check_with_none
+ FakeWeb.register_uri(:get, 'http://example.com/?', :body => 'foo')
+ assert FakeWeb.registered_uri?(:get, 'http://example.com/')
+
+ FakeWeb.register_uri(:post, URI.parse('http://example.org/?'), :body => 'foo')
+ assert FakeWeb.registered_uri?(:post, 'http://example.org/')
+ end
+
+ def test_registry_sort_query_params
+ assert_equal "a=1&b=2", FakeWeb::Registry.instance.send(:sort_query_params, "b=2&a=1")
+ end
+
+ def test_registry_sort_query_params_sorts_by_value_if_keys_collide
+ assert_equal "a=1&a=2&b=2", FakeWeb::Registry.instance.send(:sort_query_params, "a=2&b=2&a=1")
+ end
+
+end
diff --git a/fakeweb-1.2.5/test/test_regexes.rb b/fakeweb-1.2.5/test/test_regexes.rb
new file mode 100644
index 0000000..cffa69f
--- /dev/null
+++ b/fakeweb-1.2.5/test/test_regexes.rb
@@ -0,0 +1,103 @@
+require File.join(File.dirname(__FILE__), "test_helper")
+
+class TestRegexes < Test::Unit::TestCase
+
+ def test_registered_uri_with_pattern
+ FakeWeb.register_uri(:get, %r|http://example.com/test_example/\d+|, :body => "example")
+ assert FakeWeb.registered_uri?(:get, "http://example.com/test_example/25")
+ assert !FakeWeb.registered_uri?(:get, "http://example.com/test_example/abc")
+ end
+
+ def test_response_for_with_matching_registered_uri
+ FakeWeb.register_uri(:get, %r|http://www.google.com|, :body => "Welcome to Google!")
+ assert_equal "Welcome to Google!", FakeWeb.response_for(:get, "http://www.google.com").body
+ end
+
+ def test_response_for_with_matching_registered_uri_and_get_method_matching_to_any_method
+ FakeWeb.register_uri(:any, %r|http://www.example.com|, :body => "example")
+ assert_equal "example", FakeWeb.response_for(:get, "http://www.example.com").body
+ end
+
+ def test_registered_uri_with_authentication_and_pattern
+ FakeWeb.register_uri(:get, %r|http://user:pass@mock/example\.\w+|i, :body => "example")
+ assert FakeWeb.registered_uri?(:get, 'http://user:pass@mock/example.txt')
+ end
+
+ def test_registered_uri_with_authentication_and_pattern_handles_case_insensitivity
+ FakeWeb.register_uri(:get, %r|http://user:pass@mock/example\.\w+|i, :body => "example")
+ assert FakeWeb.registered_uri?(:get, 'http://uSeR:PAss@mock/example.txt')
+ end
+
+ def test_request_with_authentication_and_pattern_handles_case_insensitivity
+ FakeWeb.register_uri(:get, %r|http://user:pass@mock/example\.\w+|i, :body => "example")
+ http = Net::HTTP.new('mock', 80)
+ req = Net::HTTP::Get.new('/example.txt')
+ req.basic_auth 'uSeR', 'PAss'
+ assert_equal "example", http.request(req).body
+ end
+
+ def test_requesting_a_uri_that_matches_two_registered_regexes_raises_an_error
+ FakeWeb.register_uri(:get, %r|http://example\.com/|, :body => "first")
+ FakeWeb.register_uri(:get, %r|http://example\.com/a|, :body => "second")
+ assert_raise FakeWeb::MultipleMatchingRegexpsError do
+ Net::HTTP.start("example.com") { |query| query.get('/a') }
+ end
+ end
+
+ def test_requesting_a_uri_that_matches_two_registered_regexes_raises_an_error_including_request_info
+ FakeWeb.register_uri(:get, %r|http://example\.com/|, :body => "first")
+ FakeWeb.register_uri(:get, %r|http://example\.com/a|, :body => "second")
+ begin
+ Net::HTTP.start("example.com") { |query| query.get('/a') }
+ rescue FakeWeb::MultipleMatchingRegexpsError => exception
+ end
+ assert exception.message.include?("GET http://example.com/a")
+ end
+
+ def test_registry_does_not_find_using_mismatched_protocols_or_ports_when_registered_with_both
+ FakeWeb.register_uri(:get, %r|http://www.example.com:80|, :body => "example")
+ assert !FakeWeb.registered_uri?(:get, "https://www.example.com:80")
+ assert !FakeWeb.registered_uri?(:get, "http://www.example.com:443")
+ end
+
+ def test_registry_only_finds_using_default_port_when_registered_without_if_protocol_matches
+ FakeWeb.register_uri(:get, %r|http://www.example.com/test|, :body => "example")
+ assert FakeWeb.registered_uri?(:get, "http://www.example.com:80/test")
+ assert !FakeWeb.registered_uri?(:get, "http://www.example.com:443/test")
+ assert !FakeWeb.registered_uri?(:get, "https://www.example.com:443/test")
+ FakeWeb.register_uri(:get, %r|https://www.example.org/test|, :body => "example")
+ assert FakeWeb.registered_uri?(:get, "https://www.example.org:443/test")
+ assert !FakeWeb.registered_uri?(:get, "https://www.example.org:80/test")
+ assert !FakeWeb.registered_uri?(:get, "http://www.example.org:80/test")
+ end
+
+ def test_registry_matches_using_mismatched_port_when_registered_without
+ FakeWeb.register_uri(:get, %r|http://www.example.com|, :body => "example")
+ assert FakeWeb.registered_uri?(:get, "http://www.example.com:80")
+ assert FakeWeb.registered_uri?(:get, "http://www.example.com:443")
+ assert FakeWeb.registered_uri?(:get, "http://www.example.com:12345")
+ assert !FakeWeb.registered_uri?(:get, "https://www.example.com:443")
+ assert !FakeWeb.registered_uri?(:get, "https://www.example.com")
+ end
+
+ def test_registry_matches_using_any_protocol_and_port_when_registered_without_protocol_or_port
+ FakeWeb.register_uri(:get, %r|www.example.com|, :body => "example")
+ assert FakeWeb.registered_uri?(:get, "http://www.example.com")
+ assert FakeWeb.registered_uri?(:get, "http://www.example.com:80")
+ assert FakeWeb.registered_uri?(:get, "http://www.example.com:443")
+ assert FakeWeb.registered_uri?(:get, "https://www.example.com")
+ assert FakeWeb.registered_uri?(:get, "https://www.example.com:80")
+ assert FakeWeb.registered_uri?(:get, "https://www.example.com:443")
+ end
+
+ def test_registry_matches_with_query_params
+ FakeWeb.register_uri(:get, %r[example.com/list\?(.*&|)important=1], :body => "example")
+ assert FakeWeb.registered_uri?(:get, "http://example.com/list?hash=123&important=1&unimportant=2")
+ assert FakeWeb.registered_uri?(:get, "http://example.com/list?hash=123&important=12&unimportant=2")
+ assert FakeWeb.registered_uri?(:get, "http://example.com/list?important=1&unimportant=2")
+ assert !FakeWeb.registered_uri?(:get, "http://example.com/list?important=2")
+ assert !FakeWeb.registered_uri?(:get, "http://example.com/list?important=2&unimportant=1")
+ assert !FakeWeb.registered_uri?(:get, "http://example.com/list?hash=123&important=2&unimportant=1")
+ assert !FakeWeb.registered_uri?(:get, "http://example.com/list?notimportant=1&unimportant=1")
+ end
+end
diff --git a/fakeweb-1.2.5/test/test_response_headers.rb b/fakeweb-1.2.5/test/test_response_headers.rb
new file mode 100644
index 0000000..182cd37
--- /dev/null
+++ b/fakeweb-1.2.5/test/test_response_headers.rb
@@ -0,0 +1,67 @@
+require File.join(File.dirname(__FILE__), "test_helper")
+
+class TestResponseHeaders < Test::Unit::TestCase
+
+ def test_content_type_when_registering_with_string_and_content_type_header
+ FakeWeb.register_uri(:get, "http://example.com/users.json", :body => '[{"username": "chrisk"}]', :content_type => "application/json")
+ response = Net::HTTP.start("example.com") { |query| query.get("/users.json") }
+ assert_equal '[{"username": "chrisk"}]', response.body
+ assert_equal "application/json", response['Content-Type']
+ end
+
+ def test_content_type_when_registering_with_string_only
+ FakeWeb.register_uri(:get, "http://example.com/users.json", :body => '[{"username": "chrisk"}]')
+ response = Net::HTTP.start("example.com") { |query| query.get("/users.json") }
+ assert_equal '[{"username": "chrisk"}]', response.body
+ assert_nil response['Content-Type']
+ end
+
+ def test_cookies_when_registering_with_file_and_set_cookie_header
+ FakeWeb.register_uri(:get, "http://example.com/", :body => File.dirname(__FILE__) + '/fixtures/test_example.txt',
+ :set_cookie => "user_id=1; example=yes")
+ response = Net::HTTP.start("example.com") { |query| query.get("/") }
+ assert_equal "test example content", response.body
+ assert_equal "user_id=1; example=yes", response['Set-Cookie']
+ end
+
+ def test_registering_with_baked_response_ignores_header_options
+ fake_response = Net::HTTPOK.new('1.1', '200', 'OK')
+ fake_response["Server"] = "Apache/1.3.27 (Unix)"
+ FakeWeb.register_uri(:get, "http://example.com/", :response => fake_response,
+ :server => "FakeWeb/1.2.3 (Ruby)")
+ response = Net::HTTP.start("example.com") { |query| query.get("/") }
+ assert_equal "200", response.code
+ assert_equal "OK", response.message
+ assert_equal "Apache/1.3.27 (Unix)", response["Server"]
+ end
+
+ def test_headers_are_rotated_when_registering_with_response_rotation
+ FakeWeb.register_uri(:get, "http://example.com",
+ [{:body => 'test1', :expires => "Thu, 14 Jun 2009 16:00:00 GMT",
+ :content_type => "text/plain"},
+ {:body => 'test2', :expires => "Thu, 14 Jun 2009 16:00:01 GMT"}])
+
+ first_response = second_response = nil
+ Net::HTTP.start("example.com") do |query|
+ first_response = query.get("/")
+ second_response = query.get("/")
+ end
+ assert_equal 'test1', first_response.body
+ assert_equal "Thu, 14 Jun 2009 16:00:00 GMT", first_response['Expires']
+ assert_equal "text/plain", first_response['Content-Type']
+ assert_equal 'test2', second_response.body
+ assert_equal "Thu, 14 Jun 2009 16:00:01 GMT", second_response['Expires']
+ assert_nil second_response['Content-Type']
+ end
+
+ def test_registering_with_status_option_and_response_headers
+ FakeWeb.register_uri(:get, "http://example.com", :status => ["301", "Moved Permanently"],
+ :location => "http://www.example.com")
+
+ response = Net::HTTP.start("example.com") { |query| query.get("/") }
+ assert_equal "301", response.code
+ assert_equal "Moved Permanently", response.message
+ assert_equal "http://www.example.com", response["Location"]
+ end
+
+end
diff --git a/fakeweb-1.2.5/test/test_trailing_slashes.rb b/fakeweb-1.2.5/test/test_trailing_slashes.rb
new file mode 100644
index 0000000..517564a
--- /dev/null
+++ b/fakeweb-1.2.5/test/test_trailing_slashes.rb
@@ -0,0 +1,53 @@
+require File.join(File.dirname(__FILE__), "test_helper")
+
+class TestFakeWebTrailingSlashes < Test::Unit::TestCase
+
+ def test_registering_root_without_slash_and_ask_predicate_method_with_slash
+ FakeWeb.register_uri(:get, "http://www.example.com", :body => "root")
+ assert FakeWeb.registered_uri?(:get, "http://www.example.com/")
+ end
+
+ def test_registering_root_without_slash_and_request
+ FakeWeb.register_uri(:get, "http://www.example.com", :body => "root")
+ response = Net::HTTP.start("www.example.com") { |query| query.get('/') }
+ assert_equal "root", response.body
+ end
+
+ def test_registering_root_with_slash_and_ask_predicate_method_without_slash
+ FakeWeb.register_uri(:get, "http://www.example.com/", :body => "root")
+ assert FakeWeb.registered_uri?(:get, "http://www.example.com")
+ end
+
+ def test_registering_root_with_slash_and_request
+ FakeWeb.register_uri(:get, "http://www.example.com/", :body => "root")
+ response = Net::HTTP.start("www.example.com") { |query| query.get('/') }
+ assert_equal "root", response.body
+ end
+
+ def test_registering_path_without_slash_and_ask_predicate_method_with_slash
+ FakeWeb.register_uri(:get, "http://www.example.com/users", :body => "User list")
+ assert !FakeWeb.registered_uri?(:get, "http://www.example.com/users/")
+ end
+
+ def test_registering_path_without_slash_and_request_with_slash
+ FakeWeb.allow_net_connect = false
+ FakeWeb.register_uri(:get, "http://www.example.com/users", :body => "User list")
+ assert_raise FakeWeb::NetConnectNotAllowedError do
+ response = Net::HTTP.start("www.example.com") { |query| query.get('/users/') }
+ end
+ end
+
+ def test_registering_path_with_slash_and_ask_predicate_method_without_slash
+ FakeWeb.register_uri(:get, "http://www.example.com/users/", :body => "User list")
+ assert !FakeWeb.registered_uri?(:get, "http://www.example.com/users")
+ end
+
+ def test_registering_path_with_slash_and_request_without_slash
+ FakeWeb.allow_net_connect = false
+ FakeWeb.register_uri(:get, "http://www.example.com/users/", :body => "User list")
+ assert_raise FakeWeb::NetConnectNotAllowedError do
+ response = Net::HTTP.start("www.example.com") { |query| query.get('/users') }
+ end
+ end
+
+end
diff --git a/fakeweb-1.2.5/test/test_utility.rb b/fakeweb-1.2.5/test/test_utility.rb
new file mode 100644
index 0000000..81cad81
--- /dev/null
+++ b/fakeweb-1.2.5/test/test_utility.rb
@@ -0,0 +1,70 @@
+require File.join(File.dirname(__FILE__), "test_helper")
+
+class TestUtility < Test::Unit::TestCase
+
+ def test_decode_userinfo_from_header_handles_basic_auth
+ authorization_header = "Basic dXNlcm5hbWU6c2VjcmV0"
+ userinfo = FakeWeb::Utility.decode_userinfo_from_header(authorization_header)
+ assert_equal "username:secret", userinfo
+ end
+
+ def test_encode_unsafe_chars_in_userinfo_does_not_encode_userinfo_safe_punctuation
+ userinfo = "user;&=+$,:secret"
+ assert_equal userinfo, FakeWeb::Utility.encode_unsafe_chars_in_userinfo(userinfo)
+ end
+
+ def test_encode_unsafe_chars_in_userinfo_does_not_encode_rfc_3986_unreserved_characters
+ userinfo = "-_.!~*'()abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:secret"
+ assert_equal userinfo, FakeWeb::Utility.encode_unsafe_chars_in_userinfo(userinfo)
+ end
+
+ def test_encode_unsafe_chars_in_userinfo_does_encode_other_characters
+ userinfo, safe_userinfo = 'us#rn@me:sec//ret?"', 'us%23rn%40me:sec%2F%2Fret%3F%22'
+ assert_equal safe_userinfo, FakeWeb::Utility.encode_unsafe_chars_in_userinfo(userinfo)
+ end
+
+ def test_strip_default_port_from_uri_strips_80_from_http_with_path
+ uri = "http://example.com:80/foo/bar"
+ stripped_uri = FakeWeb::Utility.strip_default_port_from_uri(uri)
+ assert_equal "http://example.com/foo/bar", stripped_uri
+ end
+
+ def test_strip_default_port_from_uri_strips_80_from_http_without_path
+ uri = "http://example.com:80"
+ stripped_uri = FakeWeb::Utility.strip_default_port_from_uri(uri)
+ assert_equal "http://example.com", stripped_uri
+ end
+
+ def test_strip_default_port_from_uri_strips_443_from_https_without_path
+ uri = "https://example.com:443"
+ stripped_uri = FakeWeb::Utility.strip_default_port_from_uri(uri)
+ assert_equal "https://example.com", stripped_uri
+ end
+
+ def test_strip_default_port_from_uri_strips_443_from_https
+ uri = "https://example.com:443/foo/bar"
+ stripped_uri = FakeWeb::Utility.strip_default_port_from_uri(uri)
+ assert_equal "https://example.com/foo/bar", stripped_uri
+ end
+
+ def test_strip_default_port_from_uri_does_not_strip_8080_from_http
+ uri = "http://example.com:8080/foo/bar"
+ assert_equal uri, FakeWeb::Utility.strip_default_port_from_uri(uri)
+ end
+
+ def test_strip_default_port_from_uri_does_not_strip_443_from_http
+ uri = "http://example.com:443/foo/bar"
+ assert_equal uri, FakeWeb::Utility.strip_default_port_from_uri(uri)
+ end
+
+ def test_strip_default_port_from_uri_does_not_strip_80_from_query_string
+ uri = "http://example.com/?a=:80&b=c"
+ assert_equal uri, FakeWeb::Utility.strip_default_port_from_uri(uri)
+ end
+
+ def test_strip_default_port_from_uri_does_not_modify_strings_that_do_not_start_with_http_or_https
+ uri = "httpz://example.com:80/"
+ assert_equal uri, FakeWeb::Utility.strip_default_port_from_uri(uri)
+ end
+
+end
--
libgit2 0.21.2