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.
- checksums.yaml +4 -4
- data/Gemfile.lock +29 -30
- data/VERSION +1 -1
- data/lib/rush.rb +0 -1
- data/lib/rush/commands.rb +24 -6
- data/lib/rush/shell.rb +22 -18
- data/spec/access_spec.rb +34 -34
- data/spec/array_ext_spec.rb +9 -9
- data/spec/box_spec.rb +72 -72
- data/spec/commands_spec.rb +43 -43
- data/spec/embeddable_shell_spec.rb +4 -4
- data/spec/entry_spec.rb +123 -123
- data/spec/file_spec.rb +79 -79
- data/spec/find_by_spec.rb +9 -9
- data/spec/fixnum_ext_spec.rb +3 -3
- data/spec/local_spec.rb +91 -91
- data/spec/process_set_spec.rb +46 -46
- data/spec/process_spec.rb +58 -56
- data/spec/rush_spec.rb +19 -19
- data/spec/shell_spec.rb +1 -1
- data/spec/ssh_tunnel_spec.rb +122 -122
- metadata +3 -5
- data/lib/rush/remote.rb +0 -33
- data/spec/remote_spec.rb +0 -140
data/spec/commands_spec.rb
CHANGED
@@ -1,47 +1,47 @@
|
|
1
1
|
require_relative 'base'
|
2
2
|
|
3
3
|
describe Rush::Commands do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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.
|
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
|
15
|
-
}
|
13
|
+
expect(@shell.execute_in_shell {
|
14
|
+
root.class
|
15
|
+
}).to eq Rush::Dir
|
16
16
|
end
|
17
17
|
end
|
data/spec/entry_spec.rb
CHANGED
@@ -1,133 +1,133 @@
|
|
1
1
|
require_relative 'base'
|
2
2
|
|
3
3
|
describe Rush::Entry do
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
before do
|
5
|
+
@sandbox_dir = "/tmp/rush_spec.#{Process.pid}/"
|
6
|
+
system "rm -rf #{@sandbox_dir}; mkdir -p #{@sandbox_dir}"
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
@filename = "#{@sandbox_dir}/test_file"
|
9
|
+
system "touch #{@filename}"
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
@entry = Rush::Entry.new(@filename)
|
12
|
+
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
after do
|
15
|
+
system "rm -rf #{@sandbox_dir}"
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
it 'knows its name' do
|
19
|
+
expect(@entry.name).to eq File.basename(@filename)
|
20
|
+
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
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
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
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
|
data/spec/file_spec.rb
CHANGED
@@ -1,83 +1,83 @@
|
|
1
1
|
require_relative 'base'
|
2
2
|
|
3
3
|
describe Rush::File do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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
|