rush2 0.7.1 → 0.8.0

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.
@@ -1,47 +1,47 @@
1
1
  require_relative 'base'
2
2
 
3
3
  describe Rush::Commands do
4
- before do
5
- @sandbox_dir = "/tmp/rush_spec.#{Process.pid}"
6
- system "rm -rf #{@sandbox_dir}; mkdir -p #{@sandbox_dir}"
7
-
8
- @filename = "test_file"
9
- system "echo thing_to_find > #{@sandbox_dir}/#{@filename}"
10
- system "echo dont_find_me > #{@sandbox_dir}/some_other_file"
11
-
12
- @dir = Rush::Dir.new(@sandbox_dir)
13
- @array = @dir.files
14
- end
15
-
16
- after do
17
- system "rm -rf #{@sandbox_dir}"
18
- end
19
-
20
- it "searches a list of files" do
21
- results = @dir.files.search(/thing_to_find/)
22
- results.should be_kind_of(Rush::SearchResults)
23
- results.entries.should == [ @dir[@filename] ]
24
- results.lines.should == [ "thing_to_find" ]
25
- end
26
-
27
- it "searches a dir" do
28
- @dir.search(/thing_to_find/).entries.should == [ @dir[@filename] ]
29
- end
30
-
31
- it "searchs a dir's nested files" do
32
- @dir.create_dir('sub').create_file('file').write('nested')
33
- @dir['**'].search(/nested/).entries.should == [ @dir['sub/file'] ]
34
- end
35
-
36
- it "search and replace contents on all files in the glob" do
37
- @dir['1'].create.write('xax')
38
- @dir['2'].create.write('-a-')
39
- @dir.replace_contents!(/a/, 'b')
40
- @dir['1'].contents.should == "xbx"
41
- @dir['2'].contents.should == "-b-"
42
- end
43
-
44
- it "counts lines of the contained files" do
45
- @dir.files.line_count.should == 2
46
- end
4
+ before do
5
+ @sandbox_dir = "/tmp/rush_spec.#{Process.pid}"
6
+ system "rm -rf #{@sandbox_dir}; mkdir -p #{@sandbox_dir}"
7
+
8
+ @filename = 'test_file'
9
+ system "echo thing_to_find > #{@sandbox_dir}/#{@filename}"
10
+ system "echo dont_find_me > #{@sandbox_dir}/some_other_file"
11
+
12
+ @dir = Rush::Dir.new(@sandbox_dir)
13
+ @array = @dir.files
14
+ end
15
+
16
+ after do
17
+ system "rm -rf #{@sandbox_dir}"
18
+ end
19
+
20
+ it 'searches a list of files' do
21
+ results = @dir.files.search(/thing_to_find/)
22
+ expect(results).to be_kind_of(Rush::SearchResults)
23
+ expect(results.entries).to eq [@dir[@filename]]
24
+ expect(results.lines).to eq ['thing_to_find']
25
+ end
26
+
27
+ it 'searches a dir' do
28
+ expect(@dir.search(/thing_to_find/).entries).to eq [@dir[@filename]]
29
+ end
30
+
31
+ it 'searchs a dir\'s nested files' do
32
+ @dir.create_dir('sub').create_file('file').write('nested')
33
+ expect(@dir['**'].search(/nested/).entries).to eq [@dir['sub/file']]
34
+ end
35
+
36
+ it 'search and replace contents on all files in the glob' do
37
+ @dir['1'].create.write('xax')
38
+ @dir['2'].create.write('-a-')
39
+ @dir.replace_contents!(/a/, 'b')
40
+ expect(@dir['1'].contents).to eq 'xbx'
41
+ expect(@dir['2'].contents).to eq '-b-'
42
+ end
43
+
44
+ it 'counts lines of the contained files' do
45
+ expect(@dir.files.line_count).to eq 2
46
+ end
47
47
  end
@@ -6,12 +6,12 @@ describe Rush::EmbeddableShell do
6
6
  end
7
7
 
8
8
  it "should execute unknown methods against a Rush::Shell instance" do
9
- @shell.root.class.should == Rush::Dir
9
+ expect(@shell.root.class).to eq(Rush::Dir)
10
10
  end
11
11
 
12
12
  it "should executes a block as if it were inside the shell" do
13
- @shell.execute_in_shell {
14
- root.class.should == Rush::Dir
15
- }
13
+ expect(@shell.execute_in_shell {
14
+ root.class
15
+ }).to eq Rush::Dir
16
16
  end
17
17
  end
@@ -1,133 +1,133 @@
1
1
  require_relative 'base'
2
2
 
3
3
  describe Rush::Entry do
4
- before do
5
- @sandbox_dir = "/tmp/rush_spec.#{Process.pid}/"
6
- system "rm -rf #{@sandbox_dir}; mkdir -p #{@sandbox_dir}"
4
+ before do
5
+ @sandbox_dir = "/tmp/rush_spec.#{Process.pid}/"
6
+ system "rm -rf #{@sandbox_dir}; mkdir -p #{@sandbox_dir}"
7
7
 
8
- @filename = "#{@sandbox_dir}/test_file"
9
- system "touch #{@filename}"
8
+ @filename = "#{@sandbox_dir}/test_file"
9
+ system "touch #{@filename}"
10
10
 
11
- @entry = Rush::Entry.new(@filename)
12
- end
11
+ @entry = Rush::Entry.new(@filename)
12
+ end
13
13
 
14
- after do
15
- system "rm -rf #{@sandbox_dir}"
16
- end
14
+ after do
15
+ system "rm -rf #{@sandbox_dir}"
16
+ end
17
17
 
18
- it "knows its name" do
19
- @entry.name.should == File.basename(@filename)
20
- end
18
+ it 'knows its name' do
19
+ expect(@entry.name).to eq File.basename(@filename)
20
+ end
21
21
 
22
- it "knows its parent dir" do
23
- @entry.parent.should be_kind_of(Rush::Dir)
24
- @entry.parent.name.should == File.basename(@sandbox_dir)
25
- @entry.parent.full_path.should == @sandbox_dir
26
- end
27
-
28
- it "cleans its pathname" do
29
- Rush::Entry.new('/a//b//c').full_path.should == '/a/b/c'
30
- Rush::Entry.new('/1/2/../3').full_path.should == '/1/3'
31
- end
32
-
33
- it "knows its changed_at time" do
34
- @entry.changed_at.should == File.stat(@filename).ctime
35
- end
36
-
37
- it "knows its last_modified time" do
38
- @entry.last_modified.should == File.stat(@filename).mtime
39
- end
40
-
41
- it "knows its last_accessed time" do
42
- @entry.last_accessed.should == File.stat(@filename).atime
43
- end
44
-
45
- it "considers itself equal to other instances with the same full path" do
46
- Rush::Entry.new('/not/the/same').should_not == @entry
47
- Rush::Entry.new(@entry.full_path).should == @entry
48
- end
49
-
50
- it "can rename itself" do
51
- new_file = "test2"
52
-
53
- @entry.rename(new_file)
54
-
55
- File.exists?(@filename).should be_false
56
- File.exists?("#{@sandbox_dir}/#{new_file}").should be_true
57
- end
58
-
59
- it "rename returns the renamed file" do
60
- @entry.rename('file2').should == @entry.parent['file2']
61
- end
62
-
63
- it "can't rename itself if another file already exists with that name" do
64
- new_file = "test3"
65
- system "touch #{@sandbox_dir}/#{new_file}"
66
-
67
- lambda { @entry.rename(new_file) }.should raise_error(Rush::NameAlreadyExists, /#{new_file}/)
68
- end
69
-
70
- it "can't rename itself to something with a slash in it" do
71
- lambda { @entry.rename('has/slash') }.should raise_error(Rush::NameCannotContainSlash, /slash/)
72
- end
73
-
74
- it "can duplicate itself within the directory" do
75
- @entry.duplicate('newfile').should == Rush::File.new("#{@sandbox_dir}/newfile")
76
- end
77
-
78
- it "can move itself to another dir" do
79
- newdir = "#{@sandbox_dir}/newdir"
80
- system "mkdir -p #{newdir}"
81
-
82
- dst = Rush::Dir.new(newdir)
83
- @entry.move_to(dst)
84
-
85
- File.exists?(@filename).should be_false
86
- File.exists?("#{newdir}/#{@entry.name}").should be_true
87
- end
88
-
89
- it "can copy itself to another directory" do
90
- newdir = "#{@sandbox_dir}/newdir"
91
- system "mkdir -p #{newdir}"
92
-
93
- dst = Rush::Dir.new(newdir)
94
- @copied_dir = @entry.copy_to(dst)
95
-
96
- File.exists?(@filename).should be_true
97
- File.exists?("#{newdir}/#{@entry.name}").should be_true
98
-
99
- @copied_dir.full_path.should == "#{@sandbox_dir}newdir/#{@entry.name}"
100
- end
101
-
102
- it "considers dotfiles to be hidden" do
103
- Rush::Entry.new("#{@sandbox_dir}/show").should_not be_hidden
104
- Rush::Entry.new("#{@sandbox_dir}/.dont_show").should be_hidden
105
- end
22
+ it 'knows its parent dir' do
23
+ expect(@entry.parent).to be_kind_of(Rush::Dir)
24
+ expect(@entry.parent.name).to eq File.basename(@sandbox_dir)
25
+ expect(@entry.parent.full_path).to eq @sandbox_dir
26
+ end
27
+
28
+ it 'cleans its pathname' do
29
+ expect(Rush::Entry.new('/a//b//c').full_path).to eq '/a/b/c'
30
+ expect(Rush::Entry.new('/1/2/../3').full_path).to eq '/1/3'
31
+ end
32
+
33
+ it 'knows its changed_at time' do
34
+ expect(@entry.changed_at).to eq File.stat(@filename).ctime
35
+ end
36
+
37
+ it 'knows its last_modified time' do
38
+ expect(@entry.last_modified).to eq File.stat(@filename).mtime
39
+ end
40
+
41
+ it 'knows its last_accessed time' do
42
+ expect(@entry.last_accessed).to eq File.stat(@filename).atime
43
+ end
44
+
45
+ it 'considers itself equal to other instances with the same full path' do
46
+ expect(Rush::Entry.new('/not/the/same')).to_not eq @entry
47
+ expect(Rush::Entry.new(@entry.full_path)).to eq @entry
48
+ end
49
+
50
+ it 'can rename itself' do
51
+ new_file = 'test2'
52
+
53
+ @entry.rename(new_file)
54
+
55
+ expect(File.exist?(@filename)).to eq false
56
+ expect(File.exist?("#{@sandbox_dir}/#{new_file}")).to eq true
57
+ end
58
+
59
+ it 'rename returns the renamed file' do
60
+ expect(@entry.rename('file2')).to eq @entry.parent['file2']
61
+ end
62
+
63
+ it 'can\'t rename itself if another file already exists with that name' do
64
+ new_file = 'test3'
65
+ system "touch #{@sandbox_dir}/#{new_file}"
66
+
67
+ expect { @entry.rename(new_file) }.to raise_error(Rush::NameAlreadyExists, /#{new_file}/)
68
+ end
69
+
70
+ it "can't rename itself to something with a slash in it" do
71
+ expect { @entry.rename('has/slash') }.to raise_error(Rush::NameCannotContainSlash, /slash/)
72
+ end
73
+
74
+ it 'can duplicate itself within the directory' do
75
+ expect(@entry.duplicate('newfile')).to eq Rush::File.new("#{@sandbox_dir}/newfile")
76
+ end
77
+
78
+ it 'can move itself to another dir' do
79
+ newdir = "#{@sandbox_dir}/newdir"
80
+ system "mkdir -p #{newdir}"
81
+
82
+ dst = Rush::Dir.new(newdir)
83
+ @entry.move_to(dst)
84
+
85
+ expect(File.exist?(@filename)).to eq false
86
+ expect(File.exist?("#{newdir}/#{@entry.name}")).to eq true
87
+ end
88
+
89
+ it 'can copy itself to another directory' do
90
+ newdir = "#{@sandbox_dir}/newdir"
91
+ system "mkdir -p #{newdir}"
92
+
93
+ dst = Rush::Dir.new(newdir)
94
+ @copied_dir = @entry.copy_to(dst)
95
+
96
+ expect(File.exist?(@filename)).to eq true
97
+ expect(File.exist?("#{newdir}/#{@entry.name}")).to eq true
98
+
99
+ expect(@copied_dir.full_path).to eq "#{@sandbox_dir}newdir/#{@entry.name}"
100
+ end
101
+
102
+ it 'considers dotfiles to be hidden' do
103
+ expect(Rush::Entry.new("#{@sandbox_dir}/show")).to_not be_hidden
104
+ expect(Rush::Entry.new("#{@sandbox_dir}/.dont_show")).to be_hidden
105
+ end
106
106
 
107
- it "is considered equal to entries with the same full path and on the same box" do
108
- same = Rush::Entry.new(@entry.full_path, @entry.box)
109
- @entry.should == same
110
- end
111
-
112
- it "is considered not equal to entries with the same full path on a different box" do
113
- same = Rush::Entry.new(@entry.full_path, Rush::Box.new('dummy'))
114
- @entry.should_not == same
115
- end
116
-
117
- it "can mimic another entry" do
118
- copy = Rush::Entry.new('abc', :dummy)
119
- copy.mimic(@entry)
120
- copy.path.should == @entry.path
121
- end
122
-
123
- it "can update the read access permission" do
124
- system "chmod 666 #{@filename}"
125
- @entry.access = { :user_can => :read }
126
- `ls -l #{@filename}`.should match(/^-r--------/)
127
- end
128
-
129
- it "reads the file permissions in the access hash" do
130
- system "chmod 640 #{@filename}"
131
- @entry.access.should == { :user_can_read => true, :user_can_write => true, :group_can_read => true }
132
- end
107
+ it 'is considered equal to entries with the same full path and on the same box' do
108
+ same = Rush::Entry.new(@entry.full_path, @entry.box)
109
+ expect(@entry).to eq same
110
+ end
111
+
112
+ it 'is considered not equal to entries with the same full path on a different box' do
113
+ same = Rush::Entry.new(@entry.full_path, Rush::Box.new('dummy'))
114
+ expect(@entry).to_not eq same
115
+ end
116
+
117
+ it 'can mimic another entry' do
118
+ copy = Rush::Entry.new('abc', :dummy)
119
+ copy.mimic(@entry)
120
+ expect(copy.path).to eq @entry.path
121
+ end
122
+
123
+ it 'can update the read access permission' do
124
+ system "chmod 666 #{@filename}"
125
+ @entry.access = { :user_can => :read }
126
+ expect(`ls -l #{@filename}`).to match(/^-r--------/)
127
+ end
128
+
129
+ it 'reads the file permissions in the access hash' do
130
+ system "chmod 640 #{@filename}"
131
+ expect(@entry.access).to eq({ user_can_read: true, user_can_write: true, group_can_read: true })
132
+ end
133
133
  end
@@ -1,83 +1,83 @@
1
1
  require_relative 'base'
2
2
 
3
3
  describe Rush::File do
4
- before do
5
- @sandbox_dir = "/tmp/rush_spec.#{Process.pid}"
6
- system "rm -rf #{@sandbox_dir}; mkdir -p #{@sandbox_dir}"
7
-
8
- @filename = "#{@sandbox_dir}/test_file"
9
- @contents = "1234"
10
- system "echo #{@contents} > #{@filename}"
11
- @contents += "\n"
12
-
13
- @file = Rush::File.new(@filename)
14
- end
15
-
16
- after do
17
- system "rm -rf #{@sandbox_dir}"
18
- end
19
-
20
- it "is a child of Rush::Entry" do
21
- @file.should be_kind_of(Rush::Entry)
22
- end
23
-
24
- it "is not a dir" do
25
- @file.should_not be_dir
26
- end
27
-
28
- it "can create itself as a blank file, and return itself" do
29
- create_me = Rush::File.new("#{@sandbox_dir}/create_me")
30
- create_me.create.should == create_me
31
- File.exists?("#{@sandbox_dir}/create_me").should == true
32
- end
33
-
34
- it "knows its size in bytes" do
35
- @file.size.should == @contents.length
36
- end
37
-
38
- it "can read its contents" do
39
- @file.contents.should == @contents
40
- end
41
-
42
- it "read is an alias for contents" do
43
- @file.read.should == @contents
44
- end
45
-
46
- it "can write new contents" do
47
- @file.write('write test')
48
- @file.contents.should == 'write test'
49
- end
50
-
51
- it "can count the number of lines it contains" do
52
- @file.write("1\n2\n3\n")
53
- @file.line_count.should == 3
54
- end
55
-
56
- it "searches its contents for matching lines" do
57
- @file.write("a\n1\nb\n2\n")
58
- @file.search(/\d/).should == %w(1 2)
59
- end
60
-
61
- it "search returns nil if no lines match" do
62
- @file.write("a\nb\nc\n")
63
- @file.search(/\d/).should be_nil
64
- end
65
-
66
- it "find-in-file replace" do
67
- @file.replace_contents!(/\d/, 'x')
68
- @file.contents.should == "xxxx\n"
69
- end
70
-
71
- it "can destroy itself" do
72
- @file.destroy
73
- ::File.exists?(@filename).should be_false
74
- end
75
-
76
- it "can fetch contents or blank if doesn't exist" do
77
- Rush::File.new('/does/not/exist').contents_or_blank.should == ""
78
- end
79
-
80
- it "can fetch lines, or empty if doesn't exist" do
81
- Rush::File.new('/does/not/exist').lines_or_empty.should == []
82
- end
4
+ before do
5
+ @sandbox_dir = "/tmp/rush_spec.#{Process.pid}"
6
+ system "rm -rf #{@sandbox_dir}; mkdir -p #{@sandbox_dir}"
7
+
8
+ @filename = "#{@sandbox_dir}/test_file"
9
+ @contents = '1234'
10
+ system "echo #{@contents} > #{@filename}"
11
+ @contents += "\n"
12
+
13
+ @file = Rush::File.new(@filename)
14
+ end
15
+
16
+ after do
17
+ system "rm -rf #{@sandbox_dir}"
18
+ end
19
+
20
+ it 'is a child of Rush::Entry' do
21
+ expect(@file).to be_kind_of(Rush::Entry)
22
+ end
23
+
24
+ it 'is not a dir' do
25
+ expect(@file).to_not be_dir
26
+ end
27
+
28
+ it 'can create itself as a blank file, and return itself' do
29
+ create_me = Rush::File.new("#{@sandbox_dir}/create_me")
30
+ expect(create_me.create).to eq create_me
31
+ expect(File.exist?("#{@sandbox_dir}/create_me")).to eq true
32
+ end
33
+
34
+ it 'knows its size in bytes' do
35
+ expect(@file.size).to eq @contents.length
36
+ end
37
+
38
+ it 'can read its contents' do
39
+ expect(@file.contents).to eq @contents
40
+ end
41
+
42
+ it 'read is an alias for contents' do
43
+ expect(@file.read).to eq @contents
44
+ end
45
+
46
+ it 'can write new contents' do
47
+ @file.write('write test')
48
+ expect(@file.contents).to eq 'write test'
49
+ end
50
+
51
+ it 'can count the number of lines it contains' do
52
+ @file.write("1\n2\n3\n")
53
+ expect(@file.line_count).to eq 3
54
+ end
55
+
56
+ it 'searches its contents for matching lines' do
57
+ @file.write("a\n1\nb\n2\n")
58
+ expect(@file.search(/\d/)).to eq %w(1 2)
59
+ end
60
+
61
+ it 'search returns nil if no lines match' do
62
+ @file.write("a\nb\nc\n")
63
+ expect(@file.search(/\d/)).to eq nil
64
+ end
65
+
66
+ it 'find-in-file replace' do
67
+ @file.replace_contents!(/\d/, 'x')
68
+ expect(@file.contents).to eq "xxxx\n"
69
+ end
70
+
71
+ it 'can destroy itself' do
72
+ @file.destroy
73
+ expect(::File.exist?(@filename)).to eq false
74
+ end
75
+
76
+ it "can fetch contents or blank if doesn't exist" do
77
+ expect(Rush::File.new('/does/not/exist').contents_or_blank).to eq ''
78
+ end
79
+
80
+ it 'can fetch lines, or empty if doesn\'t exist' do
81
+ expect(Rush::File.new('/does/not/exist').lines_or_empty).to eq []
82
+ end
83
83
  end