guard-rackup 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ coverage/
2
+ *.gem
@@ -0,0 +1,10 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
4
+ - rbx-19mode
5
+ - jruby-19mode
6
+ - ruby-head
7
+ notifications:
8
+ email:
9
+ - k@uu59.org
10
+
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ gem "bundler"
2
+ gem "simplecov", :require => false
3
+ gem "guard"
4
+
5
+ group :test do
6
+ gem "rspec"
7
+ gem "rake"
8
+ end
@@ -0,0 +1,41 @@
1
+ GEM
2
+ specs:
3
+ diff-lcs (1.1.3)
4
+ ffi (1.0.11)
5
+ guard (1.1.1)
6
+ listen (>= 0.4.2)
7
+ thor (>= 0.14.6)
8
+ listen (0.4.2)
9
+ rb-fchange (~> 0.0.5)
10
+ rb-fsevent (~> 0.9.1)
11
+ rb-inotify (~> 0.8.8)
12
+ multi_json (1.3.5)
13
+ rake (0.9.2.2)
14
+ rb-fchange (0.0.5)
15
+ ffi
16
+ rb-fsevent (0.9.1)
17
+ rb-inotify (0.8.8)
18
+ ffi (>= 0.5.0)
19
+ rspec (2.10.0)
20
+ rspec-core (~> 2.10.0)
21
+ rspec-expectations (~> 2.10.0)
22
+ rspec-mocks (~> 2.10.0)
23
+ rspec-core (2.10.1)
24
+ rspec-expectations (2.10.0)
25
+ diff-lcs (~> 1.1.3)
26
+ rspec-mocks (2.10.1)
27
+ simplecov (0.6.4)
28
+ multi_json (~> 1.0)
29
+ simplecov-html (~> 0.5.3)
30
+ simplecov-html (0.5.3)
31
+ thor (0.14.6)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ bundler
38
+ guard
39
+ rake
40
+ rspec
41
+ simplecov
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 uu59
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ `guard-rackup` is an alternative of [shotgun](https://github.com/rtomayko/shotgun/)
2
+
3
+ # Install
4
+
5
+ $ gem i guard-rackup
6
+
7
+ Or add it your Gemfile:
8
+
9
+ $ gem "guard-rackup"
10
+ $ bundle install
11
+
12
+ And then add a basic setup to your Guardfile:
13
+
14
+ $ guard init rackup
15
+
16
+ # Usage
17
+
18
+ Please reada [Guard document](https://github.com/guard/guard#readme)
19
+
20
+
21
+ # Guardfile
22
+
23
+ guard "rackup" do
24
+ watch(%r{^app/.*\.rb$})
25
+ watch(%r{^lib/.*\.rb$})
26
+ ...
27
+ end
28
+
29
+ Or
30
+
31
+ guard "rackup",
32
+ :command => "unicorn ./config.ru -E development",
33
+ :start => proc{ Process.spawn(command) },
34
+ :stop => proc{|pid| Process.kill("QUIT", pid)},
35
+ :reload => proc{ Process.kill("HUP", @pid) }
36
+ do
37
+ watch ...
38
+ end
39
+
@@ -0,0 +1,11 @@
1
+ require File.expand_path("../spec/spec_helper.rb", __FILE__)
2
+
3
+ require "rspec/core/rake_task"
4
+ require "rspec/core/version"
5
+
6
+ task :default => :spec
7
+
8
+ desc "Run all examples"
9
+ RSpec::Core::RakeTask.new(:spec) do |t|
10
+ #t.ruby_opts = %w[-w]
11
+ end
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/guard/rackup/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["uu59"]
6
+ gem.email = ["k@uu59.org"]
7
+ gem.description = %q{Alternative of shotgun that built on guard}
8
+ gem.summary = %q{Alternative of shotgun that built on guard}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "guard-rackup"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Guard::Rackup::VERSION
17
+ end
@@ -0,0 +1,64 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+ require 'guard/watcher'
4
+
5
+ module Guard
6
+ class Rackup < Guard
7
+ autoload :Runner, "guard/rackup/runner"
8
+
9
+ attr_reader :runner
10
+
11
+ def initialize(watchers = [], options = {})
12
+ super(watchers, options)
13
+ @runner = Runner.new(options)
14
+ end
15
+
16
+ # Call once when Guard starts. Please override initialize method to init stuff.
17
+ #
18
+ # @raise [:task_has_failed] when start has failed
19
+ # @return [Object] the task result
20
+ #
21
+ def start
22
+ run_all if options[:all_on_start]
23
+ end
24
+
25
+ # Called when `stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).
26
+ #
27
+ # @raise [:task_has_failed] when stop has failed
28
+ # @return [Object] the task result
29
+ #
30
+ def stop
31
+ @runner.stop
32
+ end
33
+
34
+ # Called when `reload|r|z + enter` is pressed.
35
+ # This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
36
+ #
37
+ # @raise [:task_has_failed] when reload has failed
38
+ # @return [Object] the task result
39
+ #
40
+ def reload
41
+ @runner.reload
42
+ end
43
+
44
+ # Called when just `enter` is pressed
45
+ # This method should be principally used for long action like running all specs/tests/...
46
+ #
47
+ # @raise [:task_has_failed] when run_all has failed
48
+ # @return [Object] the task result
49
+ #
50
+ def run_all
51
+ run_on_changes
52
+ end
53
+
54
+ # Default behaviour on file(s) changes that the Guard watches.
55
+ #
56
+ # @param [Array<String>] paths the changes files or paths
57
+ # @raise [:task_has_failed] when run_on_change has failed
58
+ # @return [Object] the task result
59
+ #
60
+ def run_on_changes(paths = [])
61
+ @runner.reload
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,57 @@
1
+ module Guard
2
+ class Rackup
3
+ class Runner
4
+ DEFAULT_OPTIONS = {
5
+ :command => "rackup ./config.ru -E development",
6
+ :start => proc{ Process.spawn(command) },
7
+ :stop => proc{|pid| Process.kill("INT", pid); Process.wait pid},
8
+ :reload => proc{ stop; start },
9
+ }
10
+
11
+ attr_reader :pid, :options
12
+
13
+ def initialize(options)
14
+ @pid = nil
15
+ @options = DEFAULT_OPTIONS.merge(options)
16
+ end
17
+
18
+ def start
19
+ return @pid if alive?
20
+ @pid = instance_eval &@options[:start]
21
+ end
22
+
23
+ def stop
24
+ if alive?
25
+ instance_eval do
26
+ @options[:stop].call(@pid)
27
+ @pid = nil
28
+ end
29
+ end
30
+ end
31
+
32
+ def reload
33
+ instance_eval &@options[:reload]
34
+ end
35
+
36
+ def restart
37
+ stop if alive?
38
+ start
39
+ end
40
+
41
+ def command
42
+ @options[:command]
43
+ end
44
+
45
+ def alive?
46
+ return false unless @pid
47
+
48
+ begin
49
+ Process.getpgid(@pid)
50
+ true
51
+ rescue Errno::ESRCH => e
52
+ false
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,18 @@
1
+ # guard-rackup
2
+ # Tha command for rackup
3
+ # :command => "rackup ./config.ru -E development",
4
+ #
5
+ # start(run :command as above) proc, it must return pid
6
+ # :start => proc{ Process.spawn(command) },
7
+ #
8
+ # stop proc
9
+ # :stop => proc{|pid| Process.kill("INT", pid); Process.wait pid},
10
+ #
11
+ # reload proc that fired when watched files changed
12
+ # :reload => proc{ stop; start },
13
+ guard "rackup" do
14
+ watch(%r{^app/.*\.rb$})
15
+ watch(%r{^lib/.*\.rb$})
16
+ watch(%r{^config/.*\.rb$})
17
+ watch("config.ru")
18
+ end
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ class Rackup
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ require "spec_helper"
2
+
3
+ describe Guard::Rackup do
4
+ subject { Guard::Rackup.new }
5
+ let(:runner) { subject.runner }
6
+
7
+ %W!run_all run_on_changes reload!.each do |method|
8
+ it "##{method} call runner#reload" do
9
+ runner.should_receive(:reload)
10
+ subject.__send__(method.to_sym)
11
+ end
12
+ end
13
+
14
+ it "#stop call runner#stop" do
15
+ runner.should_receive(:stop)
16
+ subject.stop
17
+ end
18
+ end
@@ -0,0 +1,102 @@
1
+ require "spec_helper"
2
+
3
+ describe Guard::Rackup::Runner do
4
+ def guard(options = {})
5
+ Guard::Rackup.new([], options)
6
+ end
7
+
8
+ let(:runner) { @g.runner }
9
+
10
+ describe "default options" do
11
+ before(:each) do
12
+ @g = guard(:command => "sleep 2")
13
+ end
14
+
15
+ it "#start return pid" do
16
+ runner.pid.should be_nil
17
+ runner.start.should_not be_nil
18
+ runner.pid.should_not be_nil
19
+ end
20
+
21
+ it "#stop" do
22
+ runner.start
23
+ pid = runner.pid
24
+ lambda{ Process.getpgid(pid) }.should_not raise_error
25
+ runner.stop
26
+ lambda{ Process.getpgid(pid) }.should raise_error(Errno::ESRCH)
27
+ runner.pid.should be_nil
28
+ end
29
+
30
+ it "#reload" do
31
+ runner.should_receive(:stop)
32
+ runner.should_receive(:start)
33
+ runner.reload
34
+ end
35
+
36
+ it "#start" do
37
+ runner.should_not_receive(:stop)
38
+ runner.should_receive(:start)
39
+ runner.restart
40
+ end
41
+ end
42
+
43
+ describe "respond to methods" do
44
+ before(:each) do
45
+ $start = nil
46
+ $stop = nil
47
+ $reload = nil
48
+ @g = guard(
49
+ :command => "sleep 3",
50
+ :start => proc{ $start = :called; Process.spawn(command) },
51
+ :stop => proc{ $stop = :called },
52
+ :reload => proc{ $reload = :called },
53
+ )
54
+ end
55
+
56
+ it "options[:start]" do
57
+ runner.start
58
+ $start.should_not be_nil
59
+ $stop.should be_nil
60
+ $reload.should be_nil
61
+ end
62
+
63
+ it "options[:stop]" do
64
+ runner.start
65
+ runner.stop
66
+ $stop.should_not be_nil
67
+ $reload.should be_nil
68
+ end
69
+
70
+ it "options[:reload]" do
71
+ runner.reload
72
+ $reload.should_not be_nil
73
+ $start.should be_nil
74
+ $stop.should be_nil
75
+ end
76
+
77
+ it "not call options[:stop] when @pid is nil" do
78
+ runner.stop
79
+ $stop.should be_nil
80
+ $reload.should be_nil
81
+ $start.should be_nil
82
+ end
83
+ end
84
+
85
+ context "quality" do
86
+ before(:each) do
87
+ @g = guard(
88
+ :command => "sleep 3",
89
+ )
90
+ end
91
+
92
+ it "process killed by external thing" do
93
+ pid = runner.start
94
+ runner.alive?.should be_true
95
+ Process.kill("INT", pid)
96
+ Process.wait pid
97
+ runner.alive?.should be_false
98
+ lambda { runner.stop }.should_not raise_error
99
+ end
100
+ end
101
+
102
+ end
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ Bundler.require(:default, :test)
4
+
5
+ ENV["GUARD_ENV"] = 'test'
6
+
7
+ Dir["#{File.expand_path('..', __FILE__)}/support/**/*.rb"].each { |f| require f }
8
+
9
+ if ENV["COVERAGE"]
10
+ require "simplecov"
11
+ SimpleCov.start
12
+ end
13
+ require 'guard/rackup'
14
+
15
+ RSpec.configure do |conf|
16
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-rackup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - uu59
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-06 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Alternative of shotgun that built on guard
15
+ email:
16
+ - k@uu59.org
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - .travis.yml
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - LICENSE
26
+ - README.mkd
27
+ - Rakefile
28
+ - guard-rackup.gemspec
29
+ - lib/guard/rackup.rb
30
+ - lib/guard/rackup/runner.rb
31
+ - lib/guard/rackup/templates/Guardfile
32
+ - lib/guard/rackup/version.rb
33
+ - spec/rackup_spec.rb
34
+ - spec/runner_spec.rb
35
+ - spec/spec_helper.rb
36
+ homepage: ''
37
+ licenses: []
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 1.8.11
57
+ signing_key:
58
+ specification_version: 3
59
+ summary: Alternative of shotgun that built on guard
60
+ test_files:
61
+ - spec/rackup_spec.rb
62
+ - spec/runner_spec.rb
63
+ - spec/spec_helper.rb