Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Run a sinatra app in your test environment that will operate as a Fake web service
Ruby
tag: v0.2.0

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
metal
test
.document
.gitignore
LICENSE
README.rdoc
Rakefile
VERSION
sinatra.log

README.rdoc

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+

tada!

i simply used Net::HTTP to access the sinatra app, but i bet there are more ways to do it:

res = Net::HTTP.start(@fakews.host, @fakews.port) do |http| http.get('/awesome') end

assert_equal “YAY!!”, res.body

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

Copyright © 2010 Elad Meidar. See LICENSE for details.

Something went wrong with that request. Please try again.