Skip to content

Commit

Permalink
run! removed
Browse files Browse the repository at this point in the history
  • Loading branch information
Elad Meidar committed Mar 4, 2010
1 parent 38d8df8 commit 1e85fc6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
30 changes: 23 additions & 7 deletions README.rdoc
Expand Up @@ -9,7 +9,7 @@ FakeWeb is awesome, but it allows you only to register *one* response per url, a
== Installation

Command line:
sudo gem install sinatra_fake_webservice+
sudo gem install sinatra_fake_webservice

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

Expand All @@ -26,17 +26,33 @@ and then simply use the familiar sinatra DSL to create methods and responses.

@fakews.get '/awesome' do
"YAY!!"
end+
end

@fakews.post '/omglol' do
"YAY!! i posted #{params[:awesome]}"
end

@fakews.delete '/awesome' do
"there, i kiiled #{params[:id]}"
end

@fakews.put '/awesome' do
"yay, i saved the worlds"
end

tada!

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

res = Net::HTTP.start(@fakews.host, @fakews.port) do |http|
http.get('/awesome')
end
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).

assert_equal "YAY!!", res.body

== Note on Patches/Pull Requests

Expand Down
2 changes: 1 addition & 1 deletion lib/sinatra_webservice.rb
Expand Up @@ -30,7 +30,7 @@ def running?
end

def run!
if Thread.list.size > 1
if Thread.list.size > 2
Thread.list.first.kill
end

Expand Down
6 changes: 2 additions & 4 deletions sinatra_fake_webservice.gemspec
Expand Up @@ -5,11 +5,11 @@

Gem::Specification.new do |s|
s.name = %q{sinatra_fake_webservice}
s.version = "0.2.0"
s.version = "0.9.0"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Elad Meidar"]
s.date = %q{2010-02-18}
s.date = %q{2010-03-03}
s.description = %q{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)}
s.email = %q{elad@nautilus6.com}
s.extra_rdoc_files = [
Expand All @@ -23,9 +23,7 @@ Gem::Specification.new do |s|
"README.rdoc",
"Rakefile",
"VERSION",
"lib/sinatra_ext.rb",
"lib/sinatra_webservice.rb",
"lib/web_service.rb",
"metal/sinatra_stem.rb",
"sinatra.log",
"sinatra_fake_webservice.gemspec",
Expand Down
2 changes: 2 additions & 0 deletions test/test_sinatra_fake_webservice.rb
Expand Up @@ -23,6 +23,8 @@ class TestSinatraFakeWebservice < Test::Unit::TestCase
@sinatra_app.put '/gimmieitnow' do
"yay, i haz it."
end

#@sinatra_app.run!
end

should "have default host and port" do
Expand Down

0 comments on commit 1e85fc6

Please sign in to comment.