Module: Fredo
- Defined in:
- lib/fredo.rb,
lib/fredo/handler.rb,
lib/fredo/registry.rb,
lib/fredo/response.rb,
lib/fredo/stub_socket.rb
Defined Under Namespace
Classes: Handler, Mixup, NetConnectNotAllowedError, NotFound, Registry, Response, StubSocket
Constant Summary collapse
- VERSION =
Returns the version string for the Fredo you have loaded.
File.exist?('VERSION') ? File.read('VERSION') : ""
Class Method Summary collapse
-
.allow_net_connect=(allowed) ⇒ Object
Enables or disables real HTTP connections for requests that don’t match registered URIs.
-
.allow_net_connect? ⇒ Boolean
Returns
true
if requests to URIs not registered with Fredo are passed through to Net::HTTP for normal processing (the default). -
.books ⇒ Object
Returns an array that stores every request intercepted by fredo.
- .call(env) ⇒ Object
-
.clean_registry ⇒ Object
Resets Fredo’s Registry.
- .delete(path, opts = {}, &bk) ⇒ Object
- .forget ⇒ Object
-
.get(path, opts = {}, &bk) ⇒ Object
Registers get url that will make Fredo an OK response or the response generated in the block passed to get.
- .head(path, opts = {}, &bk) ⇒ Object
- .post(path, opts = {}, &bk) ⇒ Object
- .put(path, opts = {}, &bk) ⇒ Object
Class Method Details
.allow_net_connect=(allowed) ⇒ Object
Enables or disables real HTTP connections for requests that don’t match registered URIs.
If you set Fredo.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 Fredo.allow_net_connect = true
(the default), requests to URIs not stubbed with Fredo are passed through to Net::HTTP.
42 43 44 |
# File 'lib/fredo.rb', line 42 def self.allow_net_connect=(allowed) @allow_net_connect = allowed end |
.allow_net_connect? ⇒ Boolean
Returns true
if requests to URIs not registered with Fredo are passed through to Net::HTTP for normal processing (the default). Returns false
if an exception is raised for these requests.
49 50 51 |
# File 'lib/fredo.rb', line 49 def self.allow_net_connect? @allow_net_connect || true end |
.books ⇒ Object
Returns an array that stores every request intercepted by fredo
54 55 56 |
# File 'lib/fredo.rb', line 54 def self.books @books ||= [] end |
.call(env) ⇒ Object
74 75 76 |
# File 'lib/fredo.rb', line 74 def self.call(env) Handler.new.call(env) end |
.clean_registry ⇒ Object
Resets Fredo’s Registry. This will force all subsequent web requests to behave as real requests.
18 19 20 |
# File 'lib/fredo.rb', line 18 def self.clean_registry Registry.instance.clean_registry end |
.delete(path, opts = {}, &bk) ⇒ Object
27 |
# File 'lib/fredo.rb', line 27 def self.delete(path, opts={}, &bk); Registry.route 'DELETE', path, opts, &bk end |
.get(path, opts = {}, &bk) ⇒ Object
Registers get url that will make Fredo an OK response or the response generated in the block passed to get.
24 |
# File 'lib/fredo.rb', line 24 def self.get(path, opts={}, &bk); Registry.route 'GET', path, opts, &bk end |
.head(path, opts = {}, &bk) ⇒ Object
28 |
# File 'lib/fredo.rb', line 28 def self.head(path, opts={}, &bk); Registry.route 'HEAD', path, opts, &bk end |