Skip to content

Instantly share code, notes, and snippets.

@joelhelbling
Created October 17, 2012 17:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelhelbling/3906813 to your computer and use it in GitHub Desktop.
Save joelhelbling/3906813 to your computer and use it in GitHub Desktop.
mock server in a separate thread
require 'goliath'
require 'open-uri'
class Hello < Goliath::API
@@say = "Hello World"
# silly mechanism for changing
# server's response
def self.say(something)
@@say = something
end
def response(env)
[200, {}, @@say]
end
end
g = Thread.new { Goliath::Application.run! }
open('http://localhost:9000').read #=> 'Hello World'
Hello.say "Hello Mars"
open('http://localhost:9000').read #=> 'Hello Mars'
@joelhelbling
Copy link
Author

I guess this might also need a mechanism for stopping the server.

@searls
Copy link

searls commented Oct 17, 2012

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment