Created
October 17, 2012 17:16
-
-
Save joelhelbling/3906813 to your computer and use it in GitHub Desktop.
mock server in a separate thread
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