dev_commands 0.0.22 → 0.0.23

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0ba796e5048a64e2b520720283850e771417af10
4
+ data.tar.gz: 24ca4fd01762a1a48f6df4ec6bb7332d6ebd2488
5
+ SHA512:
6
+ metadata.gz: 81af5cce3f8f0141004467a78b25eb5b155889c34c2ebf46890812fd90c614926d27553ff5f355f3c29e44d9d45ced3163e8163f15cde478a016f8651e91e946
7
+ data.tar.gz: 820419d439ccac4fb9f44750bca31ac7478add38942f993c103b6d9b0ed5fa9a0c0294e4363d6936d4b2c686d096c8a0fdfc38f4db5eed70461e687445e39ec0
data/lib/array.rb CHANGED
@@ -1,25 +1,25 @@
1
- class Array
2
- def execute
3
- i=0
4
- while i < self.length
5
- self[i]=Command.new(self[i]) if(self[i].is_a?(String))
6
- self[i]=Command.new(self[i]) if(self[i].is_a?(Hash) && !self[i].is_a?(Command))
7
- self[i].execute if(self[i].is_a?(Command))
8
- i=i+1
9
- end
10
- end
11
-
12
- def add command
13
- self << command if(!include?(command))
14
- end
15
-
16
- def to_html
17
- html=Array.new
18
- html << '<div>'
19
- self.each{|e|
20
- html << e.to_html if e.respond_to?(:to_html)
21
- }
22
- html << '</div>'
23
- html.join
24
- end
1
+ class Array
2
+ def execute
3
+ i=0
4
+ while i < self.length
5
+ self[i]=Command.new(self[i]) if(self[i].is_a?(String))
6
+ self[i]=Command.new(self[i]) if(self[i].is_a?(Hash) && !self[i].is_a?(Command))
7
+ self[i].execute if(self[i].is_a?(Command))
8
+ i=i+1
9
+ end
10
+ end
11
+
12
+ def add command
13
+ self << command if(!include?(command))
14
+ end
15
+
16
+ def to_html
17
+ html=Array.new
18
+ html << '<div>'
19
+ self.each{|e|
20
+ html << e.to_html if e.respond_to?(:to_html)
21
+ }
22
+ html << '</div>'
23
+ html.join
24
+ end
25
25
  end
data/lib/command.rb CHANGED
@@ -1,129 +1,129 @@
1
- require 'open3'
2
- require_relative('./array.rb')
3
- require_relative('./hash.rb')
4
- require_relative('./timer.rb')
5
-
6
- class Command < Hash
7
- def initialize command
8
-
9
- self[:input] = ''
10
- self[:timeout] = 0
11
- self[:directory] = ''
12
- self[:exit_code] = 0
13
- self[:output] = ''
14
- self[:error] = ''
15
- self[:machine] = ''
16
- self[:user] = ''
17
- self[:start_time] = nil
18
- self[:end_time] = nil
19
-
20
- if(command.kind_of?(String))
21
- self[:input] = command
22
- end
23
-
24
- if(command.kind_of?(Hash))
25
- command.each{|k,v|
26
- self[k.to_sym]=v
27
- }
28
- end
29
- end
30
-
31
- def execute
32
- puts "#{self[:input]}"
33
- pwd=Dir.pwd
34
- Dir.chdir(self[:directory]) if(self.has_key?(:directory) && File.exists?(self[:directory]))
35
- self[:directory] = pwd if(self[:directory].length==0)
36
-
37
- self[:machine] = Command.machine
38
- self[:user] = Command.user
39
-
40
- self[:start_time]=Time.now
41
- timer=Timer.new
42
- if self[:input].include?('<%') && self[:input].include?('%>')
43
- ruby = self[:input].gsub("<%","").gsub("%>","")
44
-
45
- begin
46
- self[:output]=eval(ruby)
47
- rescue
48
- self[:exit_code]=1
49
- self[:error]="unable to eval(#{ruby})"
50
- end
51
-
52
- self[:elapsed] = timer.elapsed_str
53
- self[:end_time] = Time.now
54
- else
55
- begin
56
- self[:output],self[:error],status= Open3.capture3(self[:input])
57
- self[:exit_code]=status.to_i
58
- self[:elapsed] = timer.elapsed_str
59
- self[:end_time] = Time.now
60
- rescue Exception => e
61
- self[:elapsed] = timer.elapsed_str
62
- self[:end_time] = Time.now
63
- self[:error] = "Exception: " + e.to_s
64
- self[:exit_code]=1
65
- end
66
- end
67
-
68
- Dir.chdir(pwd) if pwd != Dir.pwd
69
-
70
- if(self[:exit_code] != 0)
71
- puts ' '
72
- puts "exit_code=#{self[:exit_code]}"
73
- puts ' '
74
- puts self[:output]
75
- puts self[:error]
76
- puts ' '
77
- if(!self.has_key?(:ignore_failure) || !self[:ignore_failure])
78
- raise "#{self[:input]} failed"
79
- end #unless (self.has_key?(:ignore_failure) && self[:ignore_failure]==true)
80
- end
81
- end
82
-
83
- def self.machine
84
- if !ENV['COMPUTERNAME'].nil?
85
- return ENV['COMPUTERNAME']
86
- end
87
-
88
- machine = `hostname`
89
- machine = machine.split('.')[0] if machine.include?('.')
90
- return machine.strip
91
- end
92
-
93
- def self.user
94
- ENV['USER'].nil? ? ENV['USERNAME'] : ENV['USER']
95
- end
96
-
97
- def self.exit_code command
98
- cmd = Command.new(command)
99
- cmd[:ignore_failure]=true
100
- cmd.execute
101
- cmd[:exit_code]
102
- end
103
-
104
- def self.output command
105
- cmd = Command.new(command)
106
- cmd[:ignore_failure]=true
107
- cmd.execute
108
- cmd[:output]
109
- end
110
-
111
- def to_html
112
- if self[:exit_code] == 0
113
- [
114
- '<div><table><tr><td width="20"></td><td><pre>',
115
- self[:input],
116
- '</pre></td></tr></table></div>'
117
- ].join
118
- else
119
- [
120
- '<div><table><tr><td width="20"></td><td><pre>',
121
- self[:input],
122
- '</pre><table><tr><td width="20"></td><td><table>',
123
- map { |k, v| ["<tr><td><strong>#{k}</strong></td>", v.respond_to?(:to_html) ? v.to_html : "<td><span><pre>#{v}</pre></span></td></tr>"] },
124
- '</table>',
125
- '</td></tr></table></td></tr></table></div>'
126
- ].join
127
- end
128
- end
1
+ require 'open3'
2
+ require_relative('./array.rb')
3
+ require_relative('./hash.rb')
4
+ require_relative('./timer.rb')
5
+
6
+ class Command < Hash
7
+ def initialize command
8
+
9
+ self[:input] = ''
10
+ self[:timeout] = 0
11
+ self[:directory] = ''
12
+ self[:exit_code] = 0
13
+ self[:output] = ''
14
+ self[:error] = ''
15
+ self[:machine] = ''
16
+ self[:user] = ''
17
+ self[:start_time] = nil
18
+ self[:end_time] = nil
19
+
20
+ if(command.kind_of?(String))
21
+ self[:input] = command
22
+ end
23
+
24
+ if(command.kind_of?(Hash))
25
+ command.each{|k,v|
26
+ self[k.to_sym]=v
27
+ }
28
+ end
29
+ end
30
+
31
+ def execute
32
+ puts "#{self[:input]}"
33
+ pwd=Dir.pwd
34
+ Dir.chdir(self[:directory]) if(self.has_key?(:directory) && File.exists?(self[:directory]))
35
+ self[:directory] = pwd if(self[:directory].length==0)
36
+
37
+ self[:machine] = Command.machine
38
+ self[:user] = Command.user
39
+
40
+ self[:start_time]=Time.now
41
+ timer=Timer.new
42
+ if self[:input].include?('<%') && self[:input].include?('%>')
43
+ ruby = self[:input].gsub("<%","").gsub("%>","")
44
+
45
+ begin
46
+ self[:output]=eval(ruby)
47
+ rescue
48
+ self[:exit_code]=1
49
+ self[:error]="unable to eval(#{ruby})"
50
+ end
51
+
52
+ self[:elapsed] = timer.elapsed_str
53
+ self[:end_time] = Time.now
54
+ else
55
+ begin
56
+ self[:output],self[:error],status= Open3.capture3(self[:input])
57
+ self[:exit_code]=status.to_i
58
+ self[:elapsed] = timer.elapsed_str
59
+ self[:end_time] = Time.now
60
+ rescue Exception => e
61
+ self[:elapsed] = timer.elapsed_str
62
+ self[:end_time] = Time.now
63
+ self[:error] = "Exception: " + e.to_s
64
+ self[:exit_code]=1
65
+ end
66
+ end
67
+
68
+ Dir.chdir(pwd) if pwd != Dir.pwd
69
+
70
+ if(self[:exit_code] != 0)
71
+ puts ' '
72
+ puts "exit_code=#{self[:exit_code]}"
73
+ puts ' '
74
+ puts self[:output]
75
+ puts self[:error]
76
+ puts ' '
77
+ if(!self.has_key?(:ignore_failure) || !self[:ignore_failure])
78
+ raise "#{self[:input]} failed"
79
+ end #unless (self.has_key?(:ignore_failure) && self[:ignore_failure]==true)
80
+ end
81
+ end
82
+
83
+ def self.machine
84
+ if !ENV['COMPUTERNAME'].nil?
85
+ return ENV['COMPUTERNAME']
86
+ end
87
+
88
+ machine = `hostname`
89
+ machine = machine.split('.')[0] if machine.include?('.')
90
+ return machine.strip
91
+ end
92
+
93
+ def self.user
94
+ ENV['USER'].nil? ? ENV['USERNAME'] : ENV['USER']
95
+ end
96
+
97
+ def self.exit_code command
98
+ cmd = Command.new(command)
99
+ cmd[:ignore_failure]=true
100
+ cmd.execute
101
+ cmd[:exit_code]
102
+ end
103
+
104
+ def self.output command
105
+ cmd = Command.new(command)
106
+ cmd[:ignore_failure]=true
107
+ cmd.execute
108
+ cmd[:output]
109
+ end
110
+
111
+ def to_html
112
+ if self[:exit_code] == 0
113
+ [
114
+ '<div><table><tr><td width="20"></td><td><pre>',
115
+ self[:input],
116
+ '</pre></td></tr></table></div>'
117
+ ].join
118
+ else
119
+ [
120
+ '<div><table><tr><td width="20"></td><td><pre>',
121
+ self[:input],
122
+ '</pre><table><tr><td width="20"></td><td><table>',
123
+ map { |k, v| ["<tr><td><strong>#{k}</strong></td>", v.respond_to?(:to_html) ? v.to_html : "<td><span><pre>#{v}</pre></span></td></tr>"] },
124
+ '</table>',
125
+ '</td></tr></table></td></tr></table></div>'
126
+ ].join
127
+ end
128
+ end
129
129
  end
data/lib/doc.rb CHANGED
@@ -1,9 +1,9 @@
1
- class Doc < Array
2
- def update
3
- #cmd=Command.new ({ :input => 'yard --version', :ignore_failure => true})
4
- #cmd.execute
5
- if(Command.exit_code('yard --version'))
6
- add 'yard doc - LICENSE' if File.exists?('README.md') && File.exists?('LICENSE')
7
- end
8
- end
1
+ class Doc < Array
2
+ def update
3
+ #cmd=Command.new ({ :input => 'yard --version', :ignore_failure => true})
4
+ #cmd.execute
5
+ if(Command.exit_code('yard --version'))
6
+ add 'yard doc - LICENSE' if File.exists?('README.md') && File.exists?('LICENSE')
7
+ end
8
+ end
9
9
  end
data/lib/gemspec.rb CHANGED
@@ -1,36 +1,36 @@
1
- class Gemspec
2
- def self.update gemspec_file
3
- Text.replace_in_file gemspec_file,
4
- /('\d{4}-\d{2}-\d{2}')/,
5
- "'#{Time.now.strftime('%Y-%m-%d')}'"
6
- end
7
-
8
- def self.gemfile gemspec_file
9
- spec=Gem::Specification.load(gemspec_file)
10
- return "#{spec.name}-#{spec.version}.gem"
11
- end
12
-
13
- def self.version gemspec_file
14
- spec=Gem::Specification.load(gemspec_file)
15
- return spec.version.to_s
16
- end
17
-
18
- def self.published_version gemspec_file
19
- published_version=''
20
- spec=Gem::Specification.load(gemspec_file)
21
- begin
22
- published_version = `gem list #{spec.name} -r`.scan(/\((\d+.\d+.\d+)\)/)[0][0]
23
- rescue
24
- published_version=''
25
- end
26
- published_version
27
- end
28
- def self.published? gemspec_file
29
- published_version(gemspec_file)==version(gemspec_file) ? true : false
30
- end
31
-
32
- def self.normalize gemspec_file
33
- spec=Gem::Specification.load(gemspec_file)
34
- File.open(gemspec_file,'w'){|f|f.write(spec.to_ruby)}
35
- end
1
+ class Gemspec
2
+ def self.update gemspec_file
3
+ Text.replace_in_file gemspec_file,
4
+ /('\d{4}-\d{2}-\d{2}')/,
5
+ "'#{Time.now.strftime('%Y-%m-%d')}'"
6
+ end
7
+
8
+ def self.gemfile gemspec_file
9
+ spec=Gem::Specification.load(gemspec_file)
10
+ return "#{spec.name}-#{spec.version}.gem"
11
+ end
12
+
13
+ def self.version gemspec_file
14
+ spec=Gem::Specification.load(gemspec_file)
15
+ return spec.version.to_s
16
+ end
17
+
18
+ def self.published_version gemspec_file
19
+ published_version=''
20
+ spec=Gem::Specification.load(gemspec_file)
21
+ begin
22
+ published_version = `gem list #{spec.name} -r`.scan(/\((\d+.\d+.\d+)\)/)[0][0]
23
+ rescue
24
+ published_version=''
25
+ end
26
+ published_version
27
+ end
28
+ def self.published? gemspec_file
29
+ published_version(gemspec_file)==version(gemspec_file) ? true : false
30
+ end
31
+
32
+ def self.normalize gemspec_file
33
+ spec=Gem::Specification.load(gemspec_file)
34
+ File.open(gemspec_file,'w'){|f|f.write(spec.to_ruby)}
35
+ end
36
36
  end
data/lib/git.rb CHANGED
@@ -1,9 +1,9 @@
1
- class Git
2
- def self.branch
3
- begin
4
- `git branch`.scan(/\* ([.\w-]+)/)[0][0]
5
- rescue
6
- ''
7
- end
8
- end
1
+ class Git
2
+ def self.branch
3
+ begin
4
+ `git branch`.scan(/\* ([.\w-]+)/)[0][0]
5
+ rescue
6
+ ''
7
+ end
8
+ end
9
9
  end
data/lib/hash.rb CHANGED
@@ -1,21 +1,21 @@
1
- class Hash
2
- def execute
3
- self.each{|k,v|
4
- v.update if v.respond_to?(:update)
5
- if(v.is_a?(Array) && v.length==0)
6
- self.delete k
7
- else
8
- #puts "executing #{k}"
9
-
10
- v.execute if v.respond_to?(:execute)
11
- end
12
- }
13
- end
14
- def to_html
15
- [
16
- '<div>',
17
- map { |k, v| ["<br/><div><strong>#{k}</strong>", v.respond_to?(:to_html) ? v.to_html : "<span>#{v}</span></div><br/>"] },
18
- '</div>'
19
- ].join
20
- end
1
+ class Hash
2
+ def execute
3
+ self.each{|k,v|
4
+ v.update if v.respond_to?(:update)
5
+ if(v.is_a?(Array) && v.length==0)
6
+ self.delete k
7
+ else
8
+ #puts "executing #{k}"
9
+
10
+ v.execute if v.respond_to?(:execute)
11
+ end
12
+ }
13
+ end
14
+ def to_html
15
+ [
16
+ '<div>',
17
+ map { |k, v| ["<br/><div><strong>#{k}</strong>", v.respond_to?(:to_html) ? v.to_html : "<span>#{v}</span></div><br/>"] },
18
+ '</div>'
19
+ ].join
20
+ end
21
21
  end
data/lib/publish.rb CHANGED
@@ -1,7 +1,7 @@
1
- class Publish < Array
2
- def update
3
- Dir.glob('*.gemspec').each{|gemspec_file|
4
- add "gem push #{Gemspec.gemfile(gemspec_file)}" if !Gemspec.published? gemspec_file
5
- }
6
- end
1
+ class Publish < Array
2
+ def update
3
+ Dir.glob('*.gemspec').each{|gemspec_file|
4
+ add "gem push #{Gemspec.gemfile(gemspec_file)}" if !Gemspec.published? gemspec_file
5
+ }
6
+ end
7
7
  end
data/lib/push.rb CHANGED
@@ -1,8 +1,8 @@
1
- class Push < Array
2
- def update
3
- if(File.exists?('.git') && `git config --list`.include?('user.name='))
4
- add 'git config --global push.default simple'
5
- self << 'git push' if Git.branch != 'develop'
6
- end
7
- end
1
+ class Push < Array
2
+ def update
3
+ if(File.exists?('.git') && `git config --list`.include?('user.name='))
4
+ add 'git config --global push.default simple'
5
+ self << 'git push' if Git.branch != 'develop'
6
+ end
7
+ end
8
8
  end
data/lib/setup.rb CHANGED
@@ -1,9 +1,9 @@
1
- class Setup < Array
2
- def update
3
- add 'bundle install' if(File.exists?('Gemfile'))
4
-
5
- Dir.glob('*.gemspec').each{|gemspec_file|
6
- add "<%Gemspec.update('#{gemspec_file}')%>"
7
- }
8
- end
1
+ class Setup < Array
2
+ def update
3
+ add 'bundle install' if(File.exists?('Gemfile'))
4
+
5
+ Dir.glob('*.gemspec').each{|gemspec_file|
6
+ add "<%Gemspec.update('#{gemspec_file}')%>"
7
+ }
8
+ end
9
9
  end
data/lib/test.rb CHANGED
@@ -1,5 +1,5 @@
1
- class Test < Array
2
- def update
3
- add 'rspec' if File.exists?('spec')
4
- end
1
+ class Test < Array
2
+ def update
3
+ add 'rspec' if File.exists?('spec')
4
+ end
5
5
  end
