rbatch 2.1.1 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/README.ja.md +14 -5
  2. data/README.md +164 -154
  3. data/bin/rbatch-init +21 -13
  4. data/doc/RBatch/Cmd.html +300 -316
  5. data/doc/RBatch/CmdException.html +146 -141
  6. data/doc/RBatch/CmdResult.html +467 -470
  7. data/doc/RBatch/Config.html +392 -433
  8. data/doc/RBatch/Controller.html +374 -0
  9. data/doc/RBatch/DoubleRunCheckException.html +146 -141
  10. data/doc/RBatch/DoubleRunChecker.html +258 -256
  11. data/doc/RBatch/Journal.html +332 -0
  12. data/doc/RBatch/Log.html +636 -805
  13. data/doc/RBatch/LogException.html +164 -0
  14. data/doc/RBatch/RBatch/RBatch/ConfigException.html +164 -0
  15. data/doc/RBatch/RBatch/RBatch.html +163 -0
  16. data/doc/RBatch/RBatch/VariablesException.html +164 -0
  17. data/doc/RBatch/RBatch.html +165 -0
  18. data/doc/RBatch/RunConf/Exception.html +146 -141
  19. data/doc/RBatch/RunConf.html +478 -532
  20. data/doc/RBatch/Variables.html +437 -0
  21. data/doc/RBatch.html +388 -862
  22. data/doc/created.rid +11 -9
  23. data/doc/index.html +178 -184
  24. data/doc/js/darkfish.js +9 -7
  25. data/doc/lib/rbatch/cmd_rb.html +46 -44
  26. data/doc/lib/rbatch/config_rb.html +42 -42
  27. data/doc/lib/rbatch/controller_rb.html +66 -0
  28. data/doc/lib/rbatch/double_run_checker_rb.html +42 -42
  29. data/doc/lib/rbatch/journal_rb.html +52 -0
  30. data/doc/lib/rbatch/log_rb.html +46 -46
  31. data/doc/lib/rbatch/run_conf_rb.html +42 -42
  32. data/doc/lib/rbatch/variables_rb.html +54 -0
  33. data/doc/lib/rbatch/version_rb.html +38 -38
  34. data/doc/lib/rbatch_rb.html +40 -52
  35. data/doc/rdoc.css +365 -308
  36. data/lib/rbatch/cmd.rb +15 -58
  37. data/lib/rbatch/config.rb +7 -7
  38. data/lib/rbatch/controller.rb +37 -61
  39. data/lib/rbatch/double_run_checker.rb +0 -0
  40. data/lib/rbatch/journal.rb +40 -0
  41. data/lib/rbatch/log.rb +71 -129
  42. data/lib/rbatch/run_conf.rb +13 -24
  43. data/lib/rbatch/variables.rb +82 -0
  44. data/lib/rbatch/version.rb +1 -1
  45. data/lib/rbatch.rb +7 -36
  46. data/sample/.rbatchrc +41 -7
  47. data/spec/01_rbach_spec.rb +99 -0
  48. data/spec/{cmd_spec.rb → rbatch/cmd_spec.rb} +40 -43
  49. data/spec/rbatch/config_spec.rb +67 -0
  50. data/spec/rbatch/controller_spec.rb +18 -0
  51. data/spec/{double_run_checker_spec.rb → rbatch/double_run_checker_spec.rb} +3 -0
  52. data/spec/rbatch/journal_spec.rb +29 -0
  53. data/spec/rbatch/log_spec.rb +350 -0
  54. data/spec/{run_conf_spec.rb → rbatch/run_conf_spec.rb} +13 -5
  55. data/spec/rbatch/variables_spec.rb +68 -0
  56. data/spec/spec_helper.rb +4 -5
  57. metadata +33 -17
  58. data/lib/rbatch/common_config.rb +0 -0
  59. data/spec/common_config_spec.rb +0 -85
  60. data/spec/config_spec.rb +0 -79
  61. data/spec/log_spec.rb +0 -430
  62. data/spec/rbatch_spec.rb +0 -22
@@ -0,0 +1,82 @@
1
+ require 'rbatch/run_conf'
2
+
3
+ module RBatch
4
+ class Variables
5
+ attr :vars,:run_conf,:merged_opt
6
+ def initialize(run_conf=nil)
7
+ @merged_opt = {}
8
+ @vars = {
9
+ :program_name => $PROGRAM_NAME ,
10
+ :program_path => File.expand_path($PROGRAM_NAME) ,
11
+ :program_base => File.basename($PROGRAM_NAME),
12
+ :date => Time.now.strftime("%Y%m%d"),
13
+ :time => Time.now.strftime("%H%M%S"),
14
+ }
15
+
16
+ if ENV["RB_VERBOSE"]
17
+ @vars[:journal_verbose] = ENV["RB_VERBOSE"].to_i
18
+ else
19
+ @vars[:journal_verbose] = 1
20
+ end
21
+
22
+ case RUBY_PLATFORM
23
+ when /mswin|mingw/
24
+ @vars[:host_name] = ENV["COMPUTERNAME"] ? ENV["COMPUTERNAME"] : "unknownhost"
25
+ when /cygwin|linux/
26
+ @vars[:host_name] = ENV["HOSTNAME"] ? ENV["HOSTNAME"] : "unknownhost"
27
+ else
28
+ @vars[:host_name] = "unknownhost"
29
+ end
30
+
31
+ if ENV["RB_HOME"]
32
+ @vars[:home_dir] = File.expand_path(ENV["RB_HOME"])
33
+ else
34
+ @vars[:home_dir] = File.expand_path(File.join(File.dirname(@vars[:program_name]), ".."))
35
+ end
36
+ @vars[:run_conf_path] = File.join(@vars[:home_dir],".rbatchrc")
37
+ @run_conf = RunConf.new(@vars[:run_conf_path]) # load run_conf
38
+ @vars.merge!(@run_conf.opt)
39
+ @vars[:common_config_path] = File.join(@vars[:conf_dir],@vars[:common_conf_name])
40
+ @vars[:config_path] = File.join(@vars[:conf_dir],Pathname(File.basename(@vars[:program_name])).sub_ext(".yaml").to_s)
41
+ end #end def
42
+
43
+ def[](key)
44
+ if @vars.has_key?(key)
45
+ if @vars[key].class == String
46
+ @vars[key]
47
+ .gsub("<home>", @vars[:home_dir])
48
+ .gsub("<date>", @vars[:date])
49
+ .gsub("<time>", @vars[:time])
50
+ .gsub("<prog>", @vars[:program_base])
51
+ .gsub("<host>", @vars[:host_name])
52
+ else
53
+ @vars[key]
54
+ end
55
+ else
56
+ raise RBatch::VariablesException, "no such key exist :" + key.to_s
57
+ end
58
+ end
59
+
60
+ def raw_value(key)
61
+ if @vars.has_key?(key)
62
+ @vars[key]
63
+ else
64
+ raise RBatch::VariablesException, "no such key exist :" + key.to_s
65
+ end
66
+ end
67
+
68
+ def merge!(merged_opt)
69
+ @merged_opt = merged_opt
70
+ @vars.merge!(merged_opt)
71
+ return nil
72
+ end
73
+
74
+ def merge(merged_opt)
75
+ @merged_opt = merged_opt
76
+ @vars.merge!(merged_opt)
77
+ return self
78
+ end
79
+
80
+ end
81
+ class RBatch::VariablesException < StandardError ; end
82
+ end
@@ -1,3 +1,3 @@
1
1
  module RBatch
2
- VERSION = "2.1.1"
2
+ VERSION = "2.1.2"
3
3
  end
data/lib/rbatch.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
2
- require 'yaml'
2
+
3
+ require 'rbatch/controller'
3
4
 
4
5
  module RBatch
5
6
  @@ctrl = nil
@@ -7,43 +8,13 @@ module RBatch
7
8
  def init
8
9
  @@ctrl = RBatch::Controller.new
9
10
  end
10
- def ctrl
11
- @@ctrl
12
- end
13
- def run_conf
14
- @@ctrl.run_conf
15
- end
16
- def run_conf_path ; @@ctrl.run_conf_path ; end
17
-
18
- # Config Reader
19
- #
20
- # Read config file and return hash opject. If the key does not exist in config file, raise RBatch::Config::Exception.
21
- #
22
- # Default config file path is "${RB_HOME}/conf/(program base name).yaml"
23
- # ==== Sample
24
- # config : ${RB_HOME}/conf/sample2.yaml
25
- # key: value
26
- # array:
27
- # - item1
28
- # - item2
29
- # - item3
30
- # script : ${RB_HOME}/bin/sample2.rb
31
- # require 'rbatch'
32
- # p RBatch::Config.new
33
- # # or p RBatch::config
34
- # => {"key" => "value", "array" => ["item1", "item2", "item3"]}
35
- def config ; @@ctrl.config ; end
36
- def common_config ; @@ctrl.common_config ; end
37
- def journal(a,b) ; @@ctrl.journal(a,b) ; end
11
+ def ctrl ; @@ctrl ; end
12
+ def vars ; @@ctrl.vars ; end
13
+ def config ; @@ctrl.config ; end
14
+ def common_config ; @@ctrl.common_config ; end
15
+ def cmd(cmd_str,opt=nil) ; @@ctrl.cmd(cmd_str,opt) ; end
38
16
  end
39
17
 
40
18
  # main
41
- require 'rbatch/controller'
42
- require 'rbatch/run_conf'
43
- require 'rbatch/double_run_checker'
44
- require 'rbatch/log'
45
- require 'rbatch/config'
46
- require 'rbatch/cmd'
47
-
48
19
  RBatch::init
49
20
 
data/sample/.rbatchrc CHANGED
@@ -10,10 +10,9 @@
10
10
  # Conf Directory
11
11
  #
12
12
  # Default is "<home>/conf"
13
- #
14
13
  # <home> is replaced to ${RB_HOME}
15
14
  #
16
- #conf_dir: <home>/config
15
+ #conf_dir: <home>/config/
17
16
  #conf_dir: /etc/rbatch/
18
17
 
19
18
  # Common config file name
@@ -22,6 +21,21 @@
22
21
  #
23
22
  #common_conf_name: share.yaml
24
23
 
24
+ # Library Directory
25
+ #
26
+ # Default is "<home>/lib"
27
+ # <home> is replaced to ${RB_HOME}
28
+ #
29
+ #lib_dir: /usr/local/lib/rbatch/
30
+
31
+ # Auto Library Load
32
+ #
33
+ # Default is true
34
+ # If true, require "(library directory)/*.rb" before script run.
35
+ #
36
+ #auto_lib_load: true
37
+ #auto_lib_load: false
38
+
25
39
  # Forbit Script Double Run
26
40
  #
27
41
  # Default is false.
@@ -71,7 +85,7 @@
71
85
  #log_name : "<date>_<time>_<prog>.log"
72
86
  #log_name : "<date>_<prog>.log"
73
87
 
74
- # Append log or not
88
+ # Append Log
75
89
  #
76
90
  # Default is ture.
77
91
  #
@@ -100,8 +114,8 @@
100
114
  #
101
115
  # Default is false.
102
116
  # If this is true, delete old log file when RBatch::Log.new is called.
103
- # A log file to delete is a log file which was made by the RBatch::Log instance,
104
- # and log filename format include "<date>".
117
+ # A log file to delete is a log file which was made by the
118
+ # RBatch::Log instance, and log filename format include "<date>".
105
119
  #
106
120
  #log_delete_old_log: true
107
121
  #log_delete_old_log: false
@@ -113,9 +127,10 @@
113
127
  #log_delete_old_log_date: 14
114
128
 
115
129
  # Send mail or not
116
- #
130
+ #
117
131
  # Default is false.
118
- # When log.error(msg) or log.fatal(msg) called , send e-mail including "msg".
132
+ # When log.error(msg) or log.fatal(msg) called , send e-mail
133
+ # including "msg".
119
134
  #
120
135
  #log_send_mail : true
121
136
 
@@ -125,3 +140,22 @@
125
140
  #log_mail_from : "xxx@sample.com"
126
141
  #log_mail_server_host : "localhost"
127
142
  #log_mail_server_port : 25
143
+
144
+ # RBatch Journal Message Level
145
+ #
146
+ # Default is 1
147
+ # If 2, put more journal messages to STDOUT.
148
+ # If 0, put nothing.
149
+ # Example of journal essages are follows.
150
+ # [RBatch] Load Config : "../conf/hoge.yaml"
151
+ #
152
+ #rbatch_journal_level = 2
153
+ #rbatch_journal_level = 0
154
+
155
+ # Mix RBatch Journal to Logs
156
+ #
157
+ # Default is true.
158
+ # If true, mix RBatch journal messages to log file(s) which is(are) opened at time.
159
+ #
160
+ #mix_rbatch_journal_to_logs : true
161
+ #mix_rbatch_journal_to_logs : false
@@ -0,0 +1,99 @@
1
+ require 'tmpdir'
2
+
3
+ describe "RBatch" do
4
+ before :all do
5
+ @rand = "rbatch_test_" + rand.to_s
6
+ @home = File.join(Dir.tmpdir, @rand)
7
+ @log_dir = File.join(@home,"log")
8
+ @conf_dir = File.join(@home,"conf")
9
+ ENV["RB_HOME"]=@home
10
+
11
+ Dir.mkdir(@home)
12
+ Dir.mkdir(@log_dir)
13
+ Dir.mkdir(@conf_dir)
14
+ open( File.join(@home,".rbatchrc") , "a" ){|f|
15
+ f.write("log_name : hoge.log")
16
+ }
17
+
18
+ open( File.join(@conf_dir,"rspec.yaml") , "a" ){|f|
19
+ f.write("key1 : value1")
20
+ }
21
+
22
+ open( File.join(@conf_dir,"common.yaml") , "a" ){|f|
23
+ f.write("key2 : value2")
24
+ }
25
+
26
+ # stop STODOUT output
27
+ #$stdout = File.open(File.join(@home,"out.txt"),"w")
28
+ #$stderr = File.open(File.join(@home,"err.txt"),"w")
29
+ end
30
+
31
+ after :all do
32
+ # FileUtils.rm_rf(@home)
33
+ end
34
+
35
+ it "success" do
36
+ require 'rbatch'
37
+
38
+ result = RBatch.cmd("ruby -e 'STDOUT.print 1; STDERR.print 2; exit 0;'")
39
+ expect(result.stdout.chomp).to eq "1"
40
+ expect(result.stderr.chomp).to eq "2"
41
+ expect(result.status).to eq 0
42
+ expect{
43
+ RBatch.cmd("ruby -e 'exit 1;'",{:raise => true})
44
+ }.to raise_error(RBatch::CmdException)
45
+
46
+
47
+ expect(RBatch.config["key1"]).to eq "value1"
48
+ expect{ RBatch.config["noexist"] }.to raise_error RBatch::ConfigException
49
+
50
+ expect(RBatch.common_config["key2"]).to eq "value2"
51
+ expect{ RBatch.common_config["noexist"] }.to raise_error RBatch::ConfigException
52
+
53
+ expect{
54
+ RBatch::Log.new do |log|
55
+ log.info("test_string")
56
+ RBatch.ctrl.journal.put 2,"var2"
57
+ RBatch.ctrl.journal.put 1,"var1"
58
+ RBatch.ctrl.journal.put 0,"var0"
59
+ RBatch.config["noexist2"]
60
+ end
61
+ }.to raise_error SystemExit
62
+
63
+ Dir::foreach(RBatch.vars[:log_dir]) do |f|
64
+ if ! (/\.+$/ =~ f)
65
+ File::open(File.join(RBatch.vars[:log_dir] , f)) {|f|
66
+ expect(f.read).to match /test_string/
67
+ }
68
+ end
69
+ end
70
+
71
+ # check journal
72
+ expect(RBatch.ctrl.journal.journals[0]).to match /START RBatch/
73
+ expect(RBatch.ctrl.journal.journals[1]).to match Regexp.new(@rand)
74
+ expect(RBatch.ctrl.journal.journals[2]).to match /batchrc/
75
+ expect(RBatch.ctrl.journal.journals[3]).to match /common.yaml/
76
+ expect(RBatch.ctrl.journal.journals[4]).to match /rspec.yaml/
77
+ expect(RBatch.ctrl.journal.journals[5]).to match /Start Script/
78
+ expect(RBatch.ctrl.journal.journals[6]).to match /Logging Start/
79
+ expect(RBatch.ctrl.journal.journals[7]).to match /var1/
80
+ expect(RBatch.ctrl.journal.journals[8]).to match /var0/
81
+
82
+ # check log
83
+ f = open(File.join(@home,"log","hoge.log")).read
84
+ lines = f.split("\n")
85
+
86
+ expect(lines[0]).to match /START RBatch/
87
+ expect(lines[1]).to match Regexp.new(@rand)
88
+ expect(lines[2]).to match /batchrc/
89
+ expect(lines[3]).to match /common.yaml/
90
+ expect(lines[4]).to match /rspec.yaml/
91
+ expect(lines[5]).to match /Start Script/
92
+ expect(lines[6]).to match /Logging Start/
93
+ expect(lines[7]).to match /test_string/
94
+ expect(lines[8]).to match /var1/
95
+ expect(lines[9]).to match /var0/
96
+ expect(lines[10]).to match /FATAL/
97
+
98
+ end
99
+ end
@@ -1,43 +1,46 @@
1
- require File.expand_path(File.join( File.dirname(__FILE__), 'spec_helper'))
1
+ require 'simplecov'
2
+ SimpleCov.start
2
3
 
3
- require 'rbatch'
4
+ require 'rbatch/variables'
5
+ require 'rbatch/cmd'
4
6
 
5
7
  describe RBatch::Cmd do
6
8
  before :each do
7
- RBatch.run_conf.reset
9
+ @def_vars = RBatch::Variables.new()
10
+ RBatch::Cmd.def_vars = @def_vars
8
11
  end
9
12
 
10
13
  it "run command which status is 0" do
11
- result = RBatch::cmd "ruby -e 'STDOUT.print 1; STDERR.print 2; exit 0;'"
14
+ result = RBatch::Cmd.new("ruby -e 'STDOUT.print 1; STDERR.print 2; exit 0;'").run
12
15
  expect(result.stdout.chomp).to eq "1"
13
16
  expect(result.stderr.chomp).to eq "2"
14
17
  expect(result.status).to eq 0
15
18
  end
16
19
  it "run command which status is 1" do
17
- result = RBatch::cmd "ruby -e 'STDOUT.print 1; STDERR.print 2; exit 1;'"
20
+ result = RBatch::Cmd.new("ruby -e 'STDOUT.print 1; STDERR.print 2; exit 1;'").run
18
21
  expect(result.stdout.chomp).to eq "1"
19
22
  expect(result.stderr.chomp).to eq "2"
20
23
  expect(result.status).to eq 1
21
24
  end
22
25
  it "raise error when command does not exist" do
23
26
  expect {
24
- RBatch::cmd "not_exist_command"
27
+ RBatch::Cmd.new("not_exist_command").run
25
28
  }.to raise_error(Errno::ENOENT)
26
29
  end
27
30
  it "run command which stdout size is greater than 65534byte" do
28
- result = RBatch::cmd "ruby -e '100000.times{print 0}'"
31
+ result = RBatch::Cmd.new("ruby -e '100000.times{print 0}'").run
29
32
  expect(result.stdout.chomp.size).to eq 100000
30
33
  expect(result.stderr.chomp).to eq ""
31
34
  expect(result.status).to eq 0
32
35
  end
33
36
  it "run command which stdout size is greater than 65534bytes with status 1" do
34
- result = RBatch::cmd "ruby -e '100000.times{print 0}; exit 1'"
37
+ result = RBatch::Cmd.new("ruby -e '100000.times{print 0}; exit 1'").run
35
38
  expect(result.stdout.chomp.size).to eq 100000
36
39
  expect(result.stderr.chomp).to eq ""
37
40
  expect(result.status).to eq 1
38
41
  end
39
42
  it "run command which status is grater than 256" do
40
- result = RBatch::cmd "ruby -e 'STDOUT.print 1; STDERR.print 2; exit 300;'"
43
+ result = RBatch::Cmd.new( "ruby -e 'STDOUT.print 1; STDERR.print 2; exit 300;'").run
41
44
  expect(result.stdout.chomp).to eq "1"
42
45
  expect(result.stderr.chomp).to eq "2"
43
46
  case RUBY_PLATFORM
@@ -49,13 +52,13 @@ describe RBatch::Cmd do
49
52
  end
50
53
  end
51
54
  it "run to_h method" do
52
- result = RBatch::cmd "ruby -e 'STDOUT.print 1; STDERR.print 2; exit 1;'"
55
+ result = RBatch::Cmd.new("ruby -e 'STDOUT.print 1; STDERR.print 2; exit 1;'").run
53
56
  expect(result.to_h[:stdout]).to eq "1"
54
57
  expect(result.to_h[:stderr]).to eq "2"
55
58
  expect(result.to_h[:status]).to eq 1
56
59
  end
57
60
  it "run to_s method" do
58
- result = RBatch::cmd "ruby -e 'STDOUT.print 1; STDERR.print 2; exit 1;'"
61
+ result = RBatch::Cmd.new("ruby -e 'STDOUT.print 1; STDERR.print 2; exit 1;'").run
59
62
  expect(result.to_s).to eq "{:cmd_str=>\"ruby -e 'STDOUT.print 1; STDERR.print 2; exit 1;'\", :stdout=>\"1\", :stderr=>\"2\", :status=>1}"
60
63
  end
61
64
  it "raise error when command is nil" do
@@ -63,61 +66,55 @@ describe RBatch::Cmd do
63
66
  RBatch::Cmd.new(nil)
64
67
  }.to raise_error(RBatch::CmdException)
65
68
  end
66
- it "run RBatch::Cmd.new method" do
67
- result = RBatch::Cmd.new("ruby -e 'STDOUT.print 1; STDERR.print 2; exit 0;'").run
68
- expect(result.stdout.chomp).to eq "1"
69
- expect(result.stderr.chomp).to eq "2"
70
- expect(result.status).to eq 0
71
- end
72
-
73
69
 
74
70
  describe "option by argument" do
75
- describe "timeout" do
76
- it "run successfuly when command is short time" do
77
- opt = {:timeout => 2}
78
- expect {
79
- RBatch::cmd("ruby -e 'sleep 1'",opt)
80
- }.to_not raise_error
81
- end
82
- it "raise timeout error when command is long time" do
83
- opt = {:timeout => 1}
71
+ describe "raise" do
72
+ it "raise error when command status is not 0" do
73
+ opt = {:raise => true}
84
74
  expect {
85
- RBatch::cmd("ruby -e 'sleep 2'",opt)
75
+ RBatch::Cmd.new("ruby -e 'exit 1;'",opt).run
86
76
  }.to raise_error(RBatch::CmdException)
87
77
  end
88
78
  end
89
- end
90
-
91
- describe "option by argument" do
92
79
  describe "timeout" do
93
80
  it "run successfuly when command is short time" do
94
81
  opt = {:timeout => 2}
95
82
  expect {
96
- RBatch::cmd("ruby -e 'sleep 1'",opt)
83
+ RBatch::Cmd.new("ruby -e 'sleep 1'",opt).run
97
84
  }.to_not raise_error
98
85
  end
99
86
  it "raise timeout error when command is long time" do
100
87
  opt = {:timeout => 1}
101
88
  expect {
102
- RBatch::cmd("ruby -e 'sleep 2'",opt)
89
+ RBatch::Cmd.new("ruby -e 'sleep 2'",opt).run
103
90
  }.to raise_error(RBatch::CmdException)
104
91
  end
105
92
  end
106
93
  end
107
94
 
108
- describe "option by config" do
109
- before :all do
110
- @config_dir=File.join(ENV["RB_HOME"],"conf")
111
- @config_file = File.join(@config_dir , "rbatch.yaml")
112
- Dir::mkdir @config_dir if ! Dir.exists? @config_dir
113
- end
95
+ describe "option by run_conf" do
114
96
  describe "raise" do
115
- before :each do
116
- RBatch.run_conf[:cmd_raise] = true
117
- end
118
97
  it "raise error when command status is not 0" do
98
+ @def_vars.merge!({:cmd_raise => true})
99
+ RBatch::Cmd.def_vars = @def_vars
100
+ expect {
101
+ RBatch::Cmd.new("ruby -e 'exit 1;'").run
102
+ }.to raise_error(RBatch::CmdException)
103
+ end
104
+ end
105
+ describe "timeout" do
106
+ it "run successfuly when command is short time" do
107
+ @def_vars.merge!({:cmd_timeout => 2})
108
+ RBatch::Cmd.def_vars = @def_vars
109
+ expect {
110
+ RBatch::Cmd.new("ruby -e 'sleep 1'").run
111
+ }.to_not raise_error
112
+ end
113
+ it "raise timeout error when command is long time" do
114
+ @def_vars.merge!({:cmd_timeout => 1})
115
+ RBatch::Cmd.def_vars = @def_vars
119
116
  expect {
120
- RBatch::cmd "ruby -e 'exit 1;'"
117
+ RBatch::Cmd.new("ruby -e 'sleep 2'").run
121
118
  }.to raise_error(RBatch::CmdException)
122
119
  end
123
120
  end
@@ -0,0 +1,67 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'tmpdir'
5
+ require 'rbatch/config'
6
+
7
+ describe RBatch::Config do
8
+ before :all do
9
+ end
10
+
11
+ before :each do
12
+ @path = File.join(Dir.tmpdir , rand.to_s)
13
+ end
14
+
15
+ after :each do
16
+ FileUtils.rm @path if File.exists? @path
17
+ end
18
+
19
+ it "read" do
20
+ open( @path , "w" ){|f| f.write("key: value")}
21
+ expect(RBatch::Config.new(@path)["key"]).to eq "value"
22
+ end
23
+
24
+ it "key is Symbol" do
25
+ open( @path , "w" ){|f| f.write(":key: value")}
26
+ expect(RBatch::Config.new(@path)[:key]).to eq "value"
27
+ end
28
+
29
+ it "raise error when config does not exist" do
30
+ expect {
31
+ RBatch::Config.new(@path)["hoge"]
32
+ }.to raise_error(RBatch::ConfigException)
33
+ expect {
34
+ RBatch::Config.new(@path).to_h
35
+ }.to raise_error(RBatch::ConfigException)
36
+ expect {
37
+ RBatch::Config.new(@path).to_s
38
+ }.to raise_error(RBatch::ConfigException)
39
+ end
40
+
41
+ it "read config twice" do
42
+ open( @path , "w" ){|f| f.write("key: value")}
43
+ expect(RBatch::Config.new(@path)["key"]).to eq "value"
44
+ expect(RBatch::Config.new(@path)["key"]).to eq "value"
45
+ end
46
+
47
+ it "raise error when read value which key does not exist" do
48
+ open( @path , "w" ){|f| f.write("key: value")}
49
+ expect {
50
+ RBatch::Config.new(@path)["not_exist"]
51
+ }.to raise_error(RBatch::ConfigException)
52
+ end
53
+
54
+ it "raise error when read value which key mistake String for Symbol" do
55
+ open( @path , "w" ){|f| f.write("key: value")}
56
+ expect {
57
+ RBatch::Config.new(@path)[:key]
58
+ }.to raise_error(RBatch::ConfigException)
59
+ end
60
+
61
+ it "raise error when read value which key mistake Symbol for String" do
62
+ open( @path , "w" ){|f| f.write(":key: value")}
63
+ expect {
64
+ RBatch::Config.new(@path)["key"]
65
+ }.to raise_error(RBatch::ConfigException)
66
+ end
67
+ end
@@ -0,0 +1,18 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'tmpdir'
5
+ require 'rbatch/controller'
6
+ describe RBatch::Controller do
7
+
8
+ before :all do
9
+ @home = File.join(Dir.tmpdir, "rbatch_test_" + rand.to_s)
10
+ end
11
+
12
+ after :each do
13
+ end
14
+
15
+ it "success" do
16
+ RBatch::Variables.new()
17
+ end
18
+ end
@@ -1,3 +1,6 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
1
4
  require 'rbatch/double_run_checker'
2
5
 
3
6
  describe RBatch::DoubleRunChecker do
@@ -0,0 +1,29 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'rbatch/journal'
5
+
6
+ describe RBatch::Journal do
7
+ it "default" do
8
+ @j = RBatch::Journal.new
9
+ expect(@j.journal_verbose) == 1
10
+ end
11
+
12
+ it "is passed argument" do
13
+ @j = RBatch::Journal.new(2)
14
+ expect(@j.journal_verbose) == 2
15
+ end
16
+
17
+ it "ENV is set" do
18
+ ENV["RB_VERBOSE"] = "0"
19
+ @j = RBatch::Journal.new
20
+ expect(@j.journal_verbose) == 0
21
+ end
22
+
23
+ it "both argument and ENV are set" do
24
+ ENV["RB_VERBOSE"] = "0"
25
+ @j = RBatch::Journal.new(2)
26
+ expect(@j.journal_verbose) == 2
27
+ end
28
+ end
29
+