Created
February 13, 2012 22:44
-
-
Save EvilScott/1821185 to your computer and use it in GitHub Desktop.
Use Sinatra to open a browser window (and close Sinatra when the window closes)
This file contains 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
%w[sinatra watir-webdriver].each { |gem| require gem } | |
class MyApp < Sinatra::Base | |
get('/') { "hello world" } | |
end | |
class AppRunner | |
def initialize | |
@browser = nil | |
end | |
def browser_start! | |
@browser = Watir::Browser.start 'http://localhost:4567' | |
end | |
def start! | |
Thread.new { sleep(1) until MyApp.settings.running?; browser_start! } | |
Thread.new { check_browser while true } | |
MyApp.run! | |
end | |
def check_browser | |
sleep(1) | |
begin | |
@browser.status unless @browser.nil? | |
rescue Exception | |
puts "== Sinatra has been led off the stage by AppRunner..." | |
exit(0) | |
end | |
end | |
end | |
AppRunner.new.start! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment