Created
July 8, 2013 16:07
-
-
Save johnbintz/5950149 to your computer and use it in GitHub Desktop.
Totally untested way to run Rack and a LiveReload listener for rack-livereload testing
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
LIVERELOAD_PORT = 50000 | |
app = Rack::LiveReload.new( | |
lambda { |env| | |
[ | |
200, | |
{ 'Content-Type' => 'text/html' }, | |
[ <<-HTML ] | |
<html> | |
<head> | |
<title>A page to livereload</title> | |
</head> | |
<body> | |
Here I am | |
</body> | |
</html> | |
HTML | |
] | |
}, :port => LIVERELOAD_PORT | |
) | |
rack = Thread.new do | |
Rack::Handler::WEBrick.run(app, :Port => 3001) do |server| | |
Thread.current[:running] = true | |
while !Thread.current[:stop] | |
sleep 1 | |
end | |
server.stop | |
end | |
end | |
require 'socket' | |
livereload = Thread.new do | |
server = TCPServer.new 'localhost', LIVERELOAD_PORT | |
Thread.current[:connected] = false | |
server.accept | |
Thread.current[:connected] = true | |
while !Thread.current[:stop] | |
sleep 1 | |
end | |
end | |
while !rack[:running] | |
sleep 1 | |
end | |
# interact with the rack server via capybara or something else | |
# stop the rack thread | |
rack[:stop] = true | |
livereload[:connected].should be_true | |
# stop the lievreload thread | |
livereload[:stop] = true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment