pax_global_header00006660000000000000000000000064120514655610014517gustar00rootroot0000000000000052 comment=6970c2eb64f63a48ad43e20f1de08bede2476765 ruby-vegas-0.1.11/000077500000000000000000000000001205146556100136635ustar00rootroot00000000000000ruby-vegas-0.1.11/History.txt000066400000000000000000000045731205146556100160760ustar00rootroot00000000000000== 0.1.8 * Add --no-proxy option for dealing with https and services behind proxies ( plukevdh) * Update test suite for 1.9.2 == 0.1.7 * Exit with specific exit status (for monitoring/good unix citizen). * Kill only after all options have been parsed. == 0.1.6 * Fixed: FileUtils no longer loaded by default == 0.1.5 2010-03-09 * Fixed: Gracefully catch error when thin isnt available (nevans) == 0.1.4 2010-02-09 * Fixed: Logging on Ruby 1.9 (greatseth) * Fixed: Dont chdir when daemonizing (messes up filesystem paths in apps) * Fixed: Test cases and dev installation (greatseth) * New: You can set the app_dir, pid file, log file and others via command line == 0.1.3 2010-01-08 * Fixed: Runner escapes :app_name to make it a valid string for using in paths (thanks greatseth!) * Fixed: Runner respects a server setting on Sinatra apps to use that specific Rack handler. (thanks greatseth!) * New: Tested against Rack 1.1 == 0.1.2 2009-12-28 * New * method: #load_config_file(path) reads a file and then eval's its contents within the scope of the app. * options: :before_run can take a Proc which is called after the options are parsed and before the app is run == 0.1.1 2009-11-18 * Repackaged with Jeweler, fixed dependency issues and removed other dev artifacts == 0.1.0 2009-08-30 * New: * options[:start] = false will keep the app from actually starting (useful for defining your own start/stop commands) * options[:launch_path] Takes a string or an object that responds to call (proc/lambda) that gets the runner as its only argument. This allows you to easily manipulate options or args to launch the app to a specific path. See latest gembox for example. * Changed: * Sinatra is no longer a dependency! Vegas can now run pure Rack apps. * All methods for starting an app are grouped into Runner#start * launch! and start both take an optional path string to launch the app to. == 0.0.4 2009-08-09 * new -L (--skip-launch) option doesn't launch the web browser (thanks bmabey!) * rubygems is required only on LoadError == 0.0.3 2009-07-06 * Vegas::Runner is now Windows compatible (require win32-process gem) * Includes daemon-ization * PID tracking * Vegas::WINDOWS is a top level boolean * Vegas is no longer dependent on Launchy * launching browser is done simply with open/start depending on platform == 0.0.1 2009-04-13 * 1 major enhancement: * Initial release ruby-vegas-0.1.11/LICENSE000066400000000000000000000021041205146556100146650ustar00rootroot00000000000000(The MIT License) Copyright (c) 2009 Aaron Quint, Quirkey NYC, LLC. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.ruby-vegas-0.1.11/README.rdoc000066400000000000000000000024001205146556100154650ustar00rootroot00000000000000= vegas http://code.quirkey.com/vegas == DESCRIPTION: Vegas aims to solve the simple problem of creating executable versions of Sinatra/Rack apps. == FEATURES/PROBLEMS: Currently, Vegas just includes a single class Vegas::Runner which wraps your Sinatra app to give it command line options, daemon-ization, PID/URL tracking, and browser launching. Lets say you have a gem with a sinatra application. With Vegas you can create a bin that looks like #!/usr/bin/env ruby # ./bin/myapp require File.expand_path(File.dirname(__FILE__) + "/../lib/myapp") require 'vegas' Vegas::Runner.new(Sinatra::Application, 'myapp') See the website: http://code.quirkey.com/vegas for full usage/options. === WINDOWS: Using vegas (and gems that depend on it) on Windows works but isn't 100% the same. Daemon-ization and browser launching work, but you will see duplicate messages. Some options might also be lost in the process. I suggest running Vegas apps in windows with the -F (foreground) flag. If you see a warning like: `expand_path': couldn't find HOME environment -- expanding `~/.vegas' (ArgumentError) You have to set your HOME path: c:\> set HOME=%HOMEPATH% == INSTALL: sudo gem install vegas == LICENSE: MIT LICENSE, see LICENSE for detailsruby-vegas-0.1.11/Rakefile000066400000000000000000000027461205146556100153410ustar00rootroot00000000000000%w[rubygems rake rake/clean rake/testtask fileutils].each { |f| require f } require File.dirname(__FILE__) + '/lib/vegas' begin require 'jeweler' rescue LoadError puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler" end VEGAS_VERSION = if ENV["DEV"] "#{Vegas::VERSION}.#{Time.new.to_i}" else Vegas::VERSION end Jeweler::Tasks.new do |s| s.name = %q{vegas} s.version = VEGAS_VERSION s.authors = ["Aaron Quint"] s.date = %q{2009-08-30} s.summary = "Vegas aims to solve the simple problem of creating executable versions of Sinatra/Rack apps." s.description = %{Vegas aims to solve the simple problem of creating executable versions of Sinatra/Rack apps. It includes a class Vegas::Runner that wraps Rack/Sinatra applications and provides a simple command line interface and launching mechanism.} s.email = ["aaron@quirkey.com"] s.homepage = %q{http://code.quirkey.com/vegas} s.rubyforge_project = %q{quirkey} s.add_runtime_dependency(%q, [">= 1.0.0"]) s.add_development_dependency(%q, ["~> 0.9.8"]) s.add_development_dependency(%q, ["~> 1.1.0"]) s.add_development_dependency(%q, ["~> 0.9.4"]) end Jeweler::GemcutterTasks.new Rake::TestTask.new do |t| t.libs << "test" t.test_files = FileList['test/test*.rb'] t.verbose = true end task :package => :build task :default => :test task "install:dev" => :build do system "gem install pkg/vegas-#{VEGAS_VERSION}.gem" end ruby-vegas-0.1.11/lib/000077500000000000000000000000001205146556100144315ustar00rootroot00000000000000ruby-vegas-0.1.11/lib/vegas.rb000066400000000000000000000004651205146556100160700ustar00rootroot00000000000000begin require 'rack' require 'rbconfig' rescue LoadError require 'rubygems' require 'rack' end module Vegas VERSION = "0.1.11" WINDOWS = !!(RUBY_PLATFORM =~ /(mingw|bccwin|wince|mswin32)/i) JRUBY = !!(RbConfig::CONFIG["RUBY_INSTALL_NAME"] =~ /^jruby/i) autoload :Runner, 'vegas/runner' end ruby-vegas-0.1.11/lib/vegas/000077500000000000000000000000001205146556100155365ustar00rootroot00000000000000ruby-vegas-0.1.11/lib/vegas/runner.rb000066400000000000000000000262041205146556100174000ustar00rootroot00000000000000require 'open-uri' require 'logger' require 'optparse' require 'fileutils' if Vegas::WINDOWS begin require 'win32/process' rescue puts "Sorry, in order to use Vegas on Windows you need the win32-process gem:", "gem install win32-process" end end module Vegas class Runner attr_reader :app, :app_name, :filesystem_friendly_app_name, :quoted_app_name, :rack_handler, :port, :host, :options, :args ROOT_DIR = ENV['HOME'] ? File.expand_path(File.join('~', '.vegas')) : nil PORT = 5678 HOST = WINDOWS ? 'localhost' : '0.0.0.0' def initialize(app, app_name, set_options = {}, runtime_args = ARGV, &block) @options = set_options || {} self.class.logger.level = options[:debug] ? Logger::DEBUG : Logger::INFO @app = app @app_name = app_name @filesystem_friendly_app_name = @app_name.gsub(/\W+/, "_") @quoted_app_name = "'#{app_name}'" @runtime_args = runtime_args @rack_handler = setup_rack_handler # load options from opt parser @args = define_options do |opts| if block_given? opts.separator '' opts.separator "#{quoted_app_name} options:" yield(self, opts, app) end end if @should_kill kill! exit!(0) end # Handle :before_run hook if (before_run = options.delete(:before_run)).respond_to?(:call) before_run.call(self) end # Set app options @host = options[:host] || HOST if app.respond_to?(:set) app.set(options) app.set(:vegas, self) end # Make sure app dir is setup FileUtils.mkdir_p(app_dir) return if options[:start] == false # evaluate the launch_path path = if options[:launch_path].respond_to?(:call) options[:launch_path].call(self) else options[:launch_path] end start(path) end def app_dir if !options[:app_dir] && !ROOT_DIR raise ArgumentError.new("nor --app-dir neither EVN['HOME'] defined") end options[:app_dir] || File.join(ROOT_DIR, filesystem_friendly_app_name) end def pid_file options[:pid_file] || File.join(app_dir, "#{filesystem_friendly_app_name}.pid") end def url_file options[:url_file] || File.join(app_dir, "#{filesystem_friendly_app_name}.url") end def log_file options[:log_file] || File.join(app_dir, "#{filesystem_friendly_app_name}.log") end def url "http://#{host}:#{port}" end def start(path = nil) logger.info "Running with Windows Settings" if WINDOWS logger.info "Running with JRuby" if JRUBY logger.info "Starting #{quoted_app_name}..." begin check_for_running(path) find_port write_url launch!(url, path) daemonize! unless options[:foreground] run! rescue RuntimeError => e logger.warn "There was an error starting #{quoted_app_name}: #{e}" exit end end def find_port if @port = options[:port] announce_port_attempted unless port_open? logger.warn "Port #{port} is already in use. Please try another. " + "You can also omit the port flag, and we'll find one for you." end else @port = PORT announce_port_attempted until port_open? @port += 1 announce_port_attempted end end end def announce_port_attempted logger.info "trying port #{port}..." end def port_open?(check_url = nil) begin check_url ||= url options[:no_proxy] ? open(check_url, :proxy => nil) : open(check_url) false rescue Errno::ECONNREFUSED, Errno::EPERM, Errno::ETIMEDOUT true end end def write_url File.open(url_file, 'w') {|f| f << url } end def check_for_running(path = nil) if File.exists?(pid_file) && File.exists?(url_file) running_url = File.read(url_file) if !port_open?(running_url) logger.warn "#{quoted_app_name} is already running at #{running_url}" launch!(running_url, path) exit!(1) end end end def run! logger.info "Running with Rack handler: #{@rack_handler.inspect}" rack_handler.run app, :Host => host, :Port => port do |server| kill_commands.each do |command| trap(command) do ## Use thins' hard #stop! if available, otherwise just #stop server.respond_to?(:stop!) ? server.stop! : server.stop logger.info "#{quoted_app_name} received INT ... stopping" delete_pid! end end end end # Adapted from Rackup def daemonize! if JRUBY # It's not a true daemon but when executed with & works like one thread = Thread.new {daemon_execute} thread.join elsif RUBY_VERSION < "1.9" logger.debug "Parent Process: #{Process.pid}" exit!(0) if fork logger.debug "Child Process: #{Process.pid}" daemon_execute else Process.daemon(true, true) daemon_execute end end def daemon_execute File.umask 0000 FileUtils.touch log_file STDIN.reopen log_file STDOUT.reopen log_file, "a" STDERR.reopen log_file, "a" logger.debug "Child Process: #{Process.pid}" File.open(pid_file, 'w') {|f| f.write("#{Process.pid}") } at_exit { delete_pid! } end def launch!(specific_url = nil, path = nil) return if options[:skip_launch] cmd = WINDOWS ? "start" : "open" system "#{cmd} #{specific_url || url}#{path}" end def kill! pid = File.read(pid_file) logger.warn "Sending #{kill_command} to #{pid.to_i}" Process.kill(kill_command, pid.to_i) rescue => e logger.warn "pid not found at #{pid_file} : #{e}" end def status if File.exists?(pid_file) logger.info "#{quoted_app_name} running" logger.info "PID #{File.read(pid_file)}" logger.info "URL #{File.read(url_file)}" if File.exists?(url_file) else logger.info "#{quoted_app_name} not running!" end end # Loads a config file at config_path and evals it in the context of the @app. def load_config_file(config_path) abort "Can not find config file at #{config_path}" if !File.readable?(config_path) config = File.read(config_path) # trim off anything after __END__ config.sub!(/^__END__\n.*/, '') @app.module_eval(config) end def self.logger=(logger) @logger = logger end def self.logger @logger ||= LOGGER if defined?(LOGGER) if !@logger @logger = Logger.new(STDOUT) @logger.formatter = Proc.new {|s, t, n, msg| "[#{t}] #{msg}\n"} @logger end @logger end def logger self.class.logger end private def setup_rack_handler # First try to set Rack handler via a special hook we honor @rack_handler = if @app.respond_to?(:detect_rack_handler) @app.detect_rack_handler # If they aren't using our hook, try to use their @app.server settings elsif @app.respond_to?(:server) and @app.server # If :server isn't set, it returns an array of possibilities, # sorted from most to least preferable. if @app.server.is_a?(Array) handler = nil @app.server.each do |server| begin handler = Rack::Handler.get(server) break rescue LoadError, NameError => e next end end handler # :server might be set explicitly to a single option like "mongrel" else Rack::Handler.get(@app.server) end # If all else fails, we'll use Thin else JRUBY ? Rack::Handler::WEBrick : Rack::Handler::Thin end end def define_options OptionParser.new("", 24, ' ') do |opts| # TODO instead of app_name, we should determine the name of the script # used to invoke Vegas and use that here opts.banner = "Usage: #{$0 || app_name} [options]" opts.separator "" opts.separator "Vegas options:" opts.on('-K', "--kill", "kill the running process and exit") {|k| @should_kill = true } opts.on('-S', "--status", "display the current running PID and URL then quit") {|s| status exit!(0) } opts.on("-s", "--server SERVER", "serve using SERVER (thin/mongrel/webrick)") { |s| @rack_handler = Rack::Handler.get(s) } opts.on("-o", "--host HOST", "listen on HOST (default: #{HOST})") { |host| @options[:host] = host } opts.on("-p", "--port PORT", "use PORT (default: #{PORT})") { |port| @options[:port] = port } opts.on("-x", "--no-proxy", "ignore env proxy settings (e.g. http_proxy)") { |p| @options[:no_proxy] = true } opts.on("-e", "--env ENVIRONMENT", "use ENVIRONMENT for defaults (default: development)") { |e| @options[:environment] = e } opts.on("-F", "--foreground", "don't daemonize, run in the foreground") { |f| @options[:foreground] = true } opts.on("-L", "--no-launch", "don't launch the browser") { |f| @options[:skip_launch] = true } opts.on('-d', "--debug", "raise the log level to :debug (default: :info)") {|s| @options[:debug] = true } opts.on("--app-dir APP_DIR", "set the app dir where files are stored (default: ~/.vegas/#{filesystem_friendly_app_name})/)") {|app_dir| @options[:app_dir] = app_dir } opts.on("-P", "--pid-file PID_FILE", "set the path to the pid file (default: app_dir/#{filesystem_friendly_app_name}.pid)") {|pid_file| @options[:pid_file] = pid_file } opts.on("--log-file LOG_FILE", "set the path to the log file (default: app_dir/#{filesystem_friendly_app_name}.log)") {|log_file| @options[:log_file] = log_file } opts.on("--url-file URL_FILE", "set the path to the URL file (default: app_dir/#{filesystem_friendly_app_name}.url)") {|url_file| @options[:url_file] = url_file } yield opts if block_given? opts.separator "" opts.separator "Common options:" opts.on_tail("-h", "--help", "Show this message") do puts opts exit end opts.on_tail("--version", "Show version") do if app.respond_to?(:version) puts "#{quoted_app_name} #{app.version}" end puts "rack #{Rack::VERSION.join('.')}" puts "sinatra #{Sinatra::VERSION}" if defined?(Sinatra) puts "vegas #{Vegas::VERSION}" exit end end.parse! @runtime_args rescue OptionParser::MissingArgument => e logger.warn "#{e}, run -h for options" exit end def kill_commands WINDOWS ? [1] : [:INT, :TERM] end def kill_command kill_commands[0] end def delete_pid! File.delete(pid_file) if File.exist?(pid_file) end end end ruby-vegas-0.1.11/metadata.yml000066400000000000000000000051421205146556100161700ustar00rootroot00000000000000--- !ruby/object:Gem::Specification name: vegas version: !ruby/object:Gem::Version version: 0.1.11 prerelease: platform: ruby authors: - Aaron Quint autorequire: bindir: bin cert_chain: [] date: 2009-08-30 00:00:00.000000000Z dependencies: - !ruby/object:Gem::Dependency name: rack requirement: &70263270797180 !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: 1.0.0 type: :runtime prerelease: false version_requirements: *70263270797180 - !ruby/object:Gem::Dependency name: mocha requirement: &70263270795200 !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: 0.9.8 type: :development prerelease: false version_requirements: *70263270795200 - !ruby/object:Gem::Dependency name: bacon requirement: &70263270793840 !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: 1.1.0 type: :development prerelease: false version_requirements: *70263270793840 - !ruby/object:Gem::Dependency name: sinatra requirement: &70263270792960 !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: 0.9.4 type: :development prerelease: false version_requirements: *70263270792960 description: Vegas aims to solve the simple problem of creating executable versions of Sinatra/Rack apps. It includes a class Vegas::Runner that wraps Rack/Sinatra applications and provides a simple command line interface and launching mechanism. email: - aaron@quirkey.com executables: [] extensions: [] extra_rdoc_files: - LICENSE - README.rdoc files: - History.txt - LICENSE - README.rdoc - Rakefile - lib/vegas.rb - lib/vegas/runner.rb - test/apps.rb - test/test_app/bin/test_app - test/test_app/bin/test_rack_app - test/test_app/test_app.rb - test/test_helper.rb - test/test_vegas_runner.rb - vegas.gemspec homepage: http://code.quirkey.com/vegas licenses: [] post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: quirkey rubygems_version: 1.8.10 signing_key: specification_version: 3 summary: Vegas aims to solve the simple problem of creating executable versions of Sinatra/Rack apps. test_files: [] ruby-vegas-0.1.11/test/000077500000000000000000000000001205146556100146425ustar00rootroot00000000000000ruby-vegas-0.1.11/test/apps.rb000066400000000000000000000005521205146556100161340ustar00rootroot00000000000000class TestApp1 < Sinatra::Base get '/' do 'TestApp1 Index' end get '/route' do 'TestApp1 route' end end class TestApp2 < Sinatra::Base get '/' do 'TestApp2 Index' end get '/route' do 'TestApp2 route' end end RackApp1 = Proc.new {|env| [200, {'Content-Type' => 'text/plain'}, ["This is an app. #{env.inspect}"]] }ruby-vegas-0.1.11/test/test_app/000077500000000000000000000000001205146556100164615ustar00rootroot00000000000000ruby-vegas-0.1.11/test/test_app/bin/000077500000000000000000000000001205146556100172315ustar00rootroot00000000000000ruby-vegas-0.1.11/test/test_app/bin/test_app000077500000000000000000000005561205146556100210040ustar00rootroot00000000000000#!/usr/bin/env ruby # # Created on 2009-2-27. # Copyright (c) 2009. All rights reserved. require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_app.rb')) require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'lib','vegas.rb')) vegas = Vegas::Runner.new(TestApp, 'test_app', :launch_path => lambda {|r| "/#{r.args.first}" })ruby-vegas-0.1.11/test/test_app/bin/test_rack_app000077500000000000000000000005241205146556100217770ustar00rootroot00000000000000#!/usr/bin/env ruby # # Created on 2009-2-27. # Copyright (c) 2009. All rights reserved. require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'lib','vegas.rb')) app = Proc.new {|env| [200, {'Content-Type' => 'text/plain'}, ["This is an app. #{env.inspect}"]] } vegas = Vegas::Runner.new(app, 'test_rack_app')ruby-vegas-0.1.11/test/test_app/test_app.rb000066400000000000000000000002201205146556100206170ustar00rootroot00000000000000require 'rubygems' require 'sinatra' class TestApp < Sinatra::Base get '/' do 'This is a TEST: params: ' + params.inspect end endruby-vegas-0.1.11/test/test_helper.rb000066400000000000000000000021461205146556100175100ustar00rootroot00000000000000dependencies = %w{ bacon mocha/standalone mocha/object sinatra } begin dependencies.each {|f| require f } rescue LoadError require 'rubygems' dependencies.each {|f| require f } end require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'vegas.rb') require File.join(File.expand_path(File.dirname(__FILE__)), 'apps.rb') module TestHelper def vegas(*args, &block) Vegas::Runner.any_instance.stubs(:daemonize!).once Vegas::JRUBY ? Rack::Handler::WEBrick.stubs(:run).once : Rack::Handler::Thin.stubs(:run).once @vegas = Vegas::Runner.new(*args, &block) end def body last_response.body.to_s end def instance_of(klass) lambda {|obj| obj.is_a?(klass) } end def exist_as_file lambda {|obj| File.exist?(obj) } end def have_matching_file_content(content_regex) lambda {|obj| File.exist?(obj) && File.read(obj).match(content_regex) } end def html_body body =~ /^\#{body}" end end module Bacon summary_on_exit # extend TestUnitOutput class Context; include TestHelper; end end ruby-vegas-0.1.11/test/test_vegas_runner.rb000066400000000000000000000125221205146556100207260ustar00rootroot00000000000000require 'test_helper' Vegas::Runner.class_eval do remove_const :ROOT_DIR Vegas::Runner::ROOT_DIR = File.join(File.dirname(__FILE__), 'tmp', '.vegas') end describe 'Vegas::Runner' do before do FileUtils.rm_rf(File.join(File.dirname(__FILE__), 'tmp')) @log = StringIO.new Vegas::Runner.logger = Logger.new(@log) end describe 'creating an instance' do describe 'basic usage' do before do Vegas::Runner.any_instance.expects(:system).once vegas(TestApp1, 'vegas_test_app_1', {:sessions => true}, ["route","--debug"]) end it "sets app" do @vegas.app.should == TestApp1 end it "sets app name" do @vegas.app_name.should == 'vegas_test_app_1' end it "sets quoted app name" do @vegas.quoted_app_name.should == "'vegas_test_app_1'" end it "sets filesystem friendly app name" do @vegas.filesystem_friendly_app_name.should == 'vegas_test_app_1' end it "stores options" do @vegas.options[:sessions].should.be.true end it "puts unparsed args into args" do @vegas.args.should == ["route"] end it "parses options into @options" do @vegas.options[:debug].should.be.true end it "writes the app dir" do @vegas.app_dir.should exist_as_file end it "writes a url with the port" do @vegas.url_file.should have_matching_file_content(/0.0.0.0\:#{@vegas.port}/) end it "knows where to find the pid file" do @vegas.pid_file.should.equal \ File.join(@vegas.app_dir, @vegas.filesystem_friendly_app_name + ".pid") # @vegas.pid_file.should exist_as_file end end describe 'basic usage with a funky app name' do before do Vegas::Runner.any_instance.expects(:system).once vegas(TestApp1, 'Funky YEAH!1!', {:sessions => true}, ["route","--debug"]) end it "sets app" do @vegas.app.should == TestApp1 end it "sets app name" do @vegas.app_name.should == 'Funky YEAH!1!' end it "sets quoted app name" do @vegas.quoted_app_name.should == "'Funky YEAH!1!'" end it "sets filesystem friendly app name" do @vegas.filesystem_friendly_app_name.should == 'Funky_YEAH_1_' end it "stores options" do @vegas.options[:sessions].should.be.true end it "puts unparsed args into args" do @vegas.args.should == ["route"] end it "parses options into @options" do @vegas.options[:debug].should.be.true end it "writes the app dir" do @vegas.app_dir.should exist_as_file end it "writes a url with the port" do @vegas.url_file.should have_matching_file_content(/0.0.0.0\:#{@vegas.port}/) end it "knows where to find the pid file" do @vegas.pid_file.should.equal \ File.join(@vegas.app_dir, @vegas.filesystem_friendly_app_name + ".pid") # @vegas.pid_file.should exist_as_file end end describe 'with a sinatra app using an explicit server setting' do before do TestApp1.set :server, "webrick" Vegas::Runner.any_instance.expects(:system).once Rack::Handler::WEBrick.stubs(:run) vegas(TestApp1, 'vegas_test_app_1', {:skip_launch => true, :sessions => true}, ["route","--debug"]) end it 'sets the rack handler automaticaly' do @vegas.rack_handler.should == Rack::Handler::WEBrick end end describe 'with a simple rack app' do before do vegas(RackApp1, 'rack_app_1', {:skip_launch => true, :sessions => true}) end it "sets default rack handler to thin when in ruby and WEBrick when in jruby" do if Vegas::JRUBY @vegas.rack_handler.should == Rack::Handler::WEBrick else @vegas.rack_handler.should == Rack::Handler::Thin end end end describe 'with a launch path specified as a proc' do it 'evaluates the proc in the context of the runner' do Vegas::Runner.any_instance.expects(:system).once.with {|s| s =~ /\?search\=blah$/ } vegas(TestApp2, 'vegas_test_app_2', {:launch_path => Proc.new {|r| "?search=#{r.args.first}" }}, ["--debug", "blah"]) @vegas.options[:launch_path].should.be instance_of(Proc) end end describe 'with a launch path specified as string' do it 'launches to the specific path' do Vegas::Runner.any_instance.expects(:system).once.with {|s| s =~ /\?search\=blah$/ } vegas(TestApp2, 'vegas_test_app_2', {:launch_path => "?search=blah"}, ["--debug", "blah"]) @vegas.options[:launch_path].should == "?search=blah" end end describe 'without environment' do Vegas::Runner::ROOT_DIR = nil before do @app_dir = './test/tmp' end it 'should be ok with --app-dir' do vegas(RackApp1, 'rack_app_1', {:skip_launch => true, :app_dir => @app_dir}) @vegas.app_dir.should == @app_dir end it 'should raise an exception without --app-dir' do success = false begin vegas(RackApp1, 'rack_app_1', {:skip_launch => true}) rescue ArgumentError success = true end success.should == true end end end end ruby-vegas-0.1.11/vegas.gemspec000066400000000000000000000041161205146556100163370ustar00rootroot00000000000000# Generated by jeweler # DO NOT EDIT THIS FILE DIRECTLY # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec' # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = "vegas" s.version = "0.1.11" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Aaron Quint"] s.date = "2009-08-30" s.description = "Vegas aims to solve the simple problem of creating executable versions of Sinatra/Rack apps. It includes a class Vegas::Runner that wraps Rack/Sinatra applications and provides a simple command line interface and launching mechanism." s.email = ["aaron@quirkey.com"] s.extra_rdoc_files = [ "LICENSE", "README.rdoc" ] s.files = [ "History.txt", "LICENSE", "README.rdoc", "Rakefile", "lib/vegas.rb", "lib/vegas/runner.rb", "test/apps.rb", "test/test_app/bin/test_app", "test/test_app/bin/test_rack_app", "test/test_app/test_app.rb", "test/test_helper.rb", "test/test_vegas_runner.rb", "vegas.gemspec" ] s.homepage = "http://code.quirkey.com/vegas" s.require_paths = ["lib"] s.rubyforge_project = "quirkey" s.rubygems_version = "1.8.10" s.summary = "Vegas aims to solve the simple problem of creating executable versions of Sinatra/Rack apps." if s.respond_to? :specification_version then s.specification_version = 3 if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then s.add_runtime_dependency(%q, [">= 1.0.0"]) s.add_development_dependency(%q, ["~> 0.9.8"]) s.add_development_dependency(%q, ["~> 1.1.0"]) s.add_development_dependency(%q, ["~> 0.9.4"]) else s.add_dependency(%q, [">= 1.0.0"]) s.add_dependency(%q, ["~> 0.9.8"]) s.add_dependency(%q, ["~> 1.1.0"]) s.add_dependency(%q, ["~> 0.9.4"]) end else s.add_dependency(%q, [">= 1.0.0"]) s.add_dependency(%q, ["~> 0.9.8"]) s.add_dependency(%q, ["~> 1.1.0"]) s.add_dependency(%q, ["~> 0.9.4"]) end end