guard-process 1.0.6 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
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.2
7
- - 1.9.3
8
- - 2.0.0
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,76 +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.2, 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
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.0.6
52
-
53
- - Allow passing in command as an Array as well as a String
54
-
55
- ## 1.0.5
56
-
57
- - Adds the dont_stop option
58
-
59
- ## 1.0.4
60
-
61
- - Adds the dir option
62
-
63
- # Development
64
- - Source hosted on [GitHub](https://github.com)
65
- - Please report issues and feature requests using [GitHub issues](https://github.com/guard/guard-process/issues)
66
-
67
- Pull requests are welcome, please make sure your patches are well tested before contributing. When sending a pull request:
68
- - Use a topic branch for your change
69
- - Add tests for your changes using MiniTest::Unit
70
- - Do not change the version number in the gemspec
71
-
72
- # License
73
- Guard::Process is released under the MIT license.
74
-
75
- # Author
76
- [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,30 +1,31 @@
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.0.6"
8
- s.authors = ["Mark Kremer"]
9
- s.email = ["mark@socialreferral.com"]
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.2'
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', '>= 0.4.2')
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
+ # -*- 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,85 +1,84 @@
1
- require 'guard'
2
- require 'guard/guard'
3
- require 'spoon'
4
-
5
- module Guard
6
- class Process < Guard
7
- def initialize(watchers = [], 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
+ 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,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,6 +1,10 @@
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
+ 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,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,144 +1,132 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-process
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.1.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Mark Kremer
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-08-31 00:00:00.000000000 Z
12
+ date: 2014-12-06 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: guard
15
- requirement: !ruby/object:Gem::Requirement
16
+ requirement: &15931600 !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - '>='
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
- version: 0.4.2
21
+ version: 2.0.0
20
22
  type: :runtime
21
23
  prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '>='
25
- - !ruby/object:Gem::Version
26
- version: 0.4.2
24
+ version_requirements: *15931600
27
25
  - !ruby/object:Gem::Dependency
28
- name: spoon
29
- requirement: !ruby/object:Gem::Requirement
26
+ name: guard-compat
27
+ requirement: &15931120 !ruby/object:Gem::Requirement
28
+ none: false
30
29
  requirements:
31
30
  - - ~>
32
31
  - !ruby/object:Gem::Version
33
- version: 0.0.1
32
+ version: '0.1'
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: 0.1.1
34
36
  type: :runtime
35
37
  prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
38
+ version_requirements: *15931120
39
+ - !ruby/object:Gem::Dependency
40
+ name: spoon
41
+ requirement: &15930260 !ruby/object:Gem::Requirement
42
+ none: false
37
43
  requirements:
38
44
  - - ~>
39
45
  - !ruby/object:Gem::Version
40
46
  version: 0.0.1
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: *15930260
41
50
  - !ruby/object:Gem::Dependency
42
51
  name: minitest
43
- requirement: !ruby/object:Gem::Requirement
52
+ requirement: &15929500 !ruby/object:Gem::Requirement
53
+ none: false
44
54
  requirements:
45
- - - '>='
55
+ - - ! '>='
46
56
  - !ruby/object:Gem::Version
47
57
  version: '0'
48
58
  type: :development
49
59
  prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
60
+ version_requirements: *15929500
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: mocha
57
- requirement: !ruby/object:Gem::Requirement
63
+ requirement: &15929040 !ruby/object:Gem::Requirement
64
+ none: false
58
65
  requirements:
59
- - - '>='
66
+ - - ! '>='
60
67
  - !ruby/object:Gem::Version
61
68
  version: '0'
62
69
  type: :development
63
70
  prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - '>='
67
- - !ruby/object:Gem::Version
68
- version: '0'
71
+ version_requirements: *15929040
69
72
  - !ruby/object:Gem::Dependency
70
73
  name: guard-minitest
71
- requirement: !ruby/object:Gem::Requirement
74
+ requirement: &15928600 !ruby/object:Gem::Requirement
75
+ none: false
72
76
  requirements:
73
- - - '>='
77
+ - - ! '>='
74
78
  - !ruby/object:Gem::Version
75
79
  version: '0'
76
80
  type: :development
77
81
  prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - '>='
81
- - !ruby/object:Gem::Version
82
- version: '0'
82
+ version_requirements: *15928600
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: guard-bundler
85
- requirement: !ruby/object:Gem::Requirement
85
+ requirement: &15928120 !ruby/object:Gem::Requirement
86
+ none: false
86
87
  requirements:
87
- - - '>='
88
+ - - ! '>='
88
89
  - !ruby/object:Gem::Version
89
90
  version: '0'
90
91
  type: :development
91
92
  prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - '>='
95
- - !ruby/object:Gem::Version
96
- version: '0'
93
+ version_requirements: *15928120
97
94
  - !ruby/object:Gem::Dependency
98
95
  name: rake
99
- requirement: !ruby/object:Gem::Requirement
96
+ requirement: &15927640 !ruby/object:Gem::Requirement
97
+ none: false
100
98
  requirements:
101
- - - '>='
99
+ - - ! '>='
102
100
  - !ruby/object:Gem::Version
103
101
  version: '0'
104
102
  type: :development
105
103
  prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - '>='
109
- - !ruby/object:Gem::Version
110
- version: '0'
104
+ version_requirements: *15927640
111
105
  - !ruby/object:Gem::Dependency
112
106
  name: rb-inotify
113
- requirement: !ruby/object:Gem::Requirement
107
+ requirement: &15927180 !ruby/object:Gem::Requirement
108
+ none: false
114
109
  requirements:
115
- - - '>='
110
+ - - ! '>='
116
111
  - !ruby/object:Gem::Version
117
112
  version: '0'
118
113
  type: :development
119
114
  prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - '>='
123
- - !ruby/object:Gem::Version
124
- version: '0'
115
+ version_requirements: *15927180
125
116
  - !ruby/object:Gem::Dependency
126
117
  name: pry
127
- requirement: !ruby/object:Gem::Requirement
118
+ requirement: &15926680 !ruby/object:Gem::Requirement
119
+ none: false
128
120
  requirements:
129
- - - '>='
121
+ - - ! '>='
130
122
  - !ruby/object:Gem::Version
131
123
  version: '0'
132
124
  type: :development
133
125
  prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - '>='
137
- - !ruby/object:Gem::Version
138
- version: '0'
126
+ version_requirements: *15926680
139
127
  description: Guard extension to run cli processes
140
128
  email:
141
- - mark@socialreferral.com
129
+ - mark@without-brains.net
142
130
  executables: []
143
131
  extensions: []
144
132
  extra_rdoc_files: []
@@ -161,25 +149,29 @@ files:
161
149
  - vagrant-provision
162
150
  homepage: ''
163
151
  licenses: []
164
- metadata: {}
165
152
  post_install_message:
166
153
  rdoc_options: []
167
154
  require_paths:
168
155
  - lib
169
156
  required_ruby_version: !ruby/object:Gem::Requirement
157
+ none: false
170
158
  requirements:
171
- - - '>='
159
+ - - ! '>='
172
160
  - !ruby/object:Gem::Version
173
- version: 1.9.2
161
+ version: 1.9.3
174
162
  required_rubygems_version: !ruby/object:Gem::Requirement
163
+ none: false
175
164
  requirements:
176
- - - '>='
165
+ - - ! '>='
177
166
  - !ruby/object:Gem::Version
178
167
  version: '0'
168
+ segments:
169
+ - 0
170
+ hash: -3112865635849170691
179
171
  requirements: []
180
172
  rubyforge_project:
181
- rubygems_version: 2.0.0
173
+ rubygems_version: 1.8.11
182
174
  signing_key:
183
- specification_version: 4
175
+ specification_version: 3
184
176
  summary: Guard extension to run cli processes
185
177
  test_files: []
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 71f3ef6034e8422847c017d3ab4d57541f9abec0
4
- data.tar.gz: 62ba22f6dae41b0c8a42d24e8604f67587b39c76
5
- SHA512:
6
- metadata.gz: ccde9ba1a1381c736c3215c2e22589ae911ca87718522be3ffbe4f0670eecbc9f9e6da90f5277b6427720da36ff4a1edfc11d4fea0503798bda730c63cdb2d52
7
- data.tar.gz: 25d7266ffc963377bad5441cc551cf98c0f2bc8874351d3b2012417b0b4a3d9db134fbca5afcabeb8de8392181f4422d8e5013e0072db5b03fd0c3075121db0f