data/lib/text.rb CHANGED
@@ -1,15 +1,15 @@
1
- class Text
2
- def self.replace_in_glob(glob,search,replace)
3
- Dir.glob(glob).each{ |f| replace_text_in_file(f,search,replace) }
4
- end
5
-
6
- def self.replace_in_file(filename,search,replace)
7
- text1 = IO.read(filename).force_encoding("ISO-8859-1").encode("utf-8", replace: nil)
8
- #File.read(f,:encoding=>'UTF-8')
9
- text2 = text1.gsub(search) { |str| str=replace }
10
- unless text1==text2
11
- File.open(filename,"w") { |f| f.puts text2 }
12
- end
13
- end
14
-
1
+ class Text
2
+ def self.replace_in_glob(glob,search,replace)
3
+ Dir.glob(glob).each{ |f| replace_text_in_file(f,search,replace) }
4
+ end
5
+
6
+ def self.replace_in_file(filename,search,replace)
7
+ text1 = IO.read(filename).force_encoding("ISO-8859-1").encode("utf-8", replace: nil)
8
+ #File.read(f,:encoding=>'UTF-8')
9
+ text2 = text1.gsub(search) { |str| str=replace }
10
+ unless text1==text2
11
+ File.open(filename,"w") { |f| f.puts text2 }
12
+ end
13
+ end
14
+
15
15
  end
@@ -1,41 +1,41 @@
1
- class Timer
2
- attr_accessor :start_time
3
-
4
- def initialize
5
- @start_time=Time.now
6
- end
7
-
8
- def elapsed # in seconds
9
- return Time.now-@start_time
10
- end
11
-
12
- def elapsed_str
13
- elapsed_str="[" + "%.0f" %(elapsed) + "s]"
14
- end
15
-
16
- def self.elapsed_exceeds?(name,duration_seconds)
17
- if(Timer.get_elapsed(name).nil? || Timer.get_elapsed(name) > duration_seconds)
18
- return true
19
- end
20
- return false
21
- end
22
-
23
- def self.get_elapsed(name)
24
- timestamp=get_timestamp(name)
25
- return Time.now-timestamp if(!timestamp.nil?)
26
- nil
27
- end
28
-
29
- def self.get_timestamp(name)
30
- dir=Rake.application.original_dir
31
- if(File.exists?("#{DEV[:dev_root]}/log/#{name}.timestamp"))
32
- return Time.parse(File.read("#{DEV[:dev_root]}/log/#{name}.timestamp").strip)
33
- end
34
- nil
35
- end
36
-
37
- def self.set_timestamp(name)
38
- Dir.mkdir("#{DEV_TASKS[:dev_root]}/log") if(!Dir.exists?("#{DEV_TASKS[:dev_root]}/log"))
39
- File.open("#{DEV_TASKS[:dev_root]}/log/#{name}.timestamp",'w'){|f|f.puts(Time.now.to_s)}
40
- end
1
+ class Timer
2
+ attr_accessor :start_time
3
+
4
+ def initialize
5
+ @start_time=Time.now
6
+ end
7
+
8
+ def elapsed # in seconds
9
+ return Time.now-@start_time
10
+ end
11
+
12
+ def elapsed_str
13
+ elapsed_str="[" + "%.0f" %(elapsed) + "s]"
14
+ end
15
+
16
+ def self.elapsed_exceeds?(name,duration_seconds)
17
+ if(Timer.get_elapsed(name).nil? || Timer.get_elapsed(name) > duration_seconds)
18
+ return true
19
+ end
20
+ return false
21
+ end
22
+
23
+ def self.get_elapsed(name)
24
+ timestamp=get_timestamp(name)
25
+ return Time.now-timestamp if(!timestamp.nil?)
26
+ nil
27
+ end
28
+
29
+ def self.get_timestamp(name)
30
+ dir=Rake.application.original_dir
31
+ if(File.exists?("#{DEV[:dev_root]}/log/#{name}.timestamp"))
32
+ return Time.parse(File.read("#{DEV[:dev_root]}/log/#{name}.timestamp").strip)
33
+ end
34
+ nil
35
+ end
36
+
37
+ def self.set_timestamp(name)
38
+ Dir.mkdir("#{DEV_TASKS[:dev_root]}/log") if(!Dir.exists?("#{DEV_TASKS[:dev_root]}/log"))
39
+ File.open("#{DEV_TASKS[:dev_root]}/log/#{name}.timestamp",'w'){|f|f.puts(Time.now.to_s)}
40
+ end
41
41
  end
data/spec/command_spec.rb CHANGED
@@ -1,110 +1,110 @@
1
- require_relative '../lib/command.rb'
2
- require 'json'
3
- require 'fileutils'
4
-
5
- describe Command do
6
- it "should be able to execute ruby --version command" do
7
- cmd=Command.new("ruby --version")
8
- # Timeout
9
- expect(cmd[:timeout]).to eq(0)
10
- cmd[:timeout]=3000
11
- expect(cmd[:timeout]).to eq(3000)
12
-
13
- # Directory
14
- expect(cmd[:directory]).to eq("")
15
- cmd[:directory] = File.dirname(__FILE__)
16
- expect(cmd[:directory]).to eq(File.dirname(__FILE__))
17
-
18
- # ExitCode
19
- expect(cmd[:exit_code]).to eq(0)
20
- cmd[:exit_code] = 1
21
- expect(cmd[:exit_code]).to eq(1)
22
-
23
- # Input
24
- expect(cmd[:input]).to eq("ruby --version")
25
- cmd2 = Command.new('')
26
- expect(cmd2[:input]).to eq('')
27
-
28
- # Output
29
- expect(cmd[:output]).to eq('')
30
- cmd[:output]='test'
31
- expect(cmd[:output]).to eq('test')
32
-
33
- # Error
34
- expect(cmd[:error]).to eq('')
35
- cmd[:error]='error_test'
36
- expect(cmd[:error]).to eq('error_test')
37
-
38
- # Machine
39
- expect(cmd[:machine]).to eq('')
40
- cmd[:machine]='machine_test'
41
- expect(cmd[:machine]).to eq('machine_test')
42
-
43
- # User
44
- expect(cmd[:user]).to eq('')
45
- cmd[:user]='user_test'
46
- expect(cmd[:user]).to eq('user_test')
47
-
48
- # StartTime
49
- expect(cmd[:start_time]).to eq(nil)
50
- cmd[:start_time]=Time.now
51
- expect(cmd[:start_time]).not_to eq(nil)
52
-
53
- # EndTime
54
- expect(cmd[:end_time]).to eq(nil)
55
- cmd[:end_time]=Time.now
56
- expect(cmd[:end_time]).not_to eq(nil)
57
-
58
- end
59
-
60
- it "should be able to write to/load from JSON" do
61
- cmd=Command.new("ruby --version")
62
- expect(cmd[:timeout]).to eq(0)
63
- expect(cmd[:input]).to eq("ruby --version")
64
- cmd2=Command.new(JSON.parse(cmd.to_json))
65
- expect(cmd2[:timeout]).to eq(0)
66
- expect(cmd2[:input]).to eq("ruby --version")
67
- end
68
-
69
- it "should be able to execute rake command in specific directory" do
70
- dir="#{File.dirname(__FILE__)}/tmp/rake_test"
71
- FileUtils.mkdir_p(dir) if(!File.exists?(dir))
72
- File.open("#{dir}/rakefile.rb","w") { |f|
73
- f.puts "task :default do"
74
- f.puts " puts 'rake_test'"
75
- f.puts "end"
76
- }
77
- cmd=Command.new("rake")
78
- cmd[:directory]=dir
79
- cmd.execute
80
- FileUtils.rm_r("#{File.dirname(__FILE__)}/tmp")
81
- expect(cmd[:output].include?('rake_test')).to eq(true)
82
- end
83
-
84
- it "should be able to execute an array of commands" do
85
- help=['git --help','rake --help','ruby --help']
86
- help.execute
87
- File.open('help.html','w'){|f|f.write(help.to_html)}
88
- end
89
-
90
- it "should be able to execute a hash with arrays or commands" do
91
- commands=Hash.new
92
- commands[:help]=['git --help','rake --help','ruby --help']
93
- commands[:version]=['git --version','rake --version','ruby --version']
94
- commands.execute
95
- File.open('commands.html','w'){|f|f.write(commands.to_html)}
96
- end
97
-
98
- it "hsould be able to get the output" do
99
- expect(Command.output('git --version').include?('git version')).to eq(true)
100
- expect(Command.output('bogus --version').include?('bogus version')).to eq(false)
101
- end
102
-
103
- it "should be able to get the exit_code" do
104
- expect(Command.exit_code('rake --version')).to eq(0)
105
- expect(Command.exit_code('bogus --version')).not_to eq(0)
106
- end
107
- #it "should fail this test" do
108
- # expect(false).to eq(true)
109
- #end
1
+ require_relative '../lib/command.rb'
2
+ require 'json'
3
+ require 'fileutils'
4
+
5
+ describe Command do
6
+ it "should be able to execute ruby --version command" do
7
+ cmd=Command.new("ruby --version")
8
+ # Timeout
9
+ expect(cmd[:timeout]).to eq(0)
10
+ cmd[:timeout]=3000
11
+ expect(cmd[:timeout]).to eq(3000)
12
+
13
+ # Directory
14
+ expect(cmd[:directory]).to eq("")
15
+ cmd[:directory] = File.dirname(__FILE__)
16
+ expect(cmd[:directory]).to eq(File.dirname(__FILE__))
17
+
18
+ # ExitCode
19
+ expect(cmd[:exit_code]).to eq(0)
20
+ cmd[:exit_code] = 1
21
+ expect(cmd[:exit_code]).to eq(1)
22
+
23
+ # Input
24
+ expect(cmd[:input]).to eq("ruby --version")
25
+ cmd2 = Command.new('')
26
+ expect(cmd2[:input]).to eq('')
27
+
28
+ # Output
29
+ expect(cmd[:output]).to eq('')
30
+ cmd[:output]='test'
31
+ expect(cmd[:output]).to eq('test')
32
+
33
+ # Error
34
+ expect(cmd[:error]).to eq('')
35
+ cmd[:error]='error_test'
36
+ expect(cmd[:error]).to eq('error_test')
37
+
38
+ # Machine
39
+ expect(cmd[:machine]).to eq('')
40
+ cmd[:machine]='machine_test'
41
+ expect(cmd[:machine]).to eq('machine_test')
42
+
43
+ # User
44
+ expect(cmd[:user]).to eq('')
45
+ cmd[:user]='user_test'
46
+ expect(cmd[:user]).to eq('user_test')
47
+
48
+ # StartTime
49
+ expect(cmd[:start_time]).to eq(nil)
50
+ cmd[:start_time]=Time.now
51
+ expect(cmd[:start_time]).not_to eq(nil)
52
+
53
+ # EndTime
54
+ expect(cmd[:end_time]).to eq(nil)
55
+ cmd[:end_time]=Time.now
56
+ expect(cmd[:end_time]).not_to eq(nil)
57
+
58
+ end
59
+
60
+ it "should be able to write to/load from JSON" do
61
+ cmd=Command.new("ruby --version")
62
+ expect(cmd[:timeout]).to eq(0)
63
+ expect(cmd[:input]).to eq("ruby --version")
64
+ cmd2=Command.new(JSON.parse(cmd.to_json))
65
+ expect(cmd2[:timeout]).to eq(0)
66
+ expect(cmd2[:input]).to eq("ruby --version")
67
+ end
68
+
69
+ it "should be able to execute rake command in specific directory" do
70
+ dir="#{File.dirname(__FILE__)}/tmp/rake_test"
71
+ FileUtils.mkdir_p(dir) if(!File.exists?(dir))
72
+ File.open("#{dir}/rakefile.rb","w") { |f|
73
+ f.puts "task :default do"
74
+ f.puts " puts 'rake_test'"
75
+ f.puts "end"
76
+ }
77
+ cmd=Command.new("rake")
78
+ cmd[:directory]=dir
79
+ cmd.execute
80
+ FileUtils.rm_r("#{File.dirname(__FILE__)}/tmp")
81
+ expect(cmd[:output].include?('rake_test')).to eq(true)
82
+ end
83
+
84
+ it "should be able to execute an array of commands" do
85
+ help=['git --help','rake --help','ruby --help']
86
+ help.execute
87
+ File.open('help.html','w'){|f|f.write(help.to_html)}
88
+ end
89
+
90
+ it "should be able to execute a hash with arrays or commands" do
91
+ commands=Hash.new
92
+ commands[:help]=['git --help','rake --help','ruby --help']
93
+ commands[:version]=['git --version','rake --version','ruby --version']
94
+ commands.execute
95
+ File.open('commands.html','w'){|f|f.write(commands.to_html)}
96
+ end
97
+
98
+ it "hsould be able to get the output" do
99
+ expect(Command.output('git --version').include?('git version')).to eq(true)
100
+ expect(Command.output('bogus --version').include?('bogus version')).to eq(false)
101
+ end
102
+
103
+ it "should be able to get the exit_code" do
104
+ expect(Command.exit_code('rake --version')).to eq(0)
105
+ expect(Command.exit_code('bogus --version')).not_to eq(0)
106
+ end
107
+ #it "should fail this test" do
108
+ # expect(false).to eq(true)
109
+ #end
110
110
  end
data/spec/text_spec.rb CHANGED
@@ -1,12 +1,12 @@
1
- require_relative '../lib/text.rb'
2
-
3
- describe Text do
4
- it "should be able to replace text in file" do
5
- FileUtils.mkdir('tmp') if(!File.exists?('tmp'))
6
- File.open('tmp/test.txt','w'){|f|
7
- f.write("test thing")
8
- }
9
- Text.replace_in_file('tmp/test.txt','thing','string')
10
- expect(IO.read('tmp/test.txt').include?('test string')).to eq(true)
11
- end
1
+ require_relative '../lib/text.rb'
2
+
3
+ describe Text do
4
+ it "should be able to replace text in file" do
5
+ FileUtils.mkdir('tmp') if(!File.exists?('tmp'))
6
+ File.open('tmp/test.txt','w'){|f|
7
+ f.write("test thing")
8
+ }
9
+ Text.replace_in_file('tmp/test.txt','thing','string')
10
+ expect(IO.read('tmp/test.txt').include?('test string')).to eq(true)
11
+ end
12
12
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dev_commands
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.22
5
- prerelease:
4
+ version: 0.0.23
6
5
  platform: ruby
7
6
  authors:
8
7
  - Lou Parslow
@@ -14,161 +13,113 @@ dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
- - !ruby/object:Gem::Dependency
47
- name: json
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
- type: :runtime
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
38
+ - - '>='
60
39
  - !ruby/object:Gem::Version
61
40
  version: '0'
62
41
  - !ruby/object:Gem::Dependency
63
42
  name: yard
64
43
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
44
  requirements:
67
- - - ! '>='
45
+ - - '>='
68
46
  - !ruby/object:Gem::Version
69
47
  version: '0'
70
48
  type: :runtime
71
49
  prerelease: false
72
50
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
51
  requirements:
75
- - - ! '>='
52
+ - - '>='
76
53
  - !ruby/object:Gem::Version
77
54
  version: '0'
78
55
  - !ruby/object:Gem::Dependency
79
56
  name: bundler
80
57
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
58
  requirements:
83
- - - ! '>='
59
+ - - '>='
84
60
  - !ruby/object:Gem::Version
85
61
  version: '0'
86
62
  type: :runtime
87
63
  prerelease: false
88
64
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
65
  requirements:
91
- - - ! '>='
66
+ - - '>='
92
67
  - !ruby/object:Gem::Version
93
68
  version: '0'
94
69
  - !ruby/object:Gem::Dependency
95
70
  name: rake
96
71
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
72
  requirements:
99
- - - ! '>='
73
+ - - '>='
100
74
  - !ruby/object:Gem::Version
101
75
  version: '0'
102
76
  type: :development
103
77
  prerelease: false
104
78
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
79
  requirements:
107
- - - ! '>='
80
+ - - '>='
108
81
  - !ruby/object:Gem::Version
109
82
  version: '0'
110
83
  - !ruby/object:Gem::Dependency
111
84
  name: rspec
112
85
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
- requirements:
115
- - - ! '>='
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
- requirements:
123
- - - ! '>='
124
- - !ruby/object:Gem::Version
125
- version: '0'
126
- - !ruby/object:Gem::Dependency
127
- name: json
128
- requirement: !ruby/object:Gem::Requirement
129
- none: false
130
86
  requirements:
131
- - - ! '>='
87
+ - - '>='
132
88
  - !ruby/object:Gem::Version
133
89
  version: '0'
134
90
  type: :development
135
91
  prerelease: false
136
92
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
93
  requirements:
139
- - - ! '>='
94
+ - - '>='
140
95
  - !ruby/object:Gem::Version
141
96
  version: '0'
142
97
  - !ruby/object:Gem::Dependency
143
98
  name: yard
144
99
  requirement: !ruby/object:Gem::Requirement
145
- none: false
146
100
  requirements:
147
- - - ! '>='
101
+ - - '>='
148
102
  - !ruby/object:Gem::Version
149
103
  version: '0'
150
104
  type: :development
151
105
  prerelease: false
152
106
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
107
  requirements:
155
- - - ! '>='
108
+ - - '>='
156
109
  - !ruby/object:Gem::Version
157
110
  version: '0'
158
111
  - !ruby/object:Gem::Dependency
159
112
  name: bundler
160
113
  requirement: !ruby/object:Gem::Requirement
161
- none: false
162
114
  requirements:
163
- - - ! '>='
115
+ - - '>='
164
116
  - !ruby/object:Gem::Version
165
117
  version: '0'
166
118
  type: :development
167
119
  prerelease: false
168
120
  version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
121
  requirements:
171
- - - ! '>='
122
+ - - '>='
172
123
  - !ruby/object:Gem::Version
173
124
  version: '0'
174
125
  description: execution of system commands
@@ -197,10 +148,10 @@ files:
197
148
  - lib/setup.rb
198
149
  - lib/test.rb
199
150
  - lib/text.rb
200
- - lib/Timer.rb
151
+ - lib/timer.rb
201
152
  - lib/update.rb
202
- - spec/commands_spec.rb
203
153
  - spec/command_spec.rb
154
+ - spec/commands_spec.rb
204
155
  - spec/gem-example/rakefile.rb
205
156
  - spec/text_spec.rb
206
157
  - LICENSE
@@ -208,27 +159,26 @@ files:
208
159
  homepage: http://github.com/lou-parslow/dev_commands.gem
209
160
  licenses:
210
161
  - Apache 2.0
162
+ metadata: {}
211
163
  post_install_message:
212
164
  rdoc_options: []
213
165
  require_paths:
214
166
  - lib
215
167
  required_ruby_version: !ruby/object:Gem::Requirement
216
- none: false
217
168
  requirements:
218
- - - ! '>='
169
+ - - '>='
219
170
  - !ruby/object:Gem::Version
220
171
  version: '0'
221
172
  required_rubygems_version: !ruby/object:Gem::Requirement
222
- none: false
223
173
  requirements:
224
- - - ! '>='
174
+ - - '>='
225
175
  - !ruby/object:Gem::Version
226
176
  version: '0'
227
177
  requirements: []
228
178
  rubyforge_project:
229
- rubygems_version: 1.8.28
179
+ rubygems_version: 2.0.14
230
180
  signing_key:
231
- specification_version: 3
181
+ specification_version: 4
232
182
  summary: gem to execute system commands
233
183
  test_files: []
234
184
  has_rdoc: