No commit activity in last 3 years
No release in over 3 years
FakeWeb allows you to fake a response from a specific url, this gem intends to give developers the option to allow several responses from the same url based on parameters (ex: WSDL)
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Sinatra Fake Webservice¶ ↑

SFW provides an easy and simple wrapper for a sinatra application you can use in your tests in order to test/simulate remote API and HTTP calls and responses.

Why shouldn’t i use FakeWeb?¶ ↑

FakeWeb is awesome, but it allows you only to register one response per url, although in some cases you might need more than one response per url depend on your usage for example: testing an XMLRPC service or a WSDL that both might have only one url and respond based on parameters.

Installation¶ ↑

Command line: sudo gem install sinatra_fake_webservice

Or in bundler (0.9.x) add this line to your .gemfile:

gem ‘sinatra_fake_webservice’, :group => :test

Usage¶ ↑

First you’ll need to create a SinatraWebService instance that can accept :host and :port options:

@fakews = SinatraWebService.new :host => ‘localhost’, :port => 7000

and then simply use the familiar sinatra DSL to create methods and responses.

@fakews.get ‘/awesome’ do “YAY!!” end

@fakews.post ‘/omglol’ do “YAY!! i posted #{params}” end

@fakews.delete ‘/awesome’ do “there, i kiiled #{params}” end @fakews.put ‘/awesome’ do “yay, i saved the worlds” end tada!

Tests¶ ↑

I added a few methods to wrap HTTP requests:

  • get_response(path)

  • post_response(path, data, headers, dest)

  • put_response(path, data, headers, dest)

  • delete_response(path, data, headers, dest)

The most important thing to remember, is that you’ll have to point your webservice api wrapper (twitter_auth or whatever) to use “localhost” and the fake sinatra app’s port, available via a simple getter (#port).

Note on Patches/Pull Requests¶ ↑

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2010 Elad Meidar. See LICENSE for details.