User:Meruvian/sandbox
Developer(s) | Blaine Cook, Chris Kampmeier |
---|---|
Initial release | May 23rd, 2006 |
Stable release | 1.3.0
/ August 22, 2010 |
Repository | github |
Written in | Ruby |
Website | rubygems |
FakeWeb is a Ruby tool that fakes HTTP web requests. It is used in software development to simulate interactions with external web servers, simplifying testing.[1]
FakeWeb provides an alternative to using live servers when testing network connections. Tests that connect to live servers risk those servers becoming unavailable or slow to respond, which can significantly slow down the testing process. Instead, FakeWeb can be used to intercept outgoing network traffic and provide a previously recorded response. This enables offline testing with timely results. A response from an HTTP request to a live server can be captured and saved, then provided to all future requests to the same target allowing tests to be replicated regardless of network connections.[2]
The current release can be found in the public repository and is installed using the gem command-line tool. While it is no longer actively being developed, it is compatible with all current versions of Ruby.[3]
History
[edit]FakeWeb 1.0.0 was first released on May 23rd, 2006. It was initially developed on GitHub by Blaine Cook, but Chris Kampmeier took over as the primary developer in October of 2008. Several authors collaborated during development, culminating in the most recent release of version 1.3.0 on August 22nd, 2010.[4]
Features
[edit]- FakeWeb is operating system independent
- Compatible with all versions of Ruby
- Only works with HTTP requests
- Allows quicker testing of HTTP code
FakeWeb is able to intercept HTTP requests from a Ruby program, allowing tests to be run without requiring live services. Unlike some other utilities, normal HTTP requests can be written into your code that target external servers. FakeWeb can be configured to catch these requests and send it's own response, removing the necessity for a network connection in program testing. Without FakeWeb or a similar tool, Ruby code must be stubbed out or mocked to avoid sending out requests to live servers during tests of software functionality.[5]
Installation
To install FakeWeb, ensure that Ruby is installed on your system of choice.
This gem can be installed using the command below.
gem install fakeweb
After installation, the utility must be listed as a required gem in the project.
require 'fakeweb'
A response can be designated for a specific HTTP address.
FakeWeb.register_uri(:get, "http: address", :body => "Your chosen response")
Or a response from a live service can be recorded for use in subsequent requests. This will be an exact copy of the response received from the live service initially.
page = 'curl -is http://reddit.com/'
FakeWeb.registeruri(:get, "http://reddit.com/", :response => page)
More complicated response behavior can also be implemented, check the API for detailed information on how to do this.
See also
[edit]- Ruby
- RubyGems
- Stubbing/Mocking
- WebMock - An updated alternative that provides all of FakeWeb's functionality and more
References
[edit]- ^ a b "FakeWeb 1.3.0 API Documentation". fakeweb.rubyforge.org. Retrieved 2017-02-21.
- ^ "Stop Net::HTTP dead in its tracks with fakeweb - Josh Nichols on the Internet". technicalpickles.com. Retrieved 2017-02-14.
- ^ "fakeweb | RubyGems.org | your community gem host". rubygems.org. Retrieved 2017-02-14.
- ^ "GitHub FakeWeb Page". GitHub. Retrieved 2017-02-13.
- ^ "Mocking and stubbing in Ruby on Rails". www.ibm.com. 2007-11-07. Retrieved 2017-02-21.