sysadmin 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c97b377baf2648ff39d95525f93b423892ab3dfc
4
- data.tar.gz: 96b732005a0d3d090411c9610961e17facb7b86b
3
+ metadata.gz: 10b36152122215a87a4edbab6face729b218cd16
4
+ data.tar.gz: 5865cca7b0751bacbff571528ca0b262523dc446
5
5
  SHA512:
6
- metadata.gz: 1c13c0dd5aec140a9a169be96a24ffe4f2ab64afcaacb25626394649ca0408924e5e7e044bdb887e1f624c5718598e977732612ef5bb8162efd703b115827683
7
- data.tar.gz: 156c0fa7310930f420ab830db3c1b957a416ef1800a625523b37e11d2b0ad002fdc7acd8cf845161e3afee959de04889ac4dbdec67f696667dd157ef8cd91e3a
6
+ metadata.gz: 1429f30d5cda6c7ca8d668d9cbaa6cd2c6982832187ff5273bae7ba341a281ae3a953a0a4696beff5c36f46caaed5f8f1a1bdc3546088ff35c1ad238171722bc
7
+ data.tar.gz: 3e29da3a47acd1b5b1d2452107105c3b1cfe3867170c59980fa14bb60512b83ca4fd6fe1bd7520baf77bd034554983ff3863318fcbb931baa28e6f54856c77f7
data/README.md CHANGED
@@ -12,6 +12,39 @@ The collection of libraries for managing the system.
12
12
  See doc/README(.ja).
13
13
 
14
14
 
15
+ Purpose
16
+ -------
17
+
18
+ **Array**
19
+
20
+ Extension for Array class. Array operation to be used well in the System Management.
21
+
22
+
23
+ **Dir**
24
+
25
+ Method filelist provides an intelligent directory scanning.
26
+
27
+
28
+ **Sysadmin::Directory**
29
+
30
+ Return file list matching regexp.
31
+
32
+
33
+ **File**
34
+
35
+ Providing useful file operations. Method zread is open zip and other type files. *line methods provides append, replace, and remove line of file.
36
+
37
+
38
+ **Time**
39
+
40
+ Providing strict_parse methods. This new method return nil when specified invalid date.
41
+
42
+
43
+ **Util**
44
+
45
+ Other useful methods.
46
+
47
+
15
48
  Development
16
49
  -----------
17
50
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.2.0
@@ -1,3 +1,15 @@
1
+ === 0.2.0 / 2013-11-22
2
+
3
+ * Add Methods
4
+
5
+ * Array#sum
6
+ * Array#sumf
7
+
8
+ * Improvement tests
9
+
10
+ * Improvement docs
11
+
12
+
1
13
  === 0.1.5 / 2013-10-08
2
14
 
3
15
  * Fix typo
@@ -59,8 +59,11 @@ $ gem install sysadmin
59
59
  - Array
60
60
  Array クラスを拡張する
61
61
 
62
- * Array#average
63
- 配列の平均を返却する
62
+ * Array#sum
63
+ 配列の合計値を整数型で返却する
64
+
65
+ * Array#sumf
66
+ 配列の合計値を浮動小数点型で返却する
64
67
 
65
68
  * Array#variance
66
69
  配列の分散を返却する
@@ -2,16 +2,16 @@
2
2
  # Name:: Sysadmin
3
3
  # Author:: 774 <http://id774.net>
4
4
  # Created:: Mar 23, 2012
5
- # Updated:: Oct 08, 2013
5
+ # Updated:: Nov 22, 2013
6
6
  # Copyright:: 774 Copyright (c) 2012
7
7
  # License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
8
8
 
9
9
  module Sysadmin
10
- VERSION = "0.1.5"
11
10
  require File.dirname(__FILE__) + "/sysadmin/util"
12
11
  require File.dirname(__FILE__) + "/sysadmin/array_ext"
13
12
  require File.dirname(__FILE__) + "/sysadmin/file_ext"
14
13
  require File.dirname(__FILE__) + "/sysadmin/dir_ext"
15
14
  require File.dirname(__FILE__) + "/sysadmin/directory"
16
15
  require File.dirname(__FILE__) + "/sysadmin/time_ext"
16
+ require File.dirname(__FILE__) + "/sysadmin/version"
17
17
  end
@@ -1,12 +1,20 @@
1
1
  # Name:: Sysadmin::ArrayExtension
2
2
  # Author:: 774 <http://id774.net>
3
3
  # Created:: Aug 20, 2013
4
- # Updated:: Oct 08, 2013
4
+ # Updated:: Nov 21, 2013
5
5
  # Copyright:: 774 Copyright (c) 2013
6
6
  # License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
7
7
 
8
8
  class Array
9
9
 
10
+ def sum
11
+ inject(0){|result, item| result + item.to_i}
12
+ end
13
+
14
+ def sumf
15
+ inject(0){|result, item| result + item.to_f}
16
+ end
17
+
10
18
  def average
11
19
  inject(0.0) { |sum, i| sum += i } / size
12
20
  end
@@ -1,7 +1,7 @@
1
1
  # Name:: Sysadmin::DirExtension
2
2
  # Author:: 774 <http://id774.net>
3
3
  # Created:: Jul 17, 2012
4
- # Updated:: Jul 17, 2012
4
+ # Updated:: Nov 22, 2013
5
5
  # Copyright:: 774 Copyright (c) 2012
6
6
  # License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
7
7
 
@@ -10,14 +10,11 @@ module Sysadmin
10
10
 
11
11
  def Dir.filelist(dir, sub_directory = false)
12
12
  array = Array.new
13
+
13
14
  if (FileTest.file?(dir))
14
15
  array << dir
15
16
  else
16
- if sub_directory
17
- dir = dir + "/**/"
18
- else
19
- dir = dir + "/"
20
- end
17
+ dir = sub_directory ? dir + "/**/" : dir = dir + "/"
21
18
  Dir::glob(dir).each do |d|
22
19
  if (FileTest.directory?(d))
23
20
  Dir::foreach(d) do |f|
@@ -28,7 +25,8 @@ module Sysadmin
28
25
  end
29
26
  end
30
27
  end
31
- return array
28
+
29
+ array
32
30
  end
33
31
 
34
32
  end
@@ -0,0 +1,10 @@
1
+ # Name:: Sysadmin::Version
2
+ # Author:: 774 <http://id774.net>
3
+ # Created:: Nov 22, 2013
4
+ # Updated:: Nov 22, 2013
5
+ # Copyright:: 774 Copyright (c) 2013
6
+ # License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
7
+
8
+ module Sysadmin
9
+ VERSION = "0.2.0"
10
+ end
@@ -2,25 +2,91 @@
2
2
 
3
3
  require File.dirname(__FILE__) + '/../../spec_helper'
4
4
 
5
- describe Sysadmin, 'Array クラス拡張' do
6
- context 'で average メソッドを呼ぶ場合' do
7
- it "平均が返却される" do
8
- a = [88, 99, 77, 66, 55, 40]
9
- a.average.should == 70.83333333333333
5
+ describe Array do
6
+ describe '#sum' do
7
+ context 'with no arguments' do
8
+ subject { array.sum }
9
+
10
+ context 'if all elements are integer' do
11
+ let(:array) { [1, 2, 3, 4, 5] }
12
+ it 'should return integer summary of elements' do
13
+ expect(subject).to eql 15
14
+ end
15
+ end
16
+
17
+ context 'if array contains string' do
18
+ let(:array) { [1, 2, 3, '4', 5] }
19
+ it 'should return integer summary of elements' do
20
+ expect(subject).to eql 15
21
+ end
22
+ end
23
+
24
+ context 'if array contains nil' do
25
+ let(:array) { [1, 2, 3, nil, 5] }
26
+ it 'should return integer summary of elements' do
27
+ expect(subject).to eql 11
28
+ end
29
+ end
10
30
  end
11
31
  end
12
32
 
13
- context 'で variance メソッドを呼ぶ場合' do
14
- it "分散が返却される" do
15
- a = [88, 99, 77, 66, 55, 40]
16
- a.variance.should == 391.8055555555556
33
+ describe '#sumf' do
34
+ context 'with no arguments' do
35
+ subject { array.sumf }
36
+
37
+ context 'if all elements are integer' do
38
+ let(:array) { [1, 2, 3, 4, 5] }
39
+ it 'should return float summary of elements' do
40
+ expect(subject).to eql 15.0
41
+ end
42
+ end
43
+
44
+ context 'if array contains string' do
45
+ let(:array) { [1, 2, 3, '4.2', 5] }
46
+ it 'should return float summary of elements' do
47
+ expect(subject).to eql 15.2
48
+ end
49
+ end
50
+
51
+ context 'if array contains string' do
52
+ let(:array) { [1, 2, 3, nil, 5] }
53
+ it 'should return float summary of elements' do
54
+ expect(subject).to eql 11.0
55
+ end
56
+ end
17
57
  end
18
58
  end
19
59
 
20
- context 'で standard_deviation メソッドを呼ぶ場合' do
21
- it "標準偏差が返却される" do
22
- a = [88, 99, 77, 66, 55, 40]
23
- a.standard_deviation.should == 19.79407880037754
60
+ describe '#average' do
61
+ context 'with no arguments' do
62
+ subject { array.average }
63
+
64
+ let(:array) { [8, 9, 7, 6, 5, 4] }
65
+ it 'should return average of array' do
66
+ expect(subject).to eql 6.5
67
+ end
68
+ end
69
+ end
70
+
71
+ describe '#variance' do
72
+ context 'with no arguments' do
73
+ subject { array.variance }
74
+
75
+ let(:array) { [8, 9, 7, 6, 5, 4] }
76
+ it 'should return variance of array' do
77
+ expect(subject).to eql 2.9166666666666665
78
+ end
79
+ end
80
+ end
81
+
82
+ describe '#standard_deviation' do
83
+ context 'with no arguments' do
84
+ subject { array.standard_deviation }
85
+
86
+ let(:array) { [8, 9, 7, 6, 5, 4] }
87
+ it 'should return standard deviation of array' do
88
+ expect(subject).to eql 1.707825127659933
89
+ end
24
90
  end
25
91
  end
26
92
  end
@@ -2,42 +2,60 @@
2
2
 
3
3
  require File.dirname(__FILE__) + '/../../spec_helper'
4
4
 
5
- describe Sysadmin::DirExtension, 'Dir クラス拡張' do
6
- context 'filelist メソッドを呼ぶ場合' do
7
- describe 'ディレクトリ名を指定すると' do
8
- it "ディレクトリ内のファイル一覧が返却される" do
9
- test_dir = File.expand_path("../../test_dir/a", File.dirname(__FILE__))
10
- Dir.filelist(test_dir).should have(2).items
5
+ describe Dir do
6
+ describe '#filelist' do
7
+ context 'specity directory name' do
8
+ subject { Dir.filelist(dir) }
9
+
10
+ let(:dir) { File.expand_path("../../test_dir/a", File.dirname(__FILE__)) }
11
+ it 'should return file list in directories' do
12
+ expect(subject).to have(2).items
11
13
  end
12
- end
13
14
 
14
- describe 'ファイル名を指定すると' do
15
- it "ファイル名が返却される" do
16
- test_dir = File.expand_path("../../test_dir/a/d.txt", File.dirname(__FILE__))
17
- Dir.filelist(test_dir).should have(1).items
15
+ context 'if subdirectory option is true' do
16
+ subject { Dir.filelist(dir, sub_directory = true) }
17
+
18
+ let(:dir) { File.expand_path("../../test_dir", File.dirname(__FILE__)) }
19
+ it 'should return file name (not in sub directories)' do
20
+ expect(subject).to have(9).items
21
+ end
18
22
  end
19
- end
20
23
 
21
- describe 'サブディレクトリを true にしてディレクトリを指定すると' do
22
- it "サブディレクトリ内のファイルも返却される" do
23
- test_dir = File.expand_path("../../test_dir", File.dirname(__FILE__))
24
- Dir.filelist(test_dir, sub_directory = true).should have(9).items
24
+ context 'if subdirectory option is false' do
25
+ subject { Dir.filelist(dir, sub_directory = false) }
26
+
27
+ let(:dir) { File.expand_path("../../test_dir/a", File.dirname(__FILE__)) }
28
+ it 'should return file name not including sub directories' do
29
+ expect(subject).to have(2).items
30
+ end
25
31
  end
26
32
  end
27
33
 
28
- describe 'サブディレクトリを false にしてディレクトリを指定すると' do
29
- it "ディレクトリ内のファイル一覧が返却される (サブディレクトリは見ない)" do
30
- test_dir = File.expand_path("../../test_dir/a", File.dirname(__FILE__))
31
- Dir.filelist(test_dir, sub_directory = false).should have(2).items
34
+ context 'specity file name' do
35
+ subject { Dir.filelist(file) }
36
+
37
+ let(:file) { File.expand_path("../../test_dir/a/d.txt", File.dirname(__FILE__)) }
38
+ it 'should return the file name' do
39
+ expect(subject).to have(1).item
32
40
  end
33
- end
34
41
 
35
- describe 'サブディレクトリを true にしてファイル名を指定しても' do
36
- it "ファイル名が返却される (サブディレクトリは見ない)" do
37
- test_dir = File.expand_path("../../test_dir/a/d.txt", File.dirname(__FILE__))
38
- Dir.filelist(test_dir).should have(1).items
42
+ context 'if subdirectory option is true' do
43
+ subject { Dir.filelist(file, sub_directory = true) }
44
+
45
+ let(:file) { File.expand_path("../../test_dir/a/d.txt", File.dirname(__FILE__)) }
46
+ it 'should return file list including subdirectories' do
47
+ expect(subject).to have(1).item
48
+ end
39
49
  end
40
- end
41
50
 
51
+ context 'if subdirectory option is true' do
52
+ subject { Dir.filelist(file, sub_directory = false) }
53
+
54
+ let(:file) { File.expand_path("../../test_dir/a/d.txt", File.dirname(__FILE__)) }
55
+ it 'should return file list not including subdirectories' do
56
+ expect(subject).to have(1).item
57
+ end
58
+ end
59
+ end
42
60
  end
43
61
  end
@@ -2,54 +2,68 @@
2
2
 
3
3
  require File.dirname(__FILE__) + '/../../spec_helper'
4
4
 
5
- describe Sysadmin::Directory, 'Directory クラス' do
6
- context 'map メソッドを呼ぶ場合' do
7
- describe 'ディレクトリ名を指定すると' do
8
- it "ディレクトリ内のファイル一覧が返却される" do
9
- test_dir = File.expand_path("../../test_dir", File.dirname(__FILE__))
10
- Sysadmin::Directory.new(test_dir).map{|f|f}.should have(9).items
5
+ describe Sysadmin::Directory do
6
+ describe '#map' do
7
+ context 'specify directory name' do
8
+ subject { Sysadmin::Directory.new(dir) }
9
+ let(:dir) { File.expand_path("../../test_dir", File.dirname(__FILE__)) }
10
+
11
+ it 'should return file list in directory' do
12
+ expect(subject).to have(9).items
11
13
  end
12
14
  end
13
15
 
14
- describe 'ディレクトリ名を指定すると' do
15
- it "ディレクトリ内のファイル一覧が返却される" do
16
- test_dir = File.expand_path("../../test_dir/a", File.dirname(__FILE__))
17
- Sysadmin::Directory.new(test_dir).map{|f|f}.should have(4).items
16
+ context 'specify directory name' do
17
+ subject { Sysadmin::Directory.new(dir) }
18
+ let(:dir) { File.expand_path("../../test_dir/a", File.dirname(__FILE__)) }
19
+
20
+ it 'should return file list in directory' do
21
+ expect(subject).to have(4).items
18
22
  end
19
23
  end
20
24
 
21
- describe 'ディレクトリ名を指定すると' do
22
- it "ディレクトリ内のファイル一覧が返却される" do
23
- test_dir = File.expand_path("../../test_dir/a/g", File.dirname(__FILE__))
24
- Sysadmin::Directory.new(test_dir).map{|f|f}.should have(2).item
25
+ context 'specify directory name' do
26
+ subject { Sysadmin::Directory.new(dir) }
27
+ let(:dir) { File.expand_path("../../test_dir/a/g", File.dirname(__FILE__)) }
28
+
29
+ it 'should return file list in directory' do
30
+ expect(subject).to have(2).items
25
31
  end
26
32
  end
27
33
 
28
- describe 'ディレクトリ名を指定すると' do
29
- it "ディレクトリ内のファイル一覧が返却される" do
30
- test_dir = File.expand_path("../../test_dir/b", File.dirname(__FILE__))
31
- Sysadmin::Directory.new(test_dir).map{|f|f}.should have(2).item
34
+ context 'specify directory name' do
35
+ subject { Sysadmin::Directory.new(dir) }
36
+ let(:dir) { File.expand_path("../../test_dir/b", File.dirname(__FILE__)) }
37
+
38
+ it 'should return file list in directory' do
39
+ expect(subject).to have(2).items
32
40
  end
33
41
  end
34
42
 
35
- describe 'ディレクトリ名を指定し grep すると' do
36
- it "ディレクトリ内の grep に適合したファイル一覧が返却される" do
37
- test_dir = File.expand_path("../../test_dir", File.dirname(__FILE__))
38
- Sysadmin::Directory.new(test_dir).grep(/\.txt/).should have(9).item
43
+ context 'specify directory name with grep' do
44
+ subject { Sysadmin::Directory.new(dir).grep(/\.txt/) }
45
+ let(:dir) { File.expand_path("../../test_dir", File.dirname(__FILE__)) }
46
+
47
+ it 'should return file list matching regexp' do
48
+ expect(subject).to have(9).item
39
49
  end
40
50
  end
41
51
 
42
- describe 'ディレクトリ名を指定し grep すると' do
43
- it "ディレクトリ内の grep に適合したファイル一覧が返却される" do
44
- test_dir = File.expand_path("../../test_dir", File.dirname(__FILE__))
45
- Sysadmin::Directory.new(test_dir).grep(/d\.txt/).should have(1).items
52
+ context 'specify directory name with grep' do
53
+ subject { Sysadmin::Directory.new(dir).grep(/d\.txt/) }
54
+ let(:dir) { File.expand_path("../../test_dir", File.dirname(__FILE__)) }
55
+
56
+ it 'should return file list matching regexp' do
57
+ expect(subject).to have(1).item
46
58
  end
47
59
  end
48
60
 
49
- describe 'ディレクトリ名を指定し grep して take すると' do
50
- it "ディレクトリ内の grep に適合し take した数だけファイル一覧が返却される" do
51
- test_dir = File.expand_path("../../test_dir", File.dirname(__FILE__))
52
- Sysadmin::Directory.new(test_dir).grep(/\.txt/).take(3).should have(3).items
61
+ context 'specify directory name with grep and take' do
62
+ subject { Sysadmin::Directory.new(dir).grep(/\.txt/).take(3) }
63
+ let(:dir) { File.expand_path("../../test_dir", File.dirname(__FILE__)) }
64
+
65
+ it 'should return picked up file list matching regexp' do
66
+ expect(subject).to have(3).items
53
67
  end
54
68
  end
55
69
 
@@ -4,115 +4,153 @@ require File.dirname(__FILE__) + '/../../spec_helper'
4
4
  require 'tempfile'
5
5
  require 'zlib'
6
6
 
7
- describe Sysadmin::FileExtension, 'File クラス拡張' do
8
- context 'で非圧縮のファイルを zread した場合' do
9
- it "正しく読み込まれる" do
10
- try = "uncompressed"
11
- expect = "uncompressed\n"
12
- @uncompressed = Tempfile::new("test.txt")
13
- File.append_line(:file => @uncompressed.path, :str => try)
14
-
15
- File.zread(@uncompressed.path).should == expect
16
- @uncompressed.close
17
- end
18
- end
7
+ describe File do
8
+ describe '#zread' do
9
+ context 'read uncompressed file' do
10
+ subject {
11
+ @uncompressed = Tempfile::new("test.txt")
12
+ File.append_line(:file => @uncompressed.path, :str => try)
13
+ File.zread(@uncompressed.path)
14
+ }
19
15
 
20
- context 'で圧縮されたファイルを zread した場合' do
21
- it "正しく読み込まれる" do
22
- try = "compressed"
23
- expect = "compressed\n"
24
- @compressed = Tempfile::new("test2.txt")
25
- Zlib::GzipWriter.open(@compressed.path) do |gz|
26
- gz.puts try
27
- end
16
+ let(:try) { "uncompressed" }
17
+ let(:expected) { "uncompressed\n" }
28
18
 
29
- File.zread(@compressed.path).should == expect
30
- @compressed.close
19
+ it 'should read successful' do
20
+ expect(subject).to eql expected
21
+ @uncompressed.close
22
+ end
31
23
  end
32
- end
33
24
 
34
- context ' append_line メソッドを呼ぶと' do
35
- it "ファイル末尾に文字列行が追加される" do
36
- @testfile = Tempfile::new("test.txt")
37
- src = 'hoge'
38
- expect = "hoge\n"
25
+ context 'read compressed file' do
26
+ subject {
27
+ @compressed = Tempfile::new("test2.txt")
28
+ Zlib::GzipWriter.open(@compressed.path) do |gz|
29
+ gz.puts try
30
+ end
31
+ File.zread(@compressed.path)
32
+ }
33
+
34
+ let(:try) { "compressed" }
35
+ let(:expected) { "compressed\n" }
39
36
 
40
- 3.times do
41
- File.append_line(:file => @testfile.path, :str => src)
37
+ it 'should read successful' do
38
+ expect(subject).to eql expected
39
+ @compressed.close
42
40
  end
41
+ end
42
+ end
43
+
44
+ describe '#append_line' do
45
+ context 'with arguments file and strings' do
43
46
 
44
- open(@testfile.path) { |file|
45
- while line = file.gets
46
- line.should == expect
47
+ subject {
48
+ @testfile = Tempfile::new("test.txt")
49
+ 3.times do
50
+ File.append_line(:file => @testfile.path, :str => src)
47
51
  end
48
52
  }
49
- @testfile.close
50
- end
51
- end
52
53
 
53
- context 'で replace_line メソッドを呼ぶと' do
54
- it "ファイル内の文字列が置換される" do
55
- @testfile = Tempfile::new("test.txt")
56
- src = 'hoge'
57
- try = 'fuga'
58
- expect = "fuga\n"
54
+ let(:src) { 'hoge' }
55
+ let(:expected) { "hoge\n" }
59
56
 
60
- 3.times do
61
- File.append_line(:file => @testfile.path, :str => src)
57
+ it 'should append strings to last line of file' do
58
+ subject
59
+
60
+ open(@testfile.path) { |file|
61
+ while line = file.gets
62
+ expect(line).to eql expected
63
+ end
64
+ }
65
+ @testfile.close
62
66
  end
63
- File.replace_line(:file => @testfile.path, :src => src, :dst => try)
67
+ end
68
+ end
69
+
70
+ describe '#replace_line' do
71
+ context 'with arguments file and strings' do
64
72
 
65
- open(@testfile.path) { |file|
66
- while line = file.gets
67
- line.should == expect
73
+ subject {
74
+ @testfile = Tempfile::new("test.txt")
75
+ 3.times do
76
+ File.append_line(:file => @testfile.path, :str => src)
68
77
  end
78
+ File.replace_line(:file => @testfile.path, :src => src, :dst => try)
69
79
  }
70
- @testfile.close
71
- end
72
- end
73
80
 
74
- context 'で remove_line メソッドを呼ぶと' do
75
- it "ファイル内の引数に適合した行が削除される" do
76
- @testfile = Tempfile::new("test.txt")
77
- src = 'hoge'
78
- replace = 'fuga'
79
- erase = 'hoge'
80
- expect = "fuga\n"
81
+ let(:src) { 'hoge' }
82
+ let(:try) { 'fuga' }
83
+ let(:expected) { "fuga\n" }
81
84
 
82
- 3.times do
83
- File.append_line(:file => @testfile.path, :str => src)
84
- end
85
- File.replace_line(:file => @testfile.path, :src => src, :dst => replace)
86
- 2.times do
87
- File.append_line(:file => @testfile.path, :str => src)
85
+ it 'should replace line in file' do
86
+ subject
87
+
88
+ open(@testfile.path) { |file|
89
+ while line = file.gets
90
+ expect(line).to eql expected
91
+ end
92
+ }
93
+ @testfile.close
88
94
  end
89
- File.remove_line(:file => @testfile.path, :str => erase)
95
+ end
96
+ end
97
+
98
+ describe '#remove_line' do
99
+ context 'with arguments file and strings' do
90
100
 
91
- open(@testfile.path) { |file|
92
- while line = file.gets
93
- line.should == expect
101
+ subject {
102
+ @testfile = Tempfile::new("test.txt")
103
+ 3.times do
104
+ File.append_line(:file => @testfile.path, :str => src)
94
105
  end
106
+ File.replace_line(:file => @testfile.path, :src => src, :dst => replace)
107
+ 2.times do
108
+ File.append_line(:file => @testfile.path, :str => src)
109
+ end
110
+ File.remove_line(:file => @testfile.path, :str => erase)
95
111
  }
96
- @testfile.close
112
+
113
+ let(:src) { 'hoge' }
114
+ let(:replace) { 'fuga' }
115
+ let(:erase) { 'hoge' }
116
+ let(:expected) { "fuga\n" }
117
+
118
+ it 'should remove line from file' do
119
+ subject
120
+
121
+ open(@testfile.path) { |file|
122
+ while line = file.gets
123
+ expect(line).to eql expected
124
+ end
125
+ }
126
+ @testfile.close
127
+ end
97
128
  end
98
129
  end
99
130
 
100
- context 'new_line メソッドを呼ぶと' do
101
- it "文字列行のファイルが新規作成される" do
102
- @testfile = Tempfile::new("test.txt")
103
- init = 'init'
104
- second = 'second'
105
- expect = "second\n"
131
+ describe '#new_line' do
132
+ context 'with arguments file and strings' do
106
133
 
107
- File.new_line(:file => @testfile.path, :str => init)
108
- File.new_line(:file => @testfile.path, :str => second)
109
-
110
- open(@testfile.path) { |file|
111
- while line = file.gets
112
- line.should == expect
113
- end
134
+ subject {
135
+ @testfile = Tempfile::new("test.txt")
136
+ File.new_line(:file => @testfile.path, :str => init)
137
+ File.new_line(:file => @testfile.path, :str => second)
114
138
  }
115
- @testfile.close
139
+
140
+ let(:init) { 'init' }
141
+ let(:second) { 'second' }
142
+ let(:expect) { "second\n" }
143
+
144
+ it 'should create file of string lines' do
145
+ subject
146
+
147
+ open(@testfile.path) { |file|
148
+ while line = file.gets
149
+ line.should == expect
150
+ end
151
+ }
152
+ @testfile.close
153
+ end
116
154
  end
117
155
  end
118
156
  end
@@ -2,18 +2,23 @@
2
2
 
3
3
  require File.dirname(__FILE__) + '/../../spec_helper'
4
4
 
5
- describe Sysadmin::TimeExtension, 'Time クラス拡張' do
6
- context 'strict_parse メソッドを呼ぶ場合' do
7
- describe '有効な日付を指定すると' do
8
- it "日付が返却される" do
9
- expect = Time.parse("2012/09/27 11:45:00")
10
- Time.strict_parse("2012/09/27 11:45:00").should == expect
5
+ describe Time do
6
+ describe '#strict_parse' do
7
+ context 'with valid date' do
8
+ subject { Time.strict_parse("2012/09/27 11:45:00") }
9
+
10
+ let(:expected) { Time.parse("2012/09/27 11:45:00") }
11
+
12
+ it 'should be returned valid date' do
13
+ expect(subject).to eql expected
11
14
  end
12
15
  end
13
16
 
14
- describe '無効な日付を指定すると' do
15
- it "nil が返却される" do
16
- Time.strict_parse("hoge").should be_nil
17
+ context 'with invalid date' do
18
+ subject { Time.strict_parse("hoge") }
19
+
20
+ it 'should be returned nil' do
21
+ expect(subject).to be_nil
17
22
  end
18
23
  end
19
24
  end
@@ -3,14 +3,15 @@
3
3
  require File.dirname(__FILE__) + '/../../spec_helper'
4
4
 
5
5
  describe Sysadmin::Util do
6
- context 'create_multi_dimensional_hash メソッドを呼ぶ場合' do
7
- describe '引数を付けずに呼ぶと' do
8
- it "多次元ハッシュが返る" do
6
+ describe '#create_multi_dimensional_hash' do
7
+ context 'with no arguments' do
8
+ subject {
9
9
  h = Sysadmin::Util.create_multi_dimensional_hash
10
10
  h["a"]["b"]["c"]["d"] = 10
11
- h["a"]["b"]["c"]["e"] = 15
12
- h["a"]["b"]["c"]["d"].should == 10
13
- h["a"]["b"]["c"]["e"].should == 15
11
+ }
12
+
13
+ it 'should be returned multi dimensional hash' do
14
+ expect(subject).to eql 10
14
15
  end
15
16
  end
16
17
  end
@@ -2,12 +2,10 @@
2
2
 
3
3
  require File.dirname(__FILE__) + '/../spec_helper'
4
4
 
5
- describe Sysadmin, 'sysadmin' do
6
- context 'のバージョンを参照した場合' do
7
- it "バージョンが正しく表示される" do
8
- expect = '0.1.5'
9
- Sysadmin.const_get(:VERSION).should be_true
10
- Sysadmin.const_get(:VERSION).should == expect
11
- end
5
+ describe Sysadmin do
6
+ context "VERSION" do
7
+ subject { Sysadmin::VERSION }
8
+
9
+ it { expect(subject).to eql "0.2.0" }
12
10
  end
13
11
  end
@@ -2,15 +2,15 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: sysadmin 0.1.5 ruby lib
5
+ # stub: sysadmin 0.2.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "sysadmin"
9
- s.version = "0.1.5"
9
+ s.version = "0.2.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.authors = ["id774"]
13
- s.date = "2013-10-08"
13
+ s.date = "2013-11-22"
14
14
  s.description = "The general-purpose library for system administrations"
15
15
  s.email = "idnanashi@gmail.com"
16
16
  s.extra_rdoc_files = [
@@ -35,6 +35,7 @@ Gem::Specification.new do |s|
35
35
  "lib/sysadmin/file_ext.rb",
36
36
  "lib/sysadmin/time_ext.rb",
37
37
  "lib/sysadmin/util.rb",
38
+ "lib/sysadmin/version.rb",
38
39
  "script/.gitkeep",
39
40
  "script/build",
40
41
  "spec/lib/sysadmin/array_ext_spec.rb",
@@ -60,7 +61,7 @@ Gem::Specification.new do |s|
60
61
  s.homepage = "http://github.com/id774/sysadmin"
61
62
  s.licenses = ["GPL"]
62
63
  s.require_paths = ["lib"]
63
- s.rubygems_version = "2.1.5"
64
+ s.rubygems_version = "2.1.9"
64
65
  s.summary = "Sysadmin"
65
66
 
66
67
  if s.respond_to? :specification_version then
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sysadmin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - id774
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-08 00:00:00.000000000 Z
11
+ date: 2013-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cucumber
@@ -77,6 +77,7 @@ files:
77
77
  - lib/sysadmin/file_ext.rb
78
78
  - lib/sysadmin/time_ext.rb
79
79
  - lib/sysadmin/util.rb
80
+ - lib/sysadmin/version.rb
80
81
  - script/.gitkeep
81
82
  - script/build
82
83
  - spec/lib/sysadmin/array_ext_spec.rb
@@ -118,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
119
  version: '0'
119
120
  requirements: []
120
121
  rubyforge_project:
121
- rubygems_version: 2.1.5
122
+ rubygems_version: 2.1.9
122
123
  signing_key:
123
124
  specification_version: 4
124
125
  summary: Sysadmin