guard-process 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8352e0702153cb9ec2326e0085e7e1afdd63fe2c
4
+ data.tar.gz: 6d1460ac31af8b7e0f5a1ed4baf2c7568e466c08
5
+ SHA512:
6
+ metadata.gz: 4bd586ca45c4b14636bfee2651f6a4496d09077dd2f44f019d132d8ce6e49a37ab254d4adf39c24260d5f34d9fcb4c1afedfcd8fac0b0c1dd40198bb7664f285
7
+ data.tar.gz: 7e01859b8413bb529c3764628313f671ecee72288671b31c77b3d45cf20e5d7154408b0049b8dcbfa119e9c4ca66532ef7f129d32dacfda869fcef7613e27588
data/.gitignore CHANGED
@@ -1,5 +1,5 @@
1
- *.gem
2
- .bundle
3
- Gemfile.lock
4
- pkg/*
5
- .vagrant
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .vagrant
@@ -1,10 +1,10 @@
1
- notifications:
2
- recipients:
3
- - mark@socialreferral.com
4
- - andre@socialreferral.com
5
- rvm:
6
- - 1.9.3
7
- - 2.0.0
8
- - 2.1.4
9
- - jruby-19mode
10
- script: "bundle exec rake test"
1
+ notifications:
2
+ recipients:
3
+ - mark@socialreferral.com
4
+ - andre@socialreferral.com
5
+ rvm:
6
+ - 1.9.3
7
+ - 2.0.0
8
+ - 2.1.4
9
+ - jruby-19mode
10
+ script: "bundle exec rake test"
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in guard-process.gemspec
4
- gemspec
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in guard-process.gemspec
4
+ gemspec
data/Guardfile CHANGED
@@ -1,11 +1,11 @@
1
- guard 'bundler' do
2
- watch('Gemfile')
3
- watch(/^.+\.gemspec/)
4
- end
5
-
6
- guard 'minitest' do
7
- # with Minitest::Unit
8
- watch(%r|^test/(.*)_test\.rb|)
9
- watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}#{m[2]}_test.rb" }
10
- watch(%r|^test/test_helper\.rb|) { "test" }
11
- end
1
+ guard 'bundler' do
2
+ watch('Gemfile')
3
+ watch(/^.+\.gemspec/)
4
+ end
5
+
6
+ guard 'minitest' do
7
+ # with Minitest::Unit
8
+ watch(%r|^test/(.*)_test\.rb|)
9
+ watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}#{m[2]}_test.rb" }
10
+ watch(%r|^test/test_helper\.rb|) { "test" }
11
+ end
data/LICENSE CHANGED
@@ -1,19 +1,19 @@
1
- Copyright (C) 2011 by SocialReferral
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy
4
- of this software and associated documentation files (the "Software"), to deal
5
- in the Software without restriction, including without limitation the rights
6
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- copies of the Software, and to permit persons to whom the Software is
8
- furnished to do so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in
11
- all copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- THE SOFTWARE.
1
+ Copyright (C) 2011 by SocialReferral
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,80 +1,80 @@
1
- # Guard::Process [![Build Status](https://secure.travis-ci.org/guard/guard-process.png)](http://travis-ci.org/guard/guard-process)
2
- Guard to run processes and commands.
3
-
4
- This gem requires Ruby 1.9.3, 2.0.0 or JRuby in 1.9 mode.
5
-
6
- # Usage
7
- Please read the [Guard documentation](https://github.com/guard/guard#readme) to learn how to use Guard.
8
-
9
- There is also an exellent screencast available on [Railscasts](http://railscasts.com/episodes/264-guard)
10
-
11
- Additionally there is a great introductory article on [Intridea Blog](http://intridea.com/2011/8/25/hire-a-guard-for-your-project) mentioning Guard::Process.
12
-
13
- # Guardfile
14
- You can add as many process Guards as you want, an example Guardfile:
15
-
16
- ``` ruby
17
- guard 'process', :name => 'EndlessRunner', :command => 'rails runner Something::ThatGoesOnAndOn' do
18
- watch('Gemfile.lock')
19
- end
20
-
21
- guard 'process', :name => 'AnotherRunner', :command => ['rails', 'runner', 'AnotherRunner'] do
22
- watch('Gemfile.lock')
23
- end
24
- ```
25
-
26
- # Options
27
- The following options are available:
28
-
29
- - name
30
- The display name of your process in Guard, this is shown when Guard::Process is starting and stopping your process
31
- - command
32
- The command to run as you would run it from the command line. NOTE: You cannot string commands together like you would on the shell with ; or && because of the way guard-process launches its processes, if you need to combine several shell commands you should write a shell script and call from your command.
33
- - dir
34
- The directory in which you want to run the command, if none is given then Ruby's current working directory is used
35
- - stop_signal
36
- The signal that Guard::Process sends to terminate the process when it needs to stop/restart it. This defaults to 'TERM' (in some cases you may need KILL).
37
- - dont_stop
38
- When a reload is triggered this will not stop the process, instead it will wait for the current process run to finish before starting a new one. This is useful for having guard-process execute commands that don't run constantly that you don't want to interrupt as they run.
39
- - env
40
- A Hash with environmental variables to set for the context where your command runs, like so:
41
- ``` ruby
42
- {"SSL_CERTS_DIR" => "/etc/ssl/certs", "JAVA_HOME" => "/usr/local/java"}
43
- ```
44
-
45
- # TODO
46
-
47
- Clean up the test cases
48
-
49
- # Changes
50
-
51
- ## 1.1.0
52
-
53
- - Updated for Guard 2.x
54
-
55
- ## 1.0.6
56
-
57
- - Allow passing in command as an Array as well as a String
58
-
59
- ## 1.0.5
60
-
61
- - Adds the dont_stop option
62
-
63
- ## 1.0.4
64
-
65
- - Adds the dir option
66
-
67
- # Development
68
- - Source hosted on [GitHub](https://github.com)
69
- - Please report issues and feature requests using [GitHub issues](https://github.com/guard/guard-process/issues)
70
-
71
- Pull requests are welcome, please make sure your patches are well tested before contributing. When sending a pull request:
72
- - Use a topic branch for your change
73
- - Add tests for your changes using MiniTest::Unit
74
- - Do not change the version number in the gemspec
75
-
76
- # License
77
- Guard::Process is released under the MIT license.
78
-
79
- # Author
80
- [Mark Kremer](https://github.com/mkremer)
1
+ # Guard::Process [![Build Status](https://secure.travis-ci.org/guard/guard-process.png)](http://travis-ci.org/guard/guard-process)
2
+ Guard to run processes and commands.
3
+
4
+ This gem requires Ruby 1.9.3, 2.0.0 or JRuby in 1.9 mode.
5
+
6
+ # Usage
7
+ Please read the [Guard documentation](https://github.com/guard/guard#readme) to learn how to use Guard.
8
+
9
+ There is also an exellent screencast available on [Railscasts](http://railscasts.com/episodes/264-guard)
10
+
11
+ Additionally there is a great introductory article on [Intridea Blog](http://intridea.com/2011/8/25/hire-a-guard-for-your-project) mentioning Guard::Process.
12
+
13
+ # Guardfile
14
+ You can add as many process Guards as you want, an example Guardfile:
15
+
16
+ ``` ruby
17
+ guard 'process', :name => 'EndlessRunner', :command => 'rails runner Something::ThatGoesOnAndOn' do
18
+ watch('Gemfile.lock')
19
+ end
20
+
21
+ guard 'process', :name => 'AnotherRunner', :command => ['rails', 'runner', 'AnotherRunner'] do
22
+ watch('Gemfile.lock')
23
+ end
24
+ ```
25
+
26
+ # Options
27
+ The following options are available:
28
+
29
+ - name
30
+ The display name of your process in Guard, this is shown when Guard::Process is starting and stopping your process
31
+ - command
32
+ The command to run as you would run it from the command line. NOTE: You cannot string commands together like you would on the shell with ; or && because of the way guard-process launches its processes, if you need to combine several shell commands you should write a shell script and call from your command.
33
+ - dir
34
+ The directory in which you want to run the command, if none is given then Ruby's current working directory is used
35
+ - stop_signal
36
+ The signal that Guard::Process sends to terminate the process when it needs to stop/restart it. This defaults to 'TERM' (in some cases you may need KILL).
37
+ - dont_stop
38
+ When a reload is triggered this will not stop the process, instead it will wait for the current process run to finish before starting a new one. This is useful for having guard-process execute commands that don't run constantly that you don't want to interrupt as they run.
39
+ - env
40
+ A Hash with environmental variables to set for the context where your command runs, like so:
41
+ ``` ruby
42
+ {"SSL_CERTS_DIR" => "/etc/ssl/certs", "JAVA_HOME" => "/usr/local/java"}
43
+ ```
44
+
45
+ # TODO
46
+
47
+ Clean up the test cases
48
+
49
+ # Changes
50
+
51
+ ## 1.1.0
52
+
53
+ - Updated for Guard 2.x
54
+
55
+ ## 1.0.6
56
+
57
+ - Allow passing in command as an Array as well as a String
58
+
59
+ ## 1.0.5
60
+
61
+ - Adds the dont_stop option
62
+
63
+ ## 1.0.4
64
+
65
+ - Adds the dir option
66
+
67
+ # Development
68
+ - Source hosted on [GitHub](https://github.com)
69
+ - Please report issues and feature requests using [GitHub issues](https://github.com/guard/guard-process/issues)
70
+
71
+ Pull requests are welcome, please make sure your patches are well tested before contributing. When sending a pull request:
72
+ - Use a topic branch for your change
73
+ - Add tests for your changes using MiniTest::Unit
74
+ - Do not change the version number in the gemspec
75
+
76
+ # License
77
+ Guard::Process is released under the MIT license.
78
+
79
+ # Author
80
+ [Mark Kremer](https://github.com/mkremer)
data/Rakefile CHANGED
@@ -1,9 +1,9 @@
1
- require 'bundler/gem_tasks'
2
- require 'rake/testtask'
3
-
4
- task :default => :test
5
- Rake::TestTask.new do |t|
6
- t.libs << 'test'
7
- t.pattern = 'test/**/*_test.rb'
8
- end
9
-
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ task :default => :test
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'test'
7
+ t.pattern = 'test/**/*_test.rb'
8
+ end
9
+
@@ -1,13 +1,13 @@
1
- # -*- mode: ruby -*-
2
- # vi: set ft=ruby :
3
-
4
- # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5
- VAGRANTFILE_API_VERSION = "2"
6
-
7
- Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
8
- config.vm.hostname = "guard"
9
- config.vm.box = "precise64"
10
- config.vm.box_url = "http://files.vagrantup.com/precise64.box"
11
- config.vm.network :private_network, ip: "192.168.33.21"
12
- config.vm.provision :shell, :path => "vagrant-provision"
13
- end
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5
+ VAGRANTFILE_API_VERSION = "2"
6
+
7
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
8
+ config.vm.hostname = "guard"
9
+ config.vm.box = "precise64"
10
+ config.vm.box_url = "http://files.vagrantup.com/precise64.box"
11
+ config.vm.network :private_network, ip: "192.168.33.21"
12
+ config.vm.provision :shell, :path => "vagrant-provision"
13
+ end
@@ -1,31 +1,30 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require 'rbconfig' unless defined?(RbConfig)
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "guard-process"
7
- s.version = "1.1.0"
8
- s.authors = ["Mark Kremer"]
9
- s.email = ["mark@without-brains.net"]
10
- s.homepage = ""
11
- s.summary = %q{Guard extension to run cli processes}
12
- s.description = %q{Guard extension to run cli processes}
13
-
14
- s.required_ruby_version = '>= 1.9.3'
15
-
16
- s.files = `git ls-files`.split("\n")
17
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
- s.require_paths = ["lib"]
20
-
21
- s.add_dependency('guard', '>= 2.0.0')
22
- s.add_dependency('guard-compat', '~> 0.1', '>= 0.1.1')
23
- s.add_dependency('spoon', '~> 0.0.1')
24
- s.add_development_dependency('minitest')
25
- s.add_development_dependency('mocha')
26
- s.add_development_dependency('guard-minitest')
27
- s.add_development_dependency('guard-bundler')
28
- s.add_development_dependency('rake')
29
- s.add_development_dependency('rb-inotify') if RbConfig::CONFIG['target_os'] == 'linux'
30
- s.add_development_dependency('pry')
31
- end
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'rbconfig' unless defined?(RbConfig)
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "guard-process"
7
+ s.version = "1.2.0"
8
+ s.authors = ["Mark Kremer"]
9
+ s.email = ["mark@without-brains.net"]
10
+ s.homepage = ""
11
+ s.summary = %q{Guard extension to run cli processes}
12
+ s.description = %q{Guard extension to run cli processes}
13
+
14
+ s.required_ruby_version = '>= 1.9.3'
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency('guard', '>= 2.0.0')
22
+ s.add_dependency('spoon', '~> 0.0.1')
23
+ s.add_development_dependency('minitest')
24
+ s.add_development_dependency('mocha')
25
+ s.add_development_dependency('guard-minitest')
26
+ s.add_development_dependency('guard-bundler')
27
+ s.add_development_dependency('rake')
28
+ s.add_development_dependency('rb-inotify') if RbConfig::CONFIG['target_os'] == 'linux'
29
+ s.add_development_dependency('pry')
30
+ end
@@ -1,84 +1,85 @@
1
- require 'guard/compat/plugin'
2
- require 'spoon'
3
-
4
- module Guard
5
- class Process < Plugin
6
- def initialize(options = {})
7
- @pid = nil
8
- @command = options.fetch(:command)
9
- @command = @command.split(" ") if @command.is_a?(String)
10
- @env = options[:env] || {}
11
- @name = options[:name]
12
- @dir = options[:dir] || Dir.getwd
13
- @stop_signal = options[:stop_signal] || "TERM"
14
- @dont_stop = options[:dont_stop]
15
- super
16
- end
17
-
18
- def wait_for_stop?
19
- @dont_stop
20
- end
21
-
22
- def process_running?
23
- begin
24
- @pid ? ::Process.kill(0, @pid) : false
25
- rescue Errno::ESRCH => e
26
- false
27
- end
28
- end
29
-
30
- def start
31
- UI.info("Starting process #{@name}")
32
- original_env = {}
33
- @env.each_pair do |key, value|
34
- original_env[key] = ENV[key]
35
- ENV[key] = value
36
- end
37
- Dir.chdir(@dir) do
38
- @pid = Spoon.spawnp(*@command)
39
- end
40
- original_env.each_pair do |key, value|
41
- ENV[key] = value
42
- end
43
- UI.info("Started process #{@name}")
44
- end
45
-
46
- def stop
47
- if @pid
48
- UI.info("Stopping process #{@name}")
49
- begin
50
- ::Process.kill(@stop_signal, @pid)
51
- ::Process.waitpid(@pid)
52
- rescue Errno::ESRCH
53
- end
54
- @pid = nil
55
- UI.info("Stopped process #{@name}")
56
- end
57
- end
58
-
59
- def wait_for_stop
60
- if @pid
61
- UI.info("Process #{@name} is still running...")
62
- ::Process.waitpid(@pid) rescue Errno::ESRCH
63
- UI.info("Process #{@name} has stopped!")
64
- end
65
- end
66
-
67
- def reload
68
- if wait_for_stop?
69
- wait_for_stop
70
- else
71
- stop
72
- end
73
- start
74
- end
75
-
76
- def run_all
77
- true
78
- end
79
-
80
- def run_on_change(paths)
81
- reload
82
- end
83
- end
84
- end
1
+ require 'guard'
2
+ require 'guard/plugin'
3
+ require 'spoon'
4
+
5
+ module Guard
6
+ class Process < Plugin
7
+ def initialize(options = {})
8
+ @pid = nil
9
+ @command = options.fetch(:command)
10
+ @command = @command.split(" ") if @command.is_a?(String)
11
+ @env = options[:env] || {}
12
+ @name = options[:name]
13
+ @dir = options[:dir] || Dir.getwd
14
+ @stop_signal = options[:stop_signal] || "TERM"
15
+ @dont_stop = options[:dont_stop]
16
+ super
17
+ end
18
+
19
+ def wait_for_stop?
20
+ @dont_stop
21
+ end
22
+
23
+ def process_running?
24
+ begin
25
+ @pid ? ::Process.kill(0, @pid) : false
26
+ rescue Errno::ESRCH => e
27
+ false
28
+ end
29
+ end
30
+
31
+ def start
32
+ UI.info("Starting process #{@name}")
33
+ original_env = {}
34
+ @env.each_pair do |key, value|
35
+ original_env[key] = ENV[key]
36
+ ENV[key] = value
37
+ end
38
+ Dir.chdir(@dir) do
39
+ @pid = Spoon.spawnp(*@command)
40
+ end
41
+ original_env.each_pair do |key, value|
42
+ ENV[key] = value
43
+ end
44
+ UI.info("Started process #{@name}")
45
+ end
46
+
47
+ def stop
48
+ if @pid
49
+ UI.info("Stopping process #{@name}")
50
+ begin
51
+ ::Process.kill(@stop_signal, @pid)
52
+ ::Process.waitpid(@pid)
53
+ rescue Errno::ESRCH
54
+ end
55
+ @pid = nil
56
+ UI.info("Stopped process #{@name}")
57
+ end
58
+ end
59
+
60
+ def wait_for_stop
61
+ if @pid
62
+ UI.info("Process #{@name} is still running...")
63
+ ::Process.waitpid(@pid) rescue Errno::ESRCH
64
+ UI.info("Process #{@name} has stopped!")
65
+ end
66
+ end
67
+
68
+ def reload
69
+ if wait_for_stop?
70
+ wait_for_stop
71
+ else
72
+ stop
73
+ end
74
+ start
75
+ end
76
+
77
+ def run_all
78
+ true
79
+ end
80
+
81
+ def run_on_change(paths)
82
+ reload
83
+ end
84
+ end
85
+ end
@@ -1,5 +1,5 @@
1
- # This is an example with all options that you can specify for guard-process
2
- guard 'process', :name => 'name of your process', :command => 'ruby path/to/your/file.rb', :env => {"ENV1" => "value 1", "ENV2" => "value 2"}, :stop_signal => "KILL" do
3
- watch('Gemfile.lock')
4
- end
5
-
1
+ # This is an example with all options that you can specify for guard-process
2
+ guard 'process', :name => 'name of your process', :command => 'ruby path/to/your/file.rb', :env => {"ENV1" => "value 1", "ENV2" => "value 2"}, :stop_signal => "KILL" do
3
+ watch('Gemfile.lock')
4
+ end
5
+
@@ -1,122 +1,122 @@
1
- require_relative '../test_helper'
2
- require 'timeout'
3
-
4
- class GuardProcessTest < MiniTest::Test
5
- def setup
6
- ENV['GUARD_ENV'] = 'test'
7
- @command = "ruby #{TEST_ROOT}/run_me.rb"
8
- @name = "RunMe"
9
- @options = {:command => @command, :name => @name}
10
- @guard = Guard::Process.new(@options)
11
- end
12
-
13
- def teardown
14
- if @guard.process_running?
15
- if @guard.wait_for_stop?
16
- @guard.wait_for_stop
17
- else
18
- @guard.stop
19
- end
20
- end
21
- ENV['GUARD_ENV'] = nil
22
- end
23
-
24
- def test_run_all_returns_true
25
- assert @guard.run_all
26
- end
27
-
28
- def test_run_on_change_does_a_reload
29
- @guard.expects(:reload)
30
- @guard.run_on_change("")
31
- end
32
-
33
- def test_start_runs_command_and_stop_stops_it
34
- Guard::UI.expects(:info).with("Starting process #{@name}")
35
- Guard::UI.expects(:info).with("Started process #{@name}")
36
- @guard.start
37
- assert @guard.process_running?
38
- Guard::UI.expects(:info).with("Stopping process #{@name}")
39
- Guard::UI.expects(:info).with("Stopped process #{@name}")
40
- @guard.stop
41
- refute @guard.process_running?
42
- end
43
-
44
- def test_reload_stops_and_starts_command
45
- @guard.expects(:wait_for_stop).never
46
- @guard.expects(:stop)
47
- @guard.expects(:start).twice
48
- @guard.start
49
- @guard.reload
50
- end
51
-
52
- def test_reload_waits_for_command_to_finish_before_starting_again_if_dont_stop_option_set
53
- @options = {:command => "ruby #{TEST_ROOT}/run_2_seconds.rb", :name => '2Seconds', :dont_stop => true}
54
- @guard = Guard::Process.new(@options)
55
- @guard.expects(:wait_for_stop).at_least_once
56
- @guard.expects(:stop).never
57
- @guard.expects(:start).twice
58
- @guard.start
59
- @guard.reload
60
- end
61
-
62
- def test_start_sets_env_properly
63
- ENV['VAR1'] = 'VALUE A'
64
- @options[:env] = {'VAR1' => 'VALUE 1', 'VAR3' => 'VALUE 2'}
65
-
66
- environment_file = "#{TEST_ROOT}/test_environment.txt"
67
- File.delete(environment_file) if File.exists?(environment_file)
68
-
69
- @guard = Guard::Process.new(@options)
70
- @guard.start
71
-
72
- # Check the environment
73
- assert_equal ENV['VAR1'], 'VALUE A'
74
- assert_nil ENV['VAR2']
75
- assert_nil ENV['VAR3']
76
-
77
- # Wait for run_me.rb to write the environment details to file
78
- Timeout.timeout(30) do
79
- until File.exist?("#{TEST_ROOT}/test_environment.txt") do
80
- sleep 0.5
81
- end
82
- end
83
-
84
- # Read the written environment and convert it to a Hash, and get rid of the file
85
- written_env = Hash[File.read("#{TEST_ROOT}/test_environment.txt").split("\n").map {|l| l.split(" = ")}]
86
- File.delete("#{TEST_ROOT}/test_environment.txt")
87
-
88
- # Verify that the written environment matches what was set in options[:env]
89
- assert_equal 'VALUE 1', written_env['VAR1']
90
- assert_equal nil, written_env['VAR2']
91
- assert_equal 'VALUE 2', written_env['VAR3']
92
- end
93
-
94
- def test_changed_working_directory_if_option_dir_is_set
95
- @options = {:command => 'ls', :name => 'LsProcess', :dir => TEST_ROOT}
96
- Dir.expects(:chdir).with(TEST_ROOT)
97
- @guard = Guard::Process.new(@options)
98
- @guard.start and @guard.stop
99
- end
100
-
101
- def test_commands_are_formatted_properly_for_spoon
102
- @options = {:command => 'echo test test', :name => 'EchoProcess', :env => {"VAR1" => "VALUE 1"}}
103
- ::Process.stubs(:kill).returns(true)
104
- ::Process.stubs(:waitpid).returns(true)
105
-
106
- Spoon.expects(:spawnp).with("echo", "test", "test").returns(stub_everything)
107
-
108
- @guard = Guard::Process.new(@options)
109
- @guard.start and @guard.stop
110
- end
111
-
112
- def test_commands_may_be_given_in_array_form
113
- @options = {:command => ['echo', 'test', 'test'], :name => 'EchoProcess', :env => {"VAR1" => "VALUE 1"}}
114
- ::Process.stubs(:kill).returns(true)
115
- ::Process.stubs(:waitpid).returns(true)
116
-
117
- Spoon.expects(:spawnp).with("echo", "test", "test").returns(stub_everything)
118
-
119
- @guard = Guard::Process.new(@options)
120
- @guard.start and @guard.stop
121
- end
122
- end
1
+ require_relative '../test_helper'
2
+ require 'timeout'
3
+
4
+ class GuardProcessTest < MiniTest::Test
5
+ def setup
6
+ ENV['GUARD_ENV'] = 'test'
7
+ @command = "ruby #{TEST_ROOT}/run_me.rb"
8
+ @name = "RunMe"
9
+ @options = {:command => @command, :name => @name}
10
+ @guard = Guard::Process.new(@options)
11
+ end
12
+
13
+ def teardown
14
+ if @guard.process_running?
15
+ if @guard.wait_for_stop?
16
+ @guard.wait_for_stop
17
+ else
18
+ @guard.stop
19
+ end
20
+ end
21
+ ENV['GUARD_ENV'] = nil
22
+ end
23
+
24
+ def test_run_all_returns_true
25
+ assert @guard.run_all
26
+ end
27
+
28
+ def test_run_on_change_does_a_reload
29
+ @guard.expects(:reload)
30
+ @guard.run_on_change("")
31
+ end
32
+
33
+ def test_start_runs_command_and_stop_stops_it
34
+ Guard::UI.expects(:info).with("Starting process #{@name}")
35
+ Guard::UI.expects(:info).with("Started process #{@name}")
36
+ @guard.start
37
+ assert @guard.process_running?
38
+ Guard::UI.expects(:info).with("Stopping process #{@name}")
39
+ Guard::UI.expects(:info).with("Stopped process #{@name}")
40
+ @guard.stop
41
+ refute @guard.process_running?
42
+ end
43
+
44
+ def test_reload_stops_and_starts_command
45
+ @guard.expects(:wait_for_stop).never
46
+ @guard.expects(:stop)
47
+ @guard.expects(:start).twice
48
+ @guard.start
49
+ @guard.reload
50
+ end
51
+
52
+ def test_reload_waits_for_command_to_finish_before_starting_again_if_dont_stop_option_set
53
+ @options = {:command => "ruby #{TEST_ROOT}/run_2_seconds.rb", :name => '2Seconds', :dont_stop => true}
54
+ @guard = Guard::Process.new(@options)
55
+ @guard.expects(:wait_for_stop).at_least_once
56
+ @guard.expects(:stop).never
57
+ @guard.expects(:start).twice
58
+ @guard.start
59
+ @guard.reload
60
+ end
61
+
62
+ def test_start_sets_env_properly
63
+ ENV['VAR1'] = 'VALUE A'
64
+ @options[:env] = {'VAR1' => 'VALUE 1', 'VAR3' => 'VALUE 2'}
65
+
66
+ environment_file = "#{TEST_ROOT}/test_environment.txt"
67
+ File.delete(environment_file) if File.exists?(environment_file)
68
+
69
+ @guard = Guard::Process.new(@options)
70
+ @guard.start
71
+
72
+ # Check the environment
73
+ assert_equal ENV['VAR1'], 'VALUE A'
74
+ assert_nil ENV['VAR2']
75
+ assert_nil ENV['VAR3']
76
+
77
+ # Wait for run_me.rb to write the environment details to file
78
+ Timeout.timeout(30) do
79
+ until File.exist?("#{TEST_ROOT}/test_environment.txt") do
80
+ sleep 0.5
81
+ end
82
+ end
83
+
84
+ # Read the written environment and convert it to a Hash, and get rid of the file
85
+ written_env = Hash[File.read("#{TEST_ROOT}/test_environment.txt").split("\n").map {|l| l.split(" = ")}]
86
+ File.delete("#{TEST_ROOT}/test_environment.txt")
87
+
88
+ # Verify that the written environment matches what was set in options[:env]
89
+ assert_equal 'VALUE 1', written_env['VAR1']
90
+ assert_equal nil, written_env['VAR2']
91
+ assert_equal 'VALUE 2', written_env['VAR3']
92
+ end
93
+
94
+ def test_changed_working_directory_if_option_dir_is_set
95
+ @options = {:command => 'ls', :name => 'LsProcess', :dir => TEST_ROOT}
96
+ Dir.expects(:chdir).with(TEST_ROOT)
97
+ @guard = Guard::Process.new(@options)
98
+ @guard.start and @guard.stop
99
+ end
100
+
101
+ def test_commands_are_formatted_properly_for_spoon
102
+ @options = {:command => 'echo test test', :name => 'EchoProcess', :env => {"VAR1" => "VALUE 1"}}
103
+ ::Process.stubs(:kill).returns(true)
104
+ ::Process.stubs(:waitpid).returns(true)
105
+
106
+ Spoon.expects(:spawnp).with("echo", "test", "test").returns(stub_everything)
107
+
108
+ @guard = Guard::Process.new(@options)
109
+ @guard.start and @guard.stop
110
+ end
111
+
112
+ def test_commands_may_be_given_in_array_form
113
+ @options = {:command => ['echo', 'test', 'test'], :name => 'EchoProcess', :env => {"VAR1" => "VALUE 1"}}
114
+ ::Process.stubs(:kill).returns(true)
115
+ ::Process.stubs(:waitpid).returns(true)
116
+
117
+ Spoon.expects(:spawnp).with("echo", "test", "test").returns(stub_everything)
118
+
119
+ @guard = Guard::Process.new(@options)
120
+ @guard.start and @guard.stop
121
+ end
122
+ end
@@ -1,7 +1,7 @@
1
- #!/usr/bin/env ruby
2
-
3
- puts "Running this program for 2 seconds"
4
- sleep 1
5
- puts "One more second to go!"
6
- sleep 1
7
- puts "Done!"
1
+ #!/usr/bin/env ruby
2
+
3
+ puts "Running this program for 2 seconds"
4
+ sleep 1
5
+ puts "One more second to go!"
6
+ sleep 1
7
+ puts "Done!"
@@ -1,14 +1,14 @@
1
- #!/usr/bin/env ruby
2
-
3
- file_name = "#{File.expand_path(File.dirname(__FILE__))}/test_environment.txt"
4
-
5
- File.open(file_name, 'w') do |file|
6
- file.write("VAR1 = #{ENV['VAR1']}\n")
7
- file.write("VAR2 = #{ENV['VAR2']}\n")
8
- file.write("VAR3 = #{ENV['VAR3']}\n")
9
- end
10
-
11
- loop do
12
- sleep 1
13
- end
14
-
1
+ #!/usr/bin/env ruby
2
+
3
+ file_name = "#{File.expand_path(File.dirname(__FILE__))}/test_environment.txt"
4
+
5
+ File.open(file_name, 'w') do |file|
6
+ file.write("VAR1 = #{ENV['VAR1']}\n")
7
+ file.write("VAR2 = #{ENV['VAR2']}\n")
8
+ file.write("VAR3 = #{ENV['VAR3']}\n")
9
+ end
10
+
11
+ loop do
12
+ sleep 1
13
+ end
14
+
@@ -1,10 +1,6 @@
1
- require 'minitest/autorun'
2
- require 'mocha/setup'
3
-
4
- require 'guard/notifier'
5
- require 'guard/compat/test/helper'
6
- require 'guard/process'
7
-
8
- require 'pry'
9
-
10
- TEST_ROOT = File.expand_path(File.dirname(__FILE__))
1
+ require 'minitest/autorun'
2
+ require 'mocha/setup'
3
+ require 'guard/process'
4
+ require 'pry'
5
+
6
+ TEST_ROOT = File.expand_path(File.dirname(__FILE__))
@@ -1,10 +1,10 @@
1
- #!/usr/bin/env bash
2
-
3
- export DEBIAN_FRONTEND=noninteractive
4
-
5
- apt-get update > /dev/null
6
- apt-get -y install build-essential git-core ruby1.9.1-full ruby1.9.1-dev libyaml-dev libssl-dev zlib1g-dev libreadline-dev openssl libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev autoconf libc6-dev ncurses-dev automake libtool bison libffi-dev
7
-
8
- gem install bundler pry
9
-
10
- su -c 'cd /vagrant && bundle' vagrant
1
+ #!/usr/bin/env bash
2
+
3
+ export DEBIAN_FRONTEND=noninteractive
4
+
5
+ apt-get update > /dev/null
6
+ apt-get -y install build-essential git-core ruby1.9.1-full ruby1.9.1-dev libyaml-dev libssl-dev zlib1g-dev libreadline-dev openssl libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev autoconf libc6-dev ncurses-dev automake libtool bison libffi-dev
7
+
8
+ gem install bundler pry
9
+
10
+ su -c 'cd /vagrant && bundle' vagrant
metadata CHANGED
@@ -1,129 +1,141 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-process
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
5
- prerelease:
4
+ version: 1.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Mark Kremer
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-12-06 00:00:00.000000000 Z
11
+ date: 2015-01-14 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: guard
16
- requirement: &15931600 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: 2.0.0
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *15931600
25
- - !ruby/object:Gem::Dependency
26
- name: guard-compat
27
- requirement: &15931120 !ruby/object:Gem::Requirement
28
- none: false
22
+ version_requirements: !ruby/object:Gem::Requirement
29
23
  requirements:
30
- - - ~>
31
- - !ruby/object:Gem::Version
32
- version: '0.1'
33
- - - ! '>='
24
+ - - ">="
34
25
  - !ruby/object:Gem::Version
35
- version: 0.1.1
36
- type: :runtime
37
- prerelease: false
38
- version_requirements: *15931120
26
+ version: 2.0.0
39
27
  - !ruby/object:Gem::Dependency
40
28
  name: spoon
41
- requirement: &15930260 !ruby/object:Gem::Requirement
42
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
43
30
  requirements:
44
- - - ~>
31
+ - - "~>"
45
32
  - !ruby/object:Gem::Version
46
33
  version: 0.0.1
47
34
  type: :runtime
48
35
  prerelease: false
49
- version_requirements: *15930260
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.1
50
41
  - !ruby/object:Gem::Dependency
51
42
  name: minitest
52
- requirement: &15929500 !ruby/object:Gem::Requirement
53
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
54
44
  requirements:
55
- - - ! '>='
45
+ - - ">="
56
46
  - !ruby/object:Gem::Version
57
47
  version: '0'
58
48
  type: :development
59
49
  prerelease: false
60
- version_requirements: *15929500
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
61
55
  - !ruby/object:Gem::Dependency
62
56
  name: mocha
63
- requirement: &15929040 !ruby/object:Gem::Requirement
64
- none: false
57
+ requirement: !ruby/object:Gem::Requirement
65
58
  requirements:
66
- - - ! '>='
59
+ - - ">="
67
60
  - !ruby/object:Gem::Version
68
61
  version: '0'
69
62
  type: :development
70
63
  prerelease: false
71
- version_requirements: *15929040
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
72
69
  - !ruby/object:Gem::Dependency
73
70
  name: guard-minitest
74
- requirement: &15928600 !ruby/object:Gem::Requirement
75
- none: false
71
+ requirement: !ruby/object:Gem::Requirement
76
72
  requirements:
77
- - - ! '>='
73
+ - - ">="
78
74
  - !ruby/object:Gem::Version
79
75
  version: '0'
80
76
  type: :development
81
77
  prerelease: false
82
- version_requirements: *15928600
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: guard-bundler
85
- requirement: &15928120 !ruby/object:Gem::Requirement
86
- none: false
85
+ requirement: !ruby/object:Gem::Requirement
87
86
  requirements:
88
- - - ! '>='
87
+ - - ">="
89
88
  - !ruby/object:Gem::Version
90
89
  version: '0'
91
90
  type: :development
92
91
  prerelease: false
93
- version_requirements: *15928120
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
94
97
  - !ruby/object:Gem::Dependency
95
98
  name: rake
96
- requirement: &15927640 !ruby/object:Gem::Requirement
97
- none: false
99
+ requirement: !ruby/object:Gem::Requirement
98
100
  requirements:
99
- - - ! '>='
101
+ - - ">="
100
102
  - !ruby/object:Gem::Version
101
103
  version: '0'
102
104
  type: :development
103
105
  prerelease: false
104
- version_requirements: *15927640
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
105
111
  - !ruby/object:Gem::Dependency
106
112
  name: rb-inotify
107
- requirement: &15927180 !ruby/object:Gem::Requirement
108
- none: false
113
+ requirement: !ruby/object:Gem::Requirement
109
114
  requirements:
110
- - - ! '>='
115
+ - - ">="
111
116
  - !ruby/object:Gem::Version
112
117
  version: '0'
113
118
  type: :development
114
119
  prerelease: false
115
- version_requirements: *15927180
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
116
125
  - !ruby/object:Gem::Dependency
117
126
  name: pry
118
- requirement: &15926680 !ruby/object:Gem::Requirement
119
- none: false
127
+ requirement: !ruby/object:Gem::Requirement
120
128
  requirements:
121
- - - ! '>='
129
+ - - ">="
122
130
  - !ruby/object:Gem::Version
123
131
  version: '0'
124
132
  type: :development
125
133
  prerelease: false
126
- version_requirements: *15926680
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
127
139
  description: Guard extension to run cli processes
128
140
  email:
129
141
  - mark@without-brains.net
@@ -131,8 +143,8 @@ executables: []
131
143
  extensions: []
132
144
  extra_rdoc_files: []
133
145
  files:
134
- - .gitignore
135
- - .travis.yml
146
+ - ".gitignore"
147
+ - ".travis.yml"
136
148
  - Gemfile
137
149
  - Guardfile
138
150
  - LICENSE
@@ -149,29 +161,25 @@ files:
149
161
  - vagrant-provision
150
162
  homepage: ''
151
163
  licenses: []
164
+ metadata: {}
152
165
  post_install_message:
153
166
  rdoc_options: []
154
167
  require_paths:
155
168
  - lib
156
169
  required_ruby_version: !ruby/object:Gem::Requirement
157
- none: false
158
170
  requirements:
159
- - - ! '>='
171
+ - - ">="
160
172
  - !ruby/object:Gem::Version
161
173
  version: 1.9.3
162
174
  required_rubygems_version: !ruby/object:Gem::Requirement
163
- none: false
164
175
  requirements:
165
- - - ! '>='
176
+ - - ">="
166
177
  - !ruby/object:Gem::Version
167
178
  version: '0'
168
- segments:
169
- - 0
170
- hash: -3112865635849170691
171
179
  requirements: []
172
180
  rubyforge_project:
173
- rubygems_version: 1.8.11
181
+ rubygems_version: 2.4.2
174
182
  signing_key:
175
- specification_version: 3
183
+ specification_version: 4
176
184
  summary: Guard extension to run cli processes
177
185
  test_files: []