dev_commands 0.0.39 → 0.0.40
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/array.rb +6 -1
- data/lib/command.rb +5 -1
- data/lib/hash.rb +2 -2
- data/spec/command_spec.rb +26 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b0ae71e6301b33d4c845fea6ce37380f17c8a52
|
4
|
+
data.tar.gz: 542e659e0926fa75fddbcde08f0d7da7fcd7e019
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bc5e4fac606037686c6cfc7e8bf49058ad64f2e73d37f2bb0bcd07f7211d2e7eaf0a1a9dda205d5e08ae1452f72045c15affc94648bbea293169079930282ee
|
7
|
+
data.tar.gz: 4c6f3584e5347f6ddd92c601a3e84445a18269549f46114f5b0b216d57da2ae833a51cf8a5e22384172fd27b7c53a618db2ae74a81b958ae73318c9edf883491
|
data/lib/array.rb
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
class Array
|
2
|
-
def execute
|
2
|
+
def execute value=nil
|
3
3
|
i=0
|
4
4
|
while i < self.length
|
5
5
|
self[i]=Command.new(self[i]) if(self[i].is_a?(String))
|
6
6
|
self[i]=Command.new(self[i]) if(self[i].is_a?(Hash) && !self[i].is_a?(Command))
|
7
|
+
|
8
|
+
if(!value.nil? && value.is_a?(Hash))
|
9
|
+
value.each{|k,v|self[i][k]=v}
|
10
|
+
end
|
11
|
+
|
7
12
|
self[i].execute if(self[i].is_a?(Command))
|
8
13
|
i=i+1
|
9
14
|
end
|
data/lib/command.rb
CHANGED
@@ -35,7 +35,11 @@ class Command < Hash
|
|
35
35
|
(self.has_key?(:quiet) && self[:quiet])
|
36
36
|
end
|
37
37
|
|
38
|
-
def execute
|
38
|
+
def execute value=nil
|
39
|
+
|
40
|
+
if(!value.nil? && value.is_a?(Hash))
|
41
|
+
value.each{|k,v|self[k]=v}
|
42
|
+
end
|
39
43
|
pwd=Dir.pwd
|
40
44
|
Dir.chdir(self[:directory]) if(self.has_key?(:directory) && File.exists?(self[:directory]))
|
41
45
|
self[:directory] = pwd if(self[:directory].length==0)
|
data/lib/hash.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Hash
|
2
|
-
def execute
|
2
|
+
def execute value=nil
|
3
3
|
self.each{|k,v|
|
4
4
|
v.update if v.respond_to?(:update)
|
5
5
|
if(v.is_a?(Array) && v.length==0)
|
@@ -7,7 +7,7 @@ class Hash
|
|
7
7
|
else
|
8
8
|
#puts "executing #{k}"
|
9
9
|
|
10
|
-
v.execute if v.respond_to?(:execute)
|
10
|
+
v.execute(value) if v.respond_to?(:execute)
|
11
11
|
end
|
12
12
|
}
|
13
13
|
end
|
data/spec/command_spec.rb
CHANGED
@@ -4,7 +4,7 @@ require 'fileutils'
|
|
4
4
|
|
5
5
|
describe Command do
|
6
6
|
it "should be able to execute ruby --version command" do
|
7
|
-
cmd=Command.new(
|
7
|
+
cmd=Command.new({ :input => 'ruby --version', :quiet => true})
|
8
8
|
# Timeout
|
9
9
|
expect(cmd[:timeout]).to eq(0)
|
10
10
|
cmd[:timeout]=3000
|
@@ -58,7 +58,7 @@ describe Command do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should be able to write to/load from JSON" do
|
61
|
-
cmd=Command.new(
|
61
|
+
cmd=Command.new({ :input => 'ruby --version', :quiet => true})
|
62
62
|
expect(cmd[:timeout]).to eq(0)
|
63
63
|
expect(cmd[:input]).to eq("ruby --version")
|
64
64
|
cmd2=Command.new(JSON.parse(cmd.to_json))
|
@@ -80,16 +80,36 @@ describe Command do
|
|
80
80
|
f.puts " puts 'rake_test'"
|
81
81
|
f.puts "end"
|
82
82
|
}
|
83
|
-
cmd=Command.new(
|
83
|
+
cmd=Command.new({ :input => 'rake', :quiet => true})
|
84
84
|
cmd[:directory]=dir
|
85
85
|
cmd.execute
|
86
86
|
FileUtils.rm_r("#{File.dirname(__FILE__)}/tmp")
|
87
87
|
expect(cmd[:output].include?('rake_test')).to eq(true)
|
88
88
|
end
|
89
89
|
|
90
|
+
it "should fail when calling rake produces an error" do
|
91
|
+
dir="#{File.dirname(__FILE__)}/tmp/rake_error_test"
|
92
|
+
FileUtils.mkdir_p(dir) if(!File.exists?(dir))
|
93
|
+
File.open("#{dir}/rakefile.rb","w") { |f|
|
94
|
+
f.puts "task :default do"
|
95
|
+
f.puts " raise 'rake_test'"
|
96
|
+
f.puts "end"
|
97
|
+
}
|
98
|
+
cmd=Command.new({ :input => 'rake', :ignore_failure => true, :quiet => true})
|
99
|
+
cmd[:directory]=dir
|
100
|
+
cmd.execute({:quiet => true})
|
101
|
+
FileUtils.rm_r("#{File.dirname(__FILE__)}/tmp")
|
102
|
+
expect(cmd[:exit_code]).not_to eq(0)
|
103
|
+
|
104
|
+
cmd=Command.new({ :input => 'rake bogus', :ignore_failure => true, :quiet => true})
|
105
|
+
cmd[:directory]=dir
|
106
|
+
cmd.execute
|
107
|
+
expect(cmd[:exit_code]).not_to eq(0)
|
108
|
+
end
|
109
|
+
|
90
110
|
it "should be able to execute an array of commands" do
|
91
111
|
help=['git --help','rake --help','ruby --help']
|
92
|
-
help.execute
|
112
|
+
help.execute({:quiet => true})
|
93
113
|
File.open('help.html','w'){|f|f.write(help.to_html)}
|
94
114
|
end
|
95
115
|
|
@@ -97,11 +117,11 @@ describe Command do
|
|
97
117
|
commands=Hash.new
|
98
118
|
commands[:help]=['git --help','rake --help','ruby --help']
|
99
119
|
commands[:version]=['git --version','rake --version','ruby --version']
|
100
|
-
commands.execute
|
120
|
+
commands.execute({:quiet => true})
|
101
121
|
File.open('commands.html','w'){|f|f.write(commands.to_html)}
|
102
122
|
end
|
103
123
|
|
104
|
-
it "
|
124
|
+
it "should be able to get the output" do
|
105
125
|
expect(Command.output('git --version').include?('git version')).to eq(true)
|
106
126
|
expect(Command.output('bogus --version').include?('bogus version')).to eq(false)
|
107
127
|
end
|