File tree 4 files changed +68
-5
lines changed
4 files changed +68
-5
lines changed Original file line number Diff line number Diff line change 1
1
source 'http://rubygems.org'
2
2
3
- gem "json"
4
-
5
- gem "sinatra" , "= 1.0"
3
+ gem 'sinatra' , '~> 1.0'
4
+ gem 'shotgun' , :group => :reloadable
5
+ gem 'thin' , :group => :reloadable
6
+ gem 'json'
Original file line number Diff line number Diff line change 1
1
GEM
2
2
remote: http://rubygems.org/
3
3
specs:
4
+ daemons (1.1.0 )
5
+ eventmachine (0.12.10 )
4
6
json (1.4.6 )
5
7
rack (1.2.1 )
6
- sinatra ( 1.0 )
8
+ shotgun ( 0.8 )
7
9
rack (>= 1.0 )
10
+ sinatra (1.1.2 )
11
+ rack (~> 1.1 )
12
+ tilt (~> 1.2 )
13
+ thin (1.2.7 )
14
+ daemons (>= 1.0.9 )
15
+ eventmachine (>= 0.12.6 )
16
+ rack (>= 1.0.0 )
17
+ tilt (1.2.1 )
8
18
9
19
PLATFORMS
10
20
ruby
11
21
12
22
DEPENDENCIES
13
23
json
14
- sinatra (= 1.0 )
24
+ shotgun
25
+ sinatra (~> 1.0 )
26
+ thin
Original file line number Diff line number Diff line change
1
+ desc %(Starts the test server and opens it in a web browser)
2
+ multitask :default => [ 'test:server' , 'test:open' ]
3
+
4
+ PORT = 4567
5
+
6
+ namespace :test do
7
+ desc %(Starts the test server)
8
+ task :server do
9
+ system 'bundle exec ruby test/server.rb'
10
+ end
11
+
12
+ desc %(Starts the test server which reloads everything on each refresh)
13
+ task :reloadable do
14
+ exec "bundle exec shotgun test/config.ru -p #{ PORT } --server thin"
15
+ end
16
+
17
+ task :open do
18
+ url = "http://localhost:#{ PORT } "
19
+ puts "Opening test app at #{ url } ..."
20
+ sleep 3
21
+ system ( *browse_cmd ( url ) )
22
+ end
23
+ end
24
+
25
+ # Returns an array e.g.: ['open', 'http://example.com']
26
+ def browse_cmd ( url )
27
+ require 'rbconfig'
28
+ browser = ENV [ 'BROWSER' ] ||
29
+ ( RbConfig ::CONFIG [ 'host_os' ] . include? ( 'darwin' ) && 'open' ) ||
30
+ ( RbConfig ::CONFIG [ 'host_os' ] =~ /msdos|mswin|djgpp|mingw|windows/ && 'start' ) ||
31
+ %w[ xdg-open x-www-browser firefox opera mozilla netscape ] . find { |comm | which comm }
32
+
33
+ abort ( 'ERROR: no web browser detected' ) unless browser
34
+ Array ( browser ) << url
35
+ end
36
+
37
+ # which('ruby') #=> /usr/bin/ruby
38
+ def which cmd
39
+ exts = ENV [ 'PATHEXT' ] ? ENV [ 'PATHEXT' ] . split ( ';' ) : [ '' ]
40
+ ENV [ 'PATH' ] . split ( File ::PATH_SEPARATOR ) . each do |path |
41
+ exts . each { |ext |
42
+ exe = "#{ path } /#{ cmd } #{ ext } "
43
+ return exe if File . executable? exe
44
+ }
45
+ end
46
+ return nil
47
+ end
Original file line number Diff line number Diff line change
1
+ $LOAD_PATH. unshift File . expand_path ( '..' , __FILE__ )
2
+ require 'server'
3
+ run Sinatra ::Application
You can’t perform that action at this time.
0 commit comments