dev_commands 0.0.39 → 0.0.40

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7474a5054ce8e1846be673781d0418af177fbe82
4
- data.tar.gz: c05e5655ac9b8bf7c1f5b6fffda3007e517659ba
3
+ metadata.gz: 6b0ae71e6301b33d4c845fea6ce37380f17c8a52
4
+ data.tar.gz: 542e659e0926fa75fddbcde08f0d7da7fcd7e019
5
5
  SHA512:
6
- metadata.gz: 463a0a95113d8d2a41bb244457c5493f340169842d003778005a48efa7dc8efd5b26fd347e07667704259522ff25428f4eec13946de643da14e7cfe166bcffa1
7
- data.tar.gz: 22dea8db2b587cbeb0659de3f2401f7f515d4dd9c9e84d552cc4a6a74eadaaac5c420ef8e6e0f25f59163117e7bb996481ad68c2696da9859c0a4b283e509684
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("ruby --version")
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("ruby --version")
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("rake")
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 "hsould be able to get the output" do
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dev_commands
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.39
4
+ version: 0.0.40
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lou Parslow