Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 70 lines (43 sloc) 2.127 kB
73d00aa @eladmeidar Readme
authored
1 = Sinatra Fake Webservice
e44f709 @eladmeidar Initial commit to sinatra_fake_webservice.
authored
2
73d00aa @eladmeidar Readme
authored
3 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.
4
5 == Why shouldn't i use FakeWeb?
6
7 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.
8
9 == Installation
10
11 Command line:
1e85fc6 @eladmeidar run! removed
authored
12 sudo gem install sinatra_fake_webservice
73d00aa @eladmeidar Readme
authored
13
bfdb957 @eladmeidar Readme and again
authored
14 Or in bundler (0.9.x) add this line to your .gemfile:
73d00aa @eladmeidar Readme
authored
15
bfdb957 @eladmeidar Readme and again
authored
16 gem 'sinatra_fake_webservice', :group => :test
73d00aa @eladmeidar Readme
authored
17
18
19 == Usage
20
21 First you'll need to create a SinatraWebService instance that can accept +:host+ and +:port+ options:
22
0aa94eb @eladmeidar Readme and again
authored
23 @fakews = SinatraWebService.new :host => 'localhost', :port => 7000
73d00aa @eladmeidar Readme
authored
24
25 and then simply use the familiar sinatra DSL to create methods and responses.
26
67f22c8 @eladmeidar Readme AGAIN
authored
27 @fakews.get '/awesome' do
28 "YAY!!"
1e85fc6 @eladmeidar run! removed
authored
29 end
30
31 @fakews.post '/omglol' do
32 "YAY!! i posted #{params[:awesome]}"
33 end
73d00aa @eladmeidar Readme
authored
34
1e85fc6 @eladmeidar run! removed
authored
35 @fakews.delete '/awesome' do
36 "there, i kiiled #{params[:id]}"
37 end
38
39 @fakews.put '/awesome' do
40 "yay, i saved the worlds"
41 end
42
73d00aa @eladmeidar Readme
authored
43 tada!
44
1e85fc6 @eladmeidar run! removed
authored
45 == Tests
67f22c8 @eladmeidar Readme AGAIN
authored
46
1e85fc6 @eladmeidar run! removed
authored
47 I added a few methods to wrap HTTP requests:
48
49 * get_response(path)
50 * post_response(path, data, headers, dest)
51 * put_response(path, data, headers, dest)
52 * delete_response(path, data, headers, dest)
53
54 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).
67f22c8 @eladmeidar Readme AGAIN
authored
55
e44f709 @eladmeidar Initial commit to sinatra_fake_webservice.
authored
56
57 == Note on Patches/Pull Requests
58
59 * Fork the project.
60 * Make your feature addition or bug fix.
61 * Add tests for it. This is important so I don't break it in a
62 future version unintentionally.
63 * Commit, do not mess with rakefile, version, or history.
64 (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)
65 * Send me a pull request. Bonus points for topic branches.
66
67 == Copyright
68
69 Copyright (c) 2010 Elad Meidar. See LICENSE for details.
Something went wrong with that request. Please try again.