subprocess 0.1.6
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.
- data/History.txt +4 -0
- data/Manifest.txt +46 -0
- data/PostInstall.txt +7 -0
- data/README.rdoc +77 -0
- data/Rakefile +20 -0
- data/TODO.rdoc +1 -0
- data/examples/simple.irb +22 -0
- data/examples/simple_timeout.irb +22 -0
- data/features/multiple_popens_sequence.feature +23 -0
- data/features/popen.feature +45 -0
- data/features/popen_over_ssh.feature +44 -0
- data/features/popen_over_ssh_without_blocking.feature +16 -0
- data/features/popen_remote_fails_with_invalid_auth_data.feature +13 -0
- data/features/popen_reports_runtime.feature +11 -0
- data/features/popen_running.feature +11 -0
- data/features/popen_with_timeout.feature +19 -0
- data/features/popen_without_blocking.feature +16 -0
- data/features/step_definitions/common_steps.rb +168 -0
- data/features/step_definitions/multiple_popens_sequence_steps.rb +73 -0
- data/features/step_definitions/popen_over_ssh_steps.rb +29 -0
- data/features/step_definitions/popen_over_ssh_without_blocking_steps.rb +30 -0
- data/features/step_definitions/popen_remote_fails_with_invalid_auth_dat_steps.rb +19 -0
- data/features/step_definitions/popen_reports_runtime_steps.rb +13 -0
- data/features/step_definitions/popen_running_steps.rb +12 -0
- data/features/step_definitions/popen_steps.rb +34 -0
- data/features/step_definitions/popen_with_timeout_steps.rb +24 -0
- data/features/step_definitions/popen_without_blocking_steps.rb +33 -0
- data/features/support/common.rb +29 -0
- data/features/support/env.rb +15 -0
- data/features/support/matchers.rb +11 -0
- data/lib/core_ext/hash.rb +14 -0
- data/lib/core_ext/process_status.rb +14 -0
- data/lib/subprocess/popen.rb +188 -0
- data/lib/subprocess/popen_factory.rb +63 -0
- data/lib/subprocess/popen_remote.rb +64 -0
- data/lib/subprocess/popen_sequence.rb +57 -0
- data/lib/subprocess.rb +23 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/subprocess/popen_spec.rb +32 -0
- data/spec/subprocess_spec.rb +2 -0
- data/subprocess.gemspec +36 -0
- data/tasks/rspec.rake +21 -0
- metadata +138 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
PostInstall.txt
|
4
|
+
README.rdoc
|
5
|
+
Rakefile
|
6
|
+
TODO.rdoc
|
7
|
+
examples/simple.irb
|
8
|
+
examples/simple_timeout.irb
|
9
|
+
features/multiple_popens_sequence.feature
|
10
|
+
features/popen.feature
|
11
|
+
features/popen_over_ssh.feature
|
12
|
+
features/popen_over_ssh_without_blocking.feature
|
13
|
+
features/popen_remote_fails_with_invalid_auth_data.feature
|
14
|
+
features/popen_reports_runtime.feature
|
15
|
+
features/popen_running.feature
|
16
|
+
features/popen_with_timeout.feature
|
17
|
+
features/popen_without_blocking.feature
|
18
|
+
features/step_definitions/common_steps.rb
|
19
|
+
features/step_definitions/multiple_popens_sequence_steps.rb
|
20
|
+
features/step_definitions/popen_over_ssh_steps.rb
|
21
|
+
features/step_definitions/popen_over_ssh_without_blocking_steps.rb
|
22
|
+
features/step_definitions/popen_remote_fails_with_invalid_auth_dat_steps.rb
|
23
|
+
features/step_definitions/popen_reports_runtime_steps.rb
|
24
|
+
features/step_definitions/popen_running_steps.rb
|
25
|
+
features/step_definitions/popen_steps.rb
|
26
|
+
features/step_definitions/popen_with_timeout_steps.rb
|
27
|
+
features/step_definitions/popen_without_blocking_steps.rb
|
28
|
+
features/support/common.rb
|
29
|
+
features/support/env.rb
|
30
|
+
features/support/matchers.rb
|
31
|
+
lib/core_ext/hash.rb
|
32
|
+
lib/core_ext/process_status.rb
|
33
|
+
lib/subprocess.rb
|
34
|
+
lib/subprocess/popen.rb
|
35
|
+
lib/subprocess/popen_factory.rb
|
36
|
+
lib/subprocess/popen_remote.rb
|
37
|
+
lib/subprocess/popen_sequence.rb
|
38
|
+
script/console
|
39
|
+
script/destroy
|
40
|
+
script/generate
|
41
|
+
spec/spec.opts
|
42
|
+
spec/spec_helper.rb
|
43
|
+
spec/subprocess/popen_spec.rb
|
44
|
+
spec/subprocess_spec.rb
|
45
|
+
subprocess.gemspec
|
46
|
+
tasks/rspec.rake
|
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
= subprocess
|
2
|
+
|
3
|
+
* http://github.com/bramswenson/subprocess
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
* Subprocess provides a clean wrapper class around the Kernel.exec method.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* Provides working Subprocess::Popen class used to call system commands in and object oriented manner.
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
=== Simple Popen
|
16
|
+
|
17
|
+
>> require 'subprocess'
|
18
|
+
=> true
|
19
|
+
>>
|
20
|
+
?> # a process to get the current version of ruby from ruby command
|
21
|
+
?> ruby_version = Subprocess::Popen.new('ruby -v')
|
22
|
+
=> #<Subprocess::Popen:0x7f9220bda3a8 @running=false, @command="ruby -v", @timeout=30, @ipc_parsed=false>
|
23
|
+
>>
|
24
|
+
?> # run the process
|
25
|
+
?> ruby_version.run
|
26
|
+
=> true
|
27
|
+
>>
|
28
|
+
?> # wait on process to complete (blocking method)
|
29
|
+
?> ruby_version.wait
|
30
|
+
=> true
|
31
|
+
>>
|
32
|
+
?> # the process will have stdout
|
33
|
+
?> ruby_version.stdout
|
34
|
+
=> "ruby 1.8.7 (2009-06-12 patchlevel 174) [x86_64-linux]"
|
35
|
+
>>
|
36
|
+
?> # and in this case no stderr
|
37
|
+
?> ruby_version.stderr
|
38
|
+
=> ""
|
39
|
+
>>
|
40
|
+
?> # the complete process info is in status
|
41
|
+
?> ruby_version.status
|
42
|
+
=> {:run_time=>0.0611081123352051, :stopsig=>nil, :exited?=>true, :pid=>16744, :termsig=>nil, :timed_out?=>false, :stopped?=>false, :success?=>true, :exitstatus=>0}
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
== REQUIREMENTS:
|
47
|
+
|
48
|
+
tested on ruby 1.8.7
|
49
|
+
|
50
|
+
== INSTALL:
|
51
|
+
|
52
|
+
[sudo] gem install subprocess
|
53
|
+
|
54
|
+
== LICENSE:
|
55
|
+
|
56
|
+
(The MIT License)
|
57
|
+
|
58
|
+
Copyright (c) 2010 Bram Swenson
|
59
|
+
|
60
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
61
|
+
a copy of this software and associated documentation files (the
|
62
|
+
'Software'), to deal in the Software without restriction, including
|
63
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
64
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
65
|
+
permit persons to whom the Software is furnished to do so, subject to
|
66
|
+
the following conditions:
|
67
|
+
|
68
|
+
The above copyright notice and this permission notice shall be
|
69
|
+
included in all copies or substantial portions of the Software.
|
70
|
+
|
71
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
72
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
73
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
74
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
75
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
76
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
77
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'hoe', '>= 2.1.0'
|
3
|
+
#gem 'rspec', '<= 1.3.0'
|
4
|
+
require 'hoe'
|
5
|
+
require 'fileutils'
|
6
|
+
require './lib/subprocess'
|
7
|
+
|
8
|
+
Hoe.plugin :newgem
|
9
|
+
# Hoe.plugin :website
|
10
|
+
Hoe.plugin :cucumberfeatures
|
11
|
+
|
12
|
+
$hoe = Hoe.spec 'subprocess' do
|
13
|
+
self.developer 'Bram Swenson', 'bram@craniumisajar.com'
|
14
|
+
end
|
15
|
+
|
16
|
+
require 'newgem/tasks'
|
17
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
18
|
+
|
19
|
+
remove_task :default
|
20
|
+
task :default => [:spec, :features]
|
data/TODO.rdoc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
* make sure rails config.gem 'subprocess' works
|
data/examples/simple.irb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env irb
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'subprocess'
|
5
|
+
rescue LoadError
|
6
|
+
require 'rubygems'
|
7
|
+
require 'subprocess'
|
8
|
+
end
|
9
|
+
|
10
|
+
# a process to get the current version of ruby from ruby command
|
11
|
+
ruby_version = Subprocess::Popen.new('ruby -v')
|
12
|
+
# run the process
|
13
|
+
ruby_version.run
|
14
|
+
# wait on process to complete (blocking method)
|
15
|
+
ruby_version.wait
|
16
|
+
# the process will have stdout
|
17
|
+
ruby_version.stdout
|
18
|
+
# and in this case no stderr
|
19
|
+
ruby_version.stderr
|
20
|
+
# the complete process info is in status
|
21
|
+
ruby_version.status
|
22
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env irb
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'subprocess'
|
5
|
+
rescue LoadError
|
6
|
+
require 'rubygems'
|
7
|
+
require 'subprocess'
|
8
|
+
end
|
9
|
+
|
10
|
+
# a process to get the current version of ruby from ruby command
|
11
|
+
ruby_version = Subprocess::Popen.new('ruby -v')
|
12
|
+
# run the process
|
13
|
+
ruby_version.run
|
14
|
+
# wait on process to complete (blocking method)
|
15
|
+
ruby_version.wait
|
16
|
+
# the process will have stdout
|
17
|
+
ruby_version.stdout
|
18
|
+
# and in this case no stderr
|
19
|
+
ruby_version.stderr
|
20
|
+
# the complete process info is in status
|
21
|
+
ruby_version.status
|
22
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Feature: Run a sequence of simple subprocesses in order
|
2
|
+
|
3
|
+
As a ruby hacker
|
4
|
+
I want to run a sequence of system subprocesses in a sequential order
|
5
|
+
So I can run complex sequences of commands in a simple way
|
6
|
+
|
7
|
+
Scenario: run a sequence of 2 sequential subprocess successfully
|
8
|
+
Given I have a subprocess sequence with 2 subprocesses to run
|
9
|
+
When I run the subprocesses sequence
|
10
|
+
Then the subprocess sequence completes with success
|
11
|
+
And the subprocess sequence has stdout for each subprocess
|
12
|
+
And the subprocess sequence has stderr for each subprocess
|
13
|
+
And the subprocess sequence has status for each subprocess
|
14
|
+
|
15
|
+
Scenario: run a sequence of 2 sequential subprocess where the first fails
|
16
|
+
Given I have a subprocess sequence with 2 subprocesses to run with a bad one first
|
17
|
+
When I run the subprocesses sequence
|
18
|
+
Then the subprocess sequence completes with failure
|
19
|
+
|
20
|
+
Scenario: run a sequence of sequences
|
21
|
+
Given I have a subprocess sequence with 2 subprocesses sequences
|
22
|
+
When I run the sequence
|
23
|
+
Then the sequences run just like any other subprocess
|
@@ -0,0 +1,45 @@
|
|
1
|
+
Feature: Run simple subprocesses in ruby
|
2
|
+
|
3
|
+
As a ruby hacker
|
4
|
+
I want to run system subprocesses
|
5
|
+
And I want to have them presented as objects
|
6
|
+
So that I can get more data about said subprocesses
|
7
|
+
And so that I can have more fine grained control of said subprocesses
|
8
|
+
|
9
|
+
Scenario Outline: run simple subprocesses
|
10
|
+
Given I have a new Subprocess instance initialized with "<command>"
|
11
|
+
When I invoke the run method of said subprocess
|
12
|
+
And I invoke the wait method of said subprocess
|
13
|
+
Then the instance should have a status attribute
|
14
|
+
And the instances exit status is "<exitstatus>"
|
15
|
+
And the instances stdout matches "<stdout>"
|
16
|
+
And the instances stderr matches "<stderr>"
|
17
|
+
And the instance should have a numerical pid
|
18
|
+
|
19
|
+
Scenarios: zero exit code subprocesses with stdout
|
20
|
+
| command | exitstatus | stdout | stderr |
|
21
|
+
| echo 1 | 0 | 1 | |
|
22
|
+
|
23
|
+
Scenarios: zero exit code subprocesses with stderr
|
24
|
+
| command | exitstatus | stdout | stderr |
|
25
|
+
| echo 1 1>&2 | 0 | | 1 |
|
26
|
+
|
27
|
+
Scenarios: zero exit code subprocesses with stdout and stderr
|
28
|
+
| command | exitstatus | stdout | stderr |
|
29
|
+
| echo 1 && echo 1 1>&2 | 0 | 1 | 1 |
|
30
|
+
|
31
|
+
Scenarios: nonzero exit code subprocesses with stdout
|
32
|
+
| command | exitstatus | stdout | stderr |
|
33
|
+
| echo 1 && exit 1 | 1 | 1 | |
|
34
|
+
| echo 1 && exit 2 | 2 | 1 | |
|
35
|
+
| echo 1 && exit 99 | 99 | 1 | |
|
36
|
+
|
37
|
+
Scenarios: nonzero exit code subprocesses with stderr
|
38
|
+
| command | exitstatus | stdout | stderr |
|
39
|
+
| echo 1 1>&2 && exit 1 | 1 | | 1 |
|
40
|
+
|
41
|
+
Scenarios: nonzero exit code subprocesses with stdout and stderr
|
42
|
+
| command | exitstatus | stdout | stderr |
|
43
|
+
| echo 1 && echo 1 1>&2 && exit 1 | 1 | 1 | 1 |
|
44
|
+
|
45
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
Feature: Run simple remote subprocesses over ssh in ruby
|
2
|
+
|
3
|
+
As a ruby hacker
|
4
|
+
I want to run remote system subprocesses over ssh
|
5
|
+
And I want to have them presented as objects
|
6
|
+
So that I can get more data about said subprocesses
|
7
|
+
And so that I can have more fine grained control of said subprocesses
|
8
|
+
|
9
|
+
Scenario Outline: run simple remote subprocesses
|
10
|
+
Given I have a new remote Subprocess instance initialized with "<command>"
|
11
|
+
When I invoke the run method of said remote subprocess
|
12
|
+
And I invoke the wait method of said remote subprocess
|
13
|
+
Then the remote instances exit status is "<exitstatus>"
|
14
|
+
And the remote instances stdout matches "<stdout>"
|
15
|
+
And the remote instances stderr matches "<stderr>"
|
16
|
+
And the remote instance should have a numerical pid
|
17
|
+
|
18
|
+
Scenarios: zero exit code remote subprocesses with stdout
|
19
|
+
| command | exitstatus | stdout | stderr |
|
20
|
+
| echo 1 | 0 | 1 | |
|
21
|
+
|
22
|
+
Scenarios: zero exit code remote subprocesses with stderr
|
23
|
+
| command | exitstatus | stdout | stderr |
|
24
|
+
| echo 1 1>&2 | 0 | | 1 |
|
25
|
+
|
26
|
+
Scenarios: zero exit code remote subprocesses with stdout and stderr
|
27
|
+
| command | exitstatus | stdout | stderr |
|
28
|
+
| echo 1 && echo 1 1>&2 | 0 | 1 | 1 |
|
29
|
+
|
30
|
+
Scenarios: nonzero exit code remote subprocesses with stdout
|
31
|
+
| command | exitstatus | stdout | stderr |
|
32
|
+
| echo 1 && exit 1 | 1 | 1 | |
|
33
|
+
| echo 1 && exit 2 | 2 | 1 | |
|
34
|
+
| echo 1 && exit 99 | 99 | 1 | |
|
35
|
+
|
36
|
+
Scenarios: nonzero exit code remote subprocesses with stderr
|
37
|
+
| command | exitstatus | stdout | stderr |
|
38
|
+
| echo 1 1>&2 && exit 1 | 1 | | 1 |
|
39
|
+
|
40
|
+
Scenarios: nonzero exit code remote subprocesses with stdout and stderr
|
41
|
+
| command | exitstatus | stdout | stderr |
|
42
|
+
| echo 1 && echo 1 1>&2 && exit 1 | 1 | 1 | 1 |
|
43
|
+
|
44
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Feature: Run simple remote subprocesses without blocking and over ssh in ruby
|
2
|
+
|
3
|
+
As a ruby hacker
|
4
|
+
I want to run remote system subprocesses that do not block over ssh
|
5
|
+
And I want to have them presented as objects
|
6
|
+
So that I can get more data about said subprocesses
|
7
|
+
And so that I can have more fine grained control of said subprocesses
|
8
|
+
|
9
|
+
Scenario: run simple remote nonblocking subprocess
|
10
|
+
Given I have a new remote nonblocking subprocess that takes a long time to run
|
11
|
+
When I invoke the run method of said nonblocking remote subprocess
|
12
|
+
Then the remote nonblocking subprocess should not block
|
13
|
+
And the remote nonblocking subprocess should report its run status
|
14
|
+
And the remote nonblocking subprocess should support being waited on till complete
|
15
|
+
And the remote nonblocking subprocess should have status info
|
16
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Feature: Run simple remote subprocesses that has bad auth data
|
2
|
+
|
3
|
+
As a ruby hacker
|
4
|
+
I want to run system remote subprocesses that require auth data
|
5
|
+
So they can be secure
|
6
|
+
And actually remote :)
|
7
|
+
|
8
|
+
Scenario: run simple remote subprocess with bad auth data
|
9
|
+
Given I have a new remote subproces with invalid username
|
10
|
+
And invalid password
|
11
|
+
When I run the remote subprocess
|
12
|
+
Then the remote subprocess should return an error
|
13
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Feature: Run simple subprocesses that report run time
|
2
|
+
|
3
|
+
As a ruby hacker
|
4
|
+
I want to run system subprocesses that report their run time
|
5
|
+
So that I know how long it took to run
|
6
|
+
|
7
|
+
Scenario: run simple subprocess that takes 3 seconds
|
8
|
+
Given I have a new subprocess that takes 3 seconds
|
9
|
+
When I wait on said 3 second process to complete
|
10
|
+
Then the subprocess should report a run time of around 3 seconds
|
11
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Feature: Run simple subprocesses that report running
|
2
|
+
|
3
|
+
As a ruby hacker
|
4
|
+
I want to run system subprocesses that report their running status
|
5
|
+
So that I know when said subprocess is finished without waiting
|
6
|
+
|
7
|
+
Scenario: run simple subprocess that finishes fast
|
8
|
+
Given I have a new subprocess that runs fast
|
9
|
+
When I invoke the run method of said fast subprocess
|
10
|
+
Then the subprocess should report running as false without waiting
|
11
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Feature: Run simple subprocesses stopping them at timeout if not complete
|
2
|
+
|
3
|
+
As a ruby hacker
|
4
|
+
I want to run system subprocesses
|
5
|
+
And I want them to terminate by a set timeout
|
6
|
+
So that I don't end up with a bunch of zombies
|
7
|
+
|
8
|
+
Scenario: run simple subprocess that goes past timeout
|
9
|
+
Given I have a new subprocess that takes more than 5 seconds to run
|
10
|
+
And I set a timeout of 5 seconds
|
11
|
+
When I invoke the run method of said subprocess with timeout
|
12
|
+
Then the subprocess should exit with exitcode 1
|
13
|
+
|
14
|
+
Scenario: run simple subprocess that does not go past timeout
|
15
|
+
Given I have a new subprocess that takes less than 5 seconds to run
|
16
|
+
And I set a timeout of 5 seconds
|
17
|
+
When I invoke the run method of said subprocess with timeout
|
18
|
+
Then the subprocess should complete fine
|
19
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Feature: Run simple subprocesses without blocking in ruby
|
2
|
+
|
3
|
+
As a ruby hacker
|
4
|
+
I want to run system subprocesses that do not block
|
5
|
+
And I want to have them presented as objects
|
6
|
+
So that I can get more data about said subprocesses
|
7
|
+
And so that I can have more fine grained control of said subprocesses
|
8
|
+
|
9
|
+
Scenario: run simple subprocess without blocking
|
10
|
+
Given I have a new subprocess that takes a long time to run
|
11
|
+
When I invoke the run method of said nonblocking subprocess
|
12
|
+
Then the subprocess should not block
|
13
|
+
And the subprocess should report its run status
|
14
|
+
And the subprocess should support being waited on till complete
|
15
|
+
And the subprocess should have status info
|
16
|
+
|
@@ -0,0 +1,168 @@
|
|
1
|
+
Given /^this project is active project folder/ do
|
2
|
+
@active_project_folder = File.expand_path(File.dirname(__FILE__) + "/../..")
|
3
|
+
end
|
4
|
+
|
5
|
+
Given /^env variable \$([\w_]+) set to "(.*)"/ do |env_var, value|
|
6
|
+
ENV[env_var] = value
|
7
|
+
end
|
8
|
+
|
9
|
+
Given /"(.*)" folder is deleted/ do |folder|
|
10
|
+
in_project_folder { FileUtils.rm_rf folder }
|
11
|
+
end
|
12
|
+
|
13
|
+
When /^I invoke "(.*)" generator with arguments "(.*)"$/ do |generator, arguments|
|
14
|
+
@stdout = StringIO.new
|
15
|
+
in_project_folder do
|
16
|
+
if Object.const_defined?("APP_ROOT")
|
17
|
+
APP_ROOT.replace(FileUtils.pwd)
|
18
|
+
else
|
19
|
+
APP_ROOT = FileUtils.pwd
|
20
|
+
end
|
21
|
+
run_generator(generator, arguments.split(' '), SOURCES, :stdout => @stdout)
|
22
|
+
end
|
23
|
+
File.open(File.join(@tmp_root, "generator.out"), "w") do |f|
|
24
|
+
@stdout.rewind
|
25
|
+
f << @stdout.read
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
When /^I run executable "(.*)" with arguments "(.*)"/ do |executable, arguments|
|
30
|
+
@stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
|
31
|
+
in_project_folder do
|
32
|
+
system "#{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
When /^I run project executable "(.*)" with arguments "(.*)"/ do |executable, arguments|
|
37
|
+
@stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
|
38
|
+
in_project_folder do
|
39
|
+
system "ruby #{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
When /^I run local executable "(.*)" with arguments "(.*)"/ do |executable, arguments|
|
44
|
+
@stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
|
45
|
+
executable = File.expand_path(File.join(File.dirname(__FILE__), "/../../bin", executable))
|
46
|
+
in_project_folder do
|
47
|
+
system "ruby #{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
When /^I invoke task "rake (.*)"/ do |task|
|
52
|
+
@stdout = File.expand_path(File.join(@tmp_root, "tests.out"))
|
53
|
+
in_project_folder do
|
54
|
+
system "rake #{task} --trace > #{@stdout} 2> #{@stdout}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
Then /^folder "(.*)" (is|is not) created/ do |folder, is|
|
59
|
+
in_project_folder do
|
60
|
+
File.exists?(folder).should(is == 'is' ? be_true : be_false)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
Then /^file "(.*)" (is|is not) created/ do |file, is|
|
65
|
+
in_project_folder do
|
66
|
+
File.exists?(file).should(is == 'is' ? be_true : be_false)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
Then /^file with name matching "(.*)" is created/ do |pattern|
|
71
|
+
in_project_folder do
|
72
|
+
Dir[pattern].should_not be_empty
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
Then /^file "(.*)" contents (does|does not) match \/(.*)\// do |file, does, regex|
|
77
|
+
in_project_folder do
|
78
|
+
actual_output = File.read(file)
|
79
|
+
(does == 'does') ?
|
80
|
+
actual_output.should(match(/#{regex}/)) :
|
81
|
+
actual_output.should_not(match(/#{regex}/))
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
Then /gem file "(.*)" and generated file "(.*)" should be the same/ do |gem_file, project_file|
|
86
|
+
File.exists?(gem_file).should be_true
|
87
|
+
File.exists?(project_file).should be_true
|
88
|
+
gem_file_contents = File.read(File.dirname(__FILE__) + "/../../#{gem_file}")
|
89
|
+
project_file_contents = File.read(File.join(@active_project_folder, project_file))
|
90
|
+
project_file_contents.should == gem_file_contents
|
91
|
+
end
|
92
|
+
|
93
|
+
Then /^(does|does not) invoke generator "(.*)"$/ do |does_invoke, generator|
|
94
|
+
actual_output = File.read(@stdout)
|
95
|
+
does_invoke == "does" ?
|
96
|
+
actual_output.should(match(/dependency\s+#{generator}/)) :
|
97
|
+
actual_output.should_not(match(/dependency\s+#{generator}/))
|
98
|
+
end
|
99
|
+
|
100
|
+
Then /help options "(.*)" and "(.*)" are displayed/ do |opt1, opt2|
|
101
|
+
actual_output = File.read(@stdout)
|
102
|
+
actual_output.should match(/#{opt1}/)
|
103
|
+
actual_output.should match(/#{opt2}/)
|
104
|
+
end
|
105
|
+
|
106
|
+
Then /^I should see "([^\"]*)"$/ do |text|
|
107
|
+
actual_output = File.read(@stdout)
|
108
|
+
actual_output.should contain(text)
|
109
|
+
end
|
110
|
+
|
111
|
+
Then /^I should see$/ do |text|
|
112
|
+
actual_output = File.read(@stdout)
|
113
|
+
actual_output.should contain(text)
|
114
|
+
end
|
115
|
+
|
116
|
+
Then /^I should not see$/ do |text|
|
117
|
+
actual_output = File.read(@stdout)
|
118
|
+
actual_output.should_not contain(text)
|
119
|
+
end
|
120
|
+
|
121
|
+
Then /^I should see exactly$/ do |text|
|
122
|
+
actual_output = File.read(@stdout)
|
123
|
+
actual_output.should == text
|
124
|
+
end
|
125
|
+
|
126
|
+
Then /^I should see all (\d+) tests pass/ do |expected_test_count|
|
127
|
+
expected = %r{^#{expected_test_count} tests, \d+ assertions, 0 failures, 0 errors}
|
128
|
+
actual_output = File.read(@stdout)
|
129
|
+
actual_output.should match(expected)
|
130
|
+
end
|
131
|
+
|
132
|
+
Then /^I should see all (\d+) examples pass/ do |expected_test_count|
|
133
|
+
expected = %r{^#{expected_test_count} examples?, 0 failures}
|
134
|
+
actual_output = File.read(@stdout)
|
135
|
+
actual_output.should match(expected)
|
136
|
+
end
|
137
|
+
|
138
|
+
Then /^yaml file "(.*)" contains (\{.*\})/ do |file, yaml|
|
139
|
+
in_project_folder do
|
140
|
+
yaml = eval yaml
|
141
|
+
YAML.load(File.read(file)).should == yaml
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
Then /^Rakefile can display tasks successfully/ do
|
146
|
+
@stdout = File.expand_path(File.join(@tmp_root, "rakefile.out"))
|
147
|
+
in_project_folder do
|
148
|
+
system "rake -T > #{@stdout} 2> #{@stdout}"
|
149
|
+
end
|
150
|
+
actual_output = File.read(@stdout)
|
151
|
+
actual_output.should match(/^rake\s+\w+\s+#\s.*/)
|
152
|
+
end
|
153
|
+
|
154
|
+
Then /^task "rake (.*)" is executed successfully/ do |task|
|
155
|
+
@stdout.should_not be_nil
|
156
|
+
actual_output = File.read(@stdout)
|
157
|
+
actual_output.should_not match(/^Don't know how to build task '#{task}'/)
|
158
|
+
actual_output.should_not match(/Error/i)
|
159
|
+
end
|
160
|
+
|
161
|
+
Then /^gem spec key "(.*)" contains \/(.*)\// do |key, regex|
|
162
|
+
in_project_folder do
|
163
|
+
gem_file = Dir["pkg/*.gem"].first
|
164
|
+
gem_spec = Gem::Specification.from_yaml(`gem spec #{gem_file}`)
|
165
|
+
spec_value = gem_spec.send(key.to_sym)
|
166
|
+
spec_value.to_s.should match(/#{regex}/)
|
167
|
+
end
|
168
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
Given /^I have a subprocess sequence with 2 subprocesses to run$/ do
|
2
|
+
@seq = Subprocess::PopenSequence.new
|
3
|
+
@seq.add_popen(Subprocess::Popen.new('echo "popen 1"'))
|
4
|
+
@seq.add_popen(Subprocess::Popen.new('echo "popen 2"'))
|
5
|
+
end
|
6
|
+
|
7
|
+
When /^I run the subprocesses sequence$/ do
|
8
|
+
@seq.perform
|
9
|
+
end
|
10
|
+
|
11
|
+
Then /^the subprocess sequence completes with success$/ do
|
12
|
+
@seq.status[:exitstatus].should == 0
|
13
|
+
@seq.completed?.should be_true
|
14
|
+
@seq.complete.length.should == 2
|
15
|
+
@seq.incomplete.length.should == 0
|
16
|
+
@seq.failed.length.should == 0
|
17
|
+
end
|
18
|
+
|
19
|
+
Then /^the subprocess sequence has stdout for each subprocess$/ do
|
20
|
+
@seq.complete.each do |popen|
|
21
|
+
popen.stdout.should_not == ""
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
Then /^the subprocess sequence has stderr for each subprocess$/ do
|
26
|
+
@seq.complete.each do |popen|
|
27
|
+
popen.stderr.should == ""
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Then /^the subprocess sequence has status for each subprocess$/ do
|
32
|
+
@seq.complete.each do |popen|
|
33
|
+
popen.status.should be_kind_of Hash
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
Given /^I have a subprocess sequence with 2 subprocesses to run with a bad one first$/ do
|
38
|
+
@seq = Subprocess::PopenSequence.new
|
39
|
+
@seq.add_popen(Subprocess::Popen.new('exit 1'))
|
40
|
+
@seq.add_popen(Subprocess::Popen.new('echo "popen 2"'))
|
41
|
+
end
|
42
|
+
|
43
|
+
Then /^the subprocess sequence completes with failure$/ do
|
44
|
+
@seq.incomplete.length.should == 1
|
45
|
+
@seq.failed.length.should == 1
|
46
|
+
@seq.complete.length.should == 0
|
47
|
+
@seq.status[:exitstatus].should_not == 0
|
48
|
+
end
|
49
|
+
|
50
|
+
Given /^I have a subprocess sequence with 2 subprocesses sequences$/ do
|
51
|
+
seq1 = Subprocess::PopenSequence.new
|
52
|
+
seq1 << Subprocess::Popen.new('echo "seq 1 - popen 1"')
|
53
|
+
seq1 << Subprocess::Popen.new('echo "seq 1 - popen 2"')
|
54
|
+
seq2 = Subprocess::PopenSequence.new
|
55
|
+
seq2 << Subprocess::Popen.new('echo "seq 2 - popen 1"')
|
56
|
+
seq2 << Subprocess::Popen.new('echo "seq 2 - popen 2"')
|
57
|
+
@seq = Subprocess::PopenSequence.new
|
58
|
+
@seq << seq1
|
59
|
+
@seq << seq2
|
60
|
+
end
|
61
|
+
|
62
|
+
When /^I run the sequence$/ do
|
63
|
+
@seq.perform
|
64
|
+
end
|
65
|
+
|
66
|
+
Then /^the sequences run just like any other subprocess$/ do
|
67
|
+
@seq.status[:exitstatus].should == 0
|
68
|
+
@seq.completed?.should be_true
|
69
|
+
@seq.complete.length.should == 2
|
70
|
+
@seq.incomplete.length.should == 0
|
71
|
+
@seq.failed.length.should == 0
|
72
|
+
end
|
73
|
+
|