shotgun 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -5,38 +5,39 @@ task :default => [:test]
5
5
  task :spec => :test
6
6
 
7
7
  Rake::TestTask.new(:test) do |t|
8
- t.test_files = FileList['test/spec_*.rb']
8
+ t.test_files = FileList['test/*_test.rb']
9
9
  t.ruby_opts = ['-rubygems'] if defined? Gem
10
10
  end
11
11
 
12
- require 'rubygems'
13
- $spec = eval(File.read('shotgun.gemspec'))
14
-
15
- def package(ext='')
16
- "pkg/#{$spec.name}-#{$spec.version}" + ext
17
- end
18
-
19
- desc 'Build packages'
20
- task :package => %w[.gem .tar.gz].map { |e| package(e) }
21
-
22
- desc 'Build and install as local gem'
23
- task :install => package('.gem') do
24
- sh "gem install #{package('.gem')}"
25
- end
26
-
27
- directory 'pkg/'
28
- CLOBBER.include('pkg')
29
-
30
- file package('.gem') => %W[pkg/ #{$spec.name}.gemspec] + $spec.files do |f|
31
- sh "gem build #{$spec.name}.gemspec"
32
- mv File.basename(f.name), f.name
33
- end
34
-
35
- file package('.tar.gz') => %w[pkg/] + $spec.files do |f|
36
- sh <<-SH
37
- git archive \
38
- --prefix=#{$spec.name}-#{$spec.version}/ \
39
- --format=tar \
40
- HEAD | gzip > #{f.name}
41
- SH
12
+ if defined? Gem
13
+ $spec = eval(File.read('shotgun.gemspec'))
14
+
15
+ def package(ext='')
16
+ "pkg/#{$spec.name}-#{$spec.version}#{ext}"
17
+ end
18
+
19
+ desc 'Build packages'
20
+ task :package => %w[.gem .tar.gz].map { |ext| package(ext) }
21
+
22
+ desc 'Build and install as local gem'
23
+ task :install => package('.gem') do
24
+ sh "gem install #{package('.gem')}"
25
+ end
26
+
27
+ directory 'pkg/'
28
+ CLOBBER.include('pkg')
29
+
30
+ file package('.gem') => %w[pkg/ shotgun.gemspec] + $spec.files do |f|
31
+ sh "gem build shotgun.gemspec"
32
+ mv File.basename(f.name), f.name
33
+ end
34
+
35
+ file package('.tar.gz') => %w[pkg/] + $spec.files do |f|
36
+ sh <<-SH
37
+ git archive \
38
+ --prefix=shotgun-#{$spec.version}/ \
39
+ --format=tar \
40
+ HEAD | gzip > #{f.name}
41
+ SH
42
+ end
42
43
  end
data/bin/shotgun CHANGED
@@ -130,14 +130,25 @@ app_wrapper =
130
130
 
131
131
  ENV['RACK_ENV'] = env
132
132
 
133
+ # use the BROWSER environment variable or fall back to a more or less standard
134
+ # set of commands
135
+ ENV['BROWSER'] ||=
136
+ %w[open xdg-open x-www-browser firefox opera mozilla netscape].find do |comm|
137
+ next if comm == 'open' && `uname` !~ /Darwin/
138
+ ENV['PATH'].split(':').any? { |dir| File.executable?("#{dir}/#{comm}") }
139
+ end
140
+
133
141
  require 'shotgun'
134
142
  app = Shotgun.new(config, app_wrapper)
135
143
 
144
+ base_url = "http://#{options[:Host]}:#{options[:Port]}"
145
+ puts "== Shotgun starting #{server.to_s} at #{base_url}"
136
146
  server.run app, options do |inst|
137
- puts "== Shotgun starting #{server.to_s} on http://#{options[:Host]}:#{options[:Port]}"
138
-
139
147
  if browse
140
- require 'launchy'
141
- Launchy.open("http://#{options[:Host]}:#{options[:Port]}#{options[:Path]}")
148
+ if ENV['BROWSER']
149
+ system "#{ENV['BROWSER']} '#{base_url}#{options[:Path]}'"
150
+ else
151
+ abort "BROWSER environment variable not set and no browser detected"
152
+ end
142
153
  end
143
154
  end
data/shotgun.gemspec CHANGED
@@ -3,8 +3,8 @@ Gem::Specification.new do |s|
3
3
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
4
4
 
5
5
  s.name = 'shotgun'
6
- s.version = '0.5'
7
- s.date = '2010-01-16'
6
+ s.version = '0.6'
7
+ s.date = '2010-01-28'
8
8
 
9
9
  s.description = "Because reloading sucks."
10
10
  s.summary = s.description
@@ -19,13 +19,14 @@ Gem::Specification.new do |s|
19
19
  shotgun.gemspec
20
20
  lib/shotgun.rb
21
21
  bin/shotgun
22
+ test/shotgun_test.rb
23
+ test/test.ru
22
24
  ]
23
25
  s.executables = ['shotgun']
24
- s.test_files = s.files.select {|path| path =~ /^test\/.*_test.rb/}
26
+ s.test_files = ['test/shotgun_test.rb']
25
27
 
26
28
  s.extra_rdoc_files = %w[README]
27
29
  s.add_dependency 'rack', '>= 0.9.1'
28
- s.add_dependency 'launchy', '>= 0.3.3', '< 1.0'
29
30
 
30
31
  s.homepage = "http://github.com/rtomayko/shotgun/"
31
32
  s.require_paths = %w[lib]
@@ -0,0 +1,22 @@
1
+ require 'test/unit'
2
+ require 'rack/mock'
3
+ require 'shotgun'
4
+
5
+ class ShotgunTest < Test::Unit::TestCase
6
+ def setup
7
+ @rackup_file = "#{File.dirname(__FILE__)}/test.ru"
8
+ @shotgun = Shotgun.new(@rackup_file)
9
+ end
10
+
11
+ def test_knows_the_rackup_file
12
+ assert_equal @rackup_file, @shotgun.rackup_file
13
+ end
14
+
15
+ def test_processes_requests
16
+ request = Rack::MockRequest.new(@shotgun)
17
+ res = request.get("/")
18
+ assert_equal 200, res.status
19
+ assert_equal "BANG!", res.body
20
+ assert_equal "text/plain", res.headers['Content-Type']
21
+ end
22
+ end
data/test/test.ru ADDED
@@ -0,0 +1,7 @@
1
+ require 'rack'
2
+
3
+ app = lambda { |env|
4
+ [200, {'Content-Type'=>'text/plain'}, ['BANG!']] }
5
+
6
+ use Rack::ContentLength
7
+ run app
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shotgun
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.5"
4
+ version: "0.6"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Tomayko
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-16 00:00:00 -08:00
12
+ date: 2010-01-28 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,19 +22,6 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: 0.9.1
24
24
  version:
25
- - !ruby/object:Gem::Dependency
26
- name: launchy
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 0.3.3
34
- - - <
35
- - !ruby/object:Gem::Version
36
- version: "1.0"
37
- version:
38
25
  description: Because reloading sucks.
39
26
  email: r@tomayko.com
40
27
  executables:
@@ -50,6 +37,8 @@ files:
50
37
  - shotgun.gemspec
51
38
  - lib/shotgun.rb
52
39
  - bin/shotgun
40
+ - test/shotgun_test.rb
41
+ - test/test.ru
53
42
  has_rdoc: true
54
43
  homepage: http://github.com/rtomayko/shotgun/
55
44
  licenses: []
@@ -78,5 +67,5 @@ rubygems_version: 1.3.5
78
67
  signing_key:
79
68
  specification_version: 2
80
69
  summary: Because reloading sucks.
81
- test_files: []
82
-
70
+ test_files:
71
+ - test/shotgun_test.rb