0.0
No commit activity in last 3 years
No release in over 3 years
A version of Wycat's Artifice for use with Excon.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

artifice-excon

Artifice allows you to replace remote HTTP/HTTPS calls with a stub that routes all requests to a Rack application. This version integrates with Excon instead of the Net:HTTP subsystem that Wycat's original gem provides.

Remote service stubs can be constructed using Sinatra, raw Rack, or even Rails, allowing you to leverage familiar and convenient tools.

Usage

Bundle artifice-excon in your Gemfile:

gem 'artifice-excon'

Use Bundle.require or require it manually:

require 'artifice/excon'

Next, activate artifice-excon by passing in a Rack endpoint:

Artifice::Excon.activate_with(rack_endpoint)

# an extremely basic example
app = proc do |env|
  [200, {}, "Hello, world!"]
end
Artifice::Excon.activate_with(app)

And finally, deactivate it again:

Artifice::Excon.deactivate

Alternatively, pass a block to activate_with to keep stub requests for the duration of the block only:

Artifice.activate_with(rack_endpoint) do
  Excon.get("https://google.com")
end

Host-based Activation

A feature present in artifice-excon that isn't in the original is host-based endpoint activation, so that a particular rack app can be activated for a particular host. This is useful in case you have an app that potentially needs to speak to multiple services with different APIs.

Artifice::Excon.activate_for('google.com', google_endpoint)

# a catch-all is still allowed! but a registered host-specific endpoint will
# always take preference
Artifice::Excon.activate_with(rack_endpoint)

Once again, deactivate for a particular host or everything:

Artifice.deactivate_for('google.com')

# deactivates all registered endpoints including host-specific and global
Artifice.deactivate

Development

Run tests using:

rake test