Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

rake tasks for testing

E.g. shotgun-powered reloadable server:

  $ rake test:reloadable

If you don't want to use this, install the bundle without it:

 $ bundle install --without reloadable
  • Loading branch information...
commit 1008c33b3775d6ceb20a1c5d19086eda972d66fa 1 parent fbbefa0
Mislav Marohnić mislav authored
Showing with 68 additions and 5 deletions.
  1. +4 −3 Gemfile
  2. +14 −2 Gemfile.lock
  3. +47 −0 Rakefile
  4. +3 −0  test/config.ru
7 Gemfile
View
@@ -1,5 +1,6 @@
source 'http://rubygems.org'
-gem "json"
-
-gem "sinatra", "= 1.0"
+gem 'sinatra', '~> 1.0'
+gem 'shotgun', :group => :reloadable
+gem 'thin', :group => :reloadable
+gem 'json'
16 Gemfile.lock
View
@@ -1,14 +1,26 @@
GEM
remote: http://rubygems.org/
specs:
+ daemons (1.1.0)
+ eventmachine (0.12.10)
json (1.4.6)
rack (1.2.1)
- sinatra (1.0)
+ shotgun (0.8)
rack (>= 1.0)
+ sinatra (1.1.2)
+ rack (~> 1.1)
+ tilt (~> 1.2)
+ thin (1.2.7)
+ daemons (>= 1.0.9)
+ eventmachine (>= 0.12.6)
+ rack (>= 1.0.0)
+ tilt (1.2.1)
PLATFORMS
ruby
DEPENDENCIES
json
- sinatra (= 1.0)
+ shotgun
+ sinatra (~> 1.0)
+ thin
47 Rakefile
View
@@ -0,0 +1,47 @@
+desc %(Starts the test server and opens it in a web browser)
+multitask :default => ['test:server', 'test:open']
+
+PORT = 4567
+
+namespace :test do
+ desc %(Starts the test server)
+ task :server do
+ system 'bundle exec ruby test/server.rb'
+ end
+
+ desc %(Starts the test server which reloads everything on each refresh)
+ task :reloadable do
+ exec "bundle exec shotgun test/config.ru -p #{PORT} --server thin"
+ end
+
+ task :open do
+ url = "http://localhost:#{PORT}"
+ puts "Opening test app at #{url} ..."
+ sleep 3
+ system( *browse_cmd(url) )
+ end
+end
+
+# Returns an array e.g.: ['open', 'http://example.com']
+def browse_cmd(url)
+ require 'rbconfig'
+ browser = ENV['BROWSER'] ||
+ (RbConfig::CONFIG['host_os'].include?('darwin') && 'open') ||
+ (RbConfig::CONFIG['host_os'] =~ /msdos|mswin|djgpp|mingw|windows/ && 'start') ||
+ %w[xdg-open x-www-browser firefox opera mozilla netscape].find { |comm| which comm }
+
+ abort('ERROR: no web browser detected') unless browser
+ Array(browser) << url
+end
+
+# which('ruby') #=> /usr/bin/ruby
+def which cmd
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
+ exts.each { |ext|
+ exe = "#{path}/#{cmd}#{ext}"
+ return exe if File.executable? exe
+ }
+ end
+ return nil
+end
3  test/config.ru
View
@@ -0,0 +1,3 @@
+$LOAD_PATH.unshift File.expand_path('..', __FILE__)
+require 'server'
+run Sinatra::Application
Please sign in to comment.
Something went wrong with that request. Please try again.