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,50 +1,50 @@
1
1
  require_relative 'base'
2
2
 
3
3
  describe Rush::ProcessSet do
4
- before do
5
- @process = double('process')
6
- @set = Rush::ProcessSet.new([ @process ])
7
- end
8
-
9
- it "is Enumerable" do
10
- @set.select { |s| s == @process }.should == [ @process ]
11
- end
12
-
13
- it "defines size" do
14
- @set.size.should == 1
15
- end
16
-
17
- it "defines first" do
18
- @set.first.should == @process
19
- end
20
-
21
- it "is equal to sets with the same contents" do
22
- @set.should == Rush::ProcessSet.new([ @process ])
23
- end
24
-
25
- it "is equal to arrays with the same contents" do
26
- @set.should == [ @process ]
27
- end
28
-
29
- it "kills all processes in the set" do
30
- @process.should_receive(:kill)
31
- @set.kill
32
- end
33
-
34
- it "checks the alive? state of all processes in the set" do
35
- @process.should_receive(:alive?).and_return(true)
36
- @set.alive?.should == [ true ]
37
- end
38
-
39
- it "filters the set from a conditions hash and returns the filtered set" do
40
- @process.stub(:pid).and_return(123)
41
- @set.filter(:pid => 123).first.should == @process
42
- @set.filter(:pid => 456).size.should == 0
43
- end
44
-
45
- it "filters with regexps if provided in the conditions" do
46
- @process.stub(:command).and_return('foobaz')
47
- @set.filter(:command => /baz/).first.should == @process
48
- @set.filter(:command => /blerg/).size.should == 0
49
- end
4
+ before do
5
+ @process = double('process')
6
+ @set = Rush::ProcessSet.new([ @process ])
7
+ end
8
+
9
+ it "is Enumerable" do
10
+ expect(@set.select { |s| s == @process }).to eq [ @process ]
11
+ end
12
+
13
+ it "defines size" do
14
+ expect(@set.size).to eq 1
15
+ end
16
+
17
+ it "defines first" do
18
+ expect(@set.first).to eq @process
19
+ end
20
+
21
+ it "is equal to sets with the same contents" do
22
+ expect(@set).to eq Rush::ProcessSet.new([ @process ])
23
+ end
24
+
25
+ it "is equal to arrays with the same contents" do
26
+ expect(@set).to eq [ @process ]
27
+ end
28
+
29
+ it "kills all processes in the set" do
30
+ expect(@process).to receive(:kill)
31
+ @set.kill
32
+ end
33
+
34
+ it "checks the alive? state of all processes in the set" do
35
+ expect(@process).to receive(:alive?).and_return(true)
36
+ expect(@set.alive?).to eq [ true ]
37
+ end
38
+
39
+ it "filters the set from a conditions hash and returns the filtered set" do
40
+ allow(@process).to receive(:pid).and_return(123)
41
+ expect(@set.filter(:pid => 123).first).to eq @process
42
+ expect(@set.filter(:pid => 456).size).to eq 0
43
+ end
44
+
45
+ it "filters with regexps if provided in the conditions" do
46
+ allow(@process).to receive(:command).and_return('foobaz')
47
+ expect(@set.filter(:command => /baz/).first).to eq @process
48
+ expect(@set.filter(:command => /blerg/).size).to eq 0
49
+ end
50
50
  end
@@ -1,73 +1,75 @@
1
1
  require_relative 'base'
2
2
 
3
3
  describe Rush::Process do
4
- before do
5
- @pid = fork do
6
- sleep 999
7
- end
8
- @process = Rush::Process.all.detect { |p| p.pid == @pid }
9
- end
4
+ before do
5
+ @pid = fork do
6
+ sleep 999
7
+ end
8
+ @process = Rush::Process.all.detect { |p| p.pid == @pid }
9
+ end
10
10
 
11
- after do
12
- system "kill -9 #{@pid}"
13
- end
11
+ after do
12
+ system "kill -9 #{@pid}"
13
+ end
14
14
 
15
- if !RUBY_PLATFORM.match(/darwin/) # OS x reports pids weird
16
- it "knows all its child processes" do
17
- parent = Rush::Process.all.detect { |p| p.pid == Process.pid }
18
- parent.children.should == [ @process ]
19
- end
20
- end
15
+ unless RUBY_PLATFORM.match(/darwin/) # OS x reports pids weird
16
+ it 'knows all its child processes' do
17
+ parent = Rush::Process.all.detect { |p| p.pid == Process.pid }
18
+ expect(parent.children).to eq [@process]
19
+ end
20
+ end
21
21
 
22
- it "gets the list of all processes" do
23
- list = Rush::Process.all
24
- list.size.should > 5
25
- list.first.should be_kind_of(Rush::Process)
26
- end
22
+ it 'gets the list of all processes' do
23
+ list = Rush::Process.all
24
+ expect(list.size).to be > 5
25
+ expect(list.first).to be_kind_of Rush::Process
26
+ end
27
27
 
28
- it "knows the pid" do
29
- @process.pid.should == @pid
30
- end
28
+ it 'knows the pid' do
29
+ expect(@process.pid).to eq @pid
30
+ end
31
31
 
32
- it "knows the uid" do
33
- @process.uid.should == ::Process.uid
34
- end
32
+ it 'knows the uid' do
33
+ expect(@process.uid).to eq ::Process.uid
34
+ end
35
35
 
36
- it "knows the executed binary" do
37
- @process.command.should match(/(ruby|rbx)/)
38
- end
36
+ it 'knows the executed binary' do
37
+ expect(@process.command).to match(/(ruby|rbx)/)
38
+ end
39
39
 
40
- it "knows the command line" do
41
- @process.cmdline.should match(/process_spec.rb/)
42
- end
40
+ it 'knows the command line' do
41
+ expect(@process.cmdline).to match(/rspec/)
42
+ end
43
43
 
44
- it "knows the memory used" do
45
- @process.mem.should > 0
46
- end
44
+ it 'knows the memory used' do
45
+ expect(@process.mem).to be > 0
46
+ end
47
47
 
48
- it "knows the cpu used" do
49
- @process.cpu.should >= 0
50
- end
48
+ it 'knows the cpu used' do
49
+ expect(@process.cpu).to be >= 0
50
+ end
51
51
 
52
- it "knows the parent process pid" do
53
- @process.parent_pid.should == Process.pid
54
- end
52
+ it 'knows the parent process pid' do
53
+ expect(@process.parent_pid).to eq Process.pid
54
+ end
55
55
 
56
- it "knows the parent process" do
57
- this = Rush::Box.new.processes.select { |p| p.pid == Process.pid }.first
58
- @process.parent.should == this
59
- end
56
+ it 'knows the parent process' do
57
+ this = Rush::Box.new.processes
58
+ .select { |p| p.pid == Process.pid }
59
+ .first
60
+ expect(@process.parent).to eq this
61
+ end
60
62
 
61
- it "can kill itself" do
62
- process = Rush.bash("sleep 30", :background => true)
63
- process.alive?.should be_true
64
- process.kill
65
- sleep 0.1
66
- process.alive?.should be_false
67
- end
63
+ it 'can kill itself' do
64
+ process = Rush.bash('sleep 30', background: true)
65
+ expect(process.alive?).to eq true
66
+ process.kill
67
+ sleep 0.1
68
+ expect(process.alive?).to eq false
69
+ end
68
70
 
69
- it "if box and pid are the same, process is equal" do
70
- other = Rush::Process.new({ :pid => @process.pid }, @process.box)
71
- @process.should == other
72
- end
71
+ it 'if box and pid are the same, process is equal' do
72
+ other = Rush::Process.new({ pid: @process.pid }, @process.box)
73
+ expect(@process).to eq other
74
+ end
73
75
  end
@@ -1,28 +1,28 @@
1
1
  require_relative 'base'
2
2
 
3
3
  describe Rush do
4
- it "fetches a local file path" do
5
- Rush['/etc/hosts'].full_path.should == '/etc/hosts'
6
- end
4
+ it 'fetches a local file path' do
5
+ expect(Rush['/etc/hosts'].full_path).to eq('/etc/hosts')
6
+ end
7
7
 
8
- it "fetches the dir of __FILE__" do
9
- Rush.dir(__FILE__).name.should == 'spec'
10
- end
8
+ it 'fetches the dir of __FILE__' do
9
+ expect(Rush.dir(__FILE__).name).to eq('spec')
10
+ end
11
11
 
12
- it "fetches the launch dir (aka current working directory or pwd)" do
13
- Dir.stub(:pwd).and_return('/tmp')
14
- Rush.launch_dir.should == Rush::Box.new['/tmp/']
15
- end
12
+ it 'fetches the launch dir (aka current working directory or pwd)' do
13
+ allow(Dir).to receive(:pwd).and_return('/tmp')
14
+ expect(Rush.launch_dir).to eq(Rush::Box.new['/tmp/'])
15
+ end
16
16
 
17
- it "runs a bash command" do
18
- Rush.bash('echo hi').should == "hi\n"
19
- end
17
+ it 'runs a bash command' do
18
+ expect(Rush.bash('echo hi')).to eq("hi\n")
19
+ end
20
20
 
21
- it "gets the list of local processes" do
22
- Rush.processes.should be_kind_of(Rush::ProcessSet)
23
- end
21
+ it 'gets the list of local processes' do
22
+ expect(Rush.processes).to be_kind_of(Rush::ProcessSet)
23
+ end
24
24
 
25
- it "gets my process" do
26
- Rush.my_process.pid.should == Process.pid
27
- end
25
+ it 'gets my process' do
26
+ expect(Rush.my_process.pid).to eq(Process.pid)
27
+ end
28
28
  end
@@ -23,7 +23,7 @@ describe Rush::Shell do
23
23
  it 'Complete method names' do
24
24
  expect(@shell.complete('Rush.meth')).
25
25
  to eq(["Rush.method_part", "Rush.method_defined?", "Rush.methods", "Rush.method"])
26
- expect(@shell.complete('Rush.methods.inc')).to eq ["Rush.methods.include?"]
26
+ expect(@shell.complete('Rush.methods.inc')).to include "Rush.methods.include?"
27
27
  end
28
28
 
29
29
  it 'Complete paths' do
@@ -1,122 +1,122 @@
1
- require_relative 'base'
2
-
3
- describe Rush::SshTunnel do
4
- before do
5
- @tunnel = Rush::SshTunnel.new('spec.example.com')
6
- @tunnel.stub(:config).and_return(mock_config_start)
7
- @tunnel.stub(:display)
8
- end
9
-
10
- after do
11
- mock_config_cleanup
12
- end
13
-
14
- it "ensure_tunnel sets everything up for the tunnel when one does not already exist" do
15
- @tunnel.should_receive(:push_credentials)
16
- @tunnel.should_receive(:launch_rushd)
17
- @tunnel.should_receive(:establish_tunnel)
18
- @tunnel.ensure_tunnel
19
- end
20
-
21
- it "ensure_tunnel uses the existing port as long as the tunnel is still alive" do
22
- @tunnel.should_receive(:tunnel_alive?).and_return(true)
23
- @tunnel.instance_eval("@port = 2345")
24
- @tunnel.ensure_tunnel
25
- @tunnel.port.should == 2345
26
- end
27
-
28
- it "existing tunnel is used when it is specified in the tunnels file" do
29
- @tunnel.config.tunnels_file.write "spec.example.com:4567\n"
30
- @tunnel.should_receive(:tunnel_alive?).and_return(true)
31
- @tunnel.should_not_receive(:setup_everything)
32
- @tunnel.ensure_tunnel
33
- @tunnel.port.should == 4567
34
- end
35
-
36
- it "tunnel host is always local" do
37
- @tunnel.host.should == 'localhost'
38
- end
39
-
40
- it "picks the first port number when there are no tunnels yet" do
41
- @tunnel.next_available_port.should == 7771
42
- end
43
-
44
- it "picks the next port number when there is already a tunnel" do
45
- @tunnel.config.tunnels_file.write("#{@tunnel.host}:7771")
46
- @tunnel.next_available_port.should == 7772
47
- end
48
-
49
- it "establishes a tunnel and saves it to ~/.rush/tunnels" do
50
- @tunnel.should_receive(:make_ssh_tunnel)
51
- @tunnel.should_receive(:port).exactly(0).times
52
- @tunnel.establish_tunnel
53
- @tunnel.config.tunnels_file.contents.should == "spec.example.com:7771\n"
54
- end
55
-
56
- it "converts instance vars to options hash for ssh_tunnel_command" do
57
- @tunnel.instance_eval("@port = 1234")
58
- @tunnel.tunnel_options.should == {
59
- :local_port => 1234,
60
- :remote_port => 7770,
61
- :ssh_host => 'spec.example.com'
62
- }
63
- end
64
-
65
- it "ssh_stall_command uses an infinite loop for :timeout => :infinite" do
66
- @tunnel.ssh_stall_command(:timeout => :infinite).should match(/while .* sleep .* done/)
67
- end
68
-
69
- it "ssh_stall_command sleeps for the number of seconds given as the :timeout option" do
70
- @tunnel.ssh_stall_command(:timeout => 123).should == "sleep 123"
71
- end
72
-
73
- it "ssh_stall_command uses the default timeout when no options are given" do
74
- @tunnel.ssh_stall_command.should == "sleep 9000"
75
- end
76
-
77
- it "constructs the ssh tunnel command (everything but stall) from the options hash" do
78
- @tunnel.should_receive(:tunnel_options).at_least(:once).and_return(
79
- :local_port => 123,
80
- :remote_port => 456,
81
- :ssh_host => 'example.com'
82
- )
83
- @tunnel.ssh_tunnel_command_without_stall.should == "ssh -f -L 123:127.0.0.1:456 example.com"
84
- end
85
-
86
- it "combines the tunnel command without stall and the stall command into the final command" do
87
- @tunnel.should_receive(:ssh_tunnel_command_without_stall).and_return('ssh command')
88
- @tunnel.should_receive(:ssh_stall_command).and_return('sleep 123')
89
- @tunnel.ssh_tunnel_command.should == 'ssh command "sleep 123"'
90
- end
91
-
92
- it "ssh_tunnel_command request that the port be set" do
93
- @tunnel.should_receive(:tunnel_options).at_least(:once).and_return(:local_port => nil)
94
- lambda { @tunnel.ssh_tunnel_command }.should raise_error(Rush::SshTunnel::NoPortSelectedYet)
95
- end
96
-
97
-
98
- it "push_credentials uses ssh to append to remote host's passwords file" do
99
- @tunnel.should_receive(:ssh_append_to_credentials).and_return(true)
100
- @tunnel.push_credentials
101
- end
102
-
103
- it "launches rushd on the remote host via ssh" do
104
- @tunnel.should_receive(:ssh) do |cmd|
105
- cmd.should match(/rushd/)
106
- end
107
- @tunnel.launch_rushd
108
- end
109
-
110
- it "tunnel_alive? checks whether a tunnel is still up" do
111
- @tunnel.should_receive(:tunnel_count_command).and_return("echo 1")
112
- @tunnel.tunnel_alive?.should be_true
113
- end
114
-
115
- it "tunnel_count_command greps ps to find the ssh tunnel" do
116
- @tunnel.should_receive(:ssh_tunnel_command_without_stall).and_return('ssh command')
117
- command = @tunnel.tunnel_count_command
118
- command.should match(/ps/)
119
- command.should match(/grep/)
120
- command.should match(/ssh command/)
121
- end
122
- end
1
+ # require_relative 'base'
2
+ #
3
+ # describe Rush::SshTunnel do
4
+ # before do
5
+ # @tunnel = Rush::SshTunnel.new('spec.example.com')
6
+ # @tunnel.stub(:config).and_return(mock_config_start)
7
+ # @tunnel.stub(:display)
8
+ # end
9
+ #
10
+ # after do
11
+ # mock_config_cleanup
12
+ # end
13
+ #
14
+ # it "ensure_tunnel sets everything up for the tunnel when one does not already exist" do
15
+ # @tunnel.should_receive(:push_credentials)
16
+ # @tunnel.should_receive(:launch_rushd)
17
+ # @tunnel.should_receive(:establish_tunnel)
18
+ # @tunnel.ensure_tunnel
19
+ # end
20
+ #
21
+ # it "ensure_tunnel uses the existing port as long as the tunnel is still alive" do
22
+ # @tunnel.should_receive(:tunnel_alive?).and_return(true)
23
+ # @tunnel.instance_eval("@port = 2345")
24
+ # @tunnel.ensure_tunnel
25
+ # @tunnel.port.should == 2345
26
+ # end
27
+ #
28
+ # it "existing tunnel is used when it is specified in the tunnels file" do
29
+ # @tunnel.config.tunnels_file.write "spec.example.com:4567\n"
30
+ # @tunnel.should_receive(:tunnel_alive?).and_return(true)
31
+ # @tunnel.should_not_receive(:setup_everything)
32
+ # @tunnel.ensure_tunnel
33
+ # @tunnel.port.should == 4567
34
+ # end
35
+ #
36
+ # it "tunnel host is always local" do
37
+ # @tunnel.host.should == 'localhost'
38
+ # end
39
+ #
40
+ # it "picks the first port number when there are no tunnels yet" do
41
+ # @tunnel.next_available_port.should == 7771
42
+ # end
43
+ #
44
+ # it "picks the next port number when there is already a tunnel" do
45
+ # @tunnel.config.tunnels_file.write("#{@tunnel.host}:7771")
46
+ # @tunnel.next_available_port.should == 7772
47
+ # end
48
+ #
49
+ # it "establishes a tunnel and saves it to ~/.rush/tunnels" do
50
+ # @tunnel.should_receive(:make_ssh_tunnel)
51
+ # @tunnel.should_receive(:port).exactly(0).times
52
+ # @tunnel.establish_tunnel
53
+ # @tunnel.config.tunnels_file.contents.should == "spec.example.com:7771\n"
54
+ # end
55
+ #
56
+ # it "converts instance vars to options hash for ssh_tunnel_command" do
57
+ # @tunnel.instance_eval("@port = 1234")
58
+ # @tunnel.tunnel_options.should == {
59
+ # :local_port => 1234,
60
+ # :remote_port => 7770,
61
+ # :ssh_host => 'spec.example.com'
62
+ # }
63
+ # end
64
+ #
65
+ # it "ssh_stall_command uses an infinite loop for :timeout => :infinite" do
66
+ # @tunnel.ssh_stall_command(:timeout => :infinite).should match(/while .* sleep .* done/)
67
+ # end
68
+ #
69
+ # it "ssh_stall_command sleeps for the number of seconds given as the :timeout option" do
70
+ # @tunnel.ssh_stall_command(:timeout => 123).should == "sleep 123"
71
+ # end
72
+ #
73
+ # it "ssh_stall_command uses the default timeout when no options are given" do
74
+ # @tunnel.ssh_stall_command.should == "sleep 9000"
75
+ # end
76
+ #
77
+ # it "constructs the ssh tunnel command (everything but stall) from the options hash" do
78
+ # @tunnel.should_receive(:tunnel_options).at_least(:once).and_return(
79
+ # :local_port => 123,
80
+ # :remote_port => 456,
81
+ # :ssh_host => 'example.com'
82
+ # )
83
+ # @tunnel.ssh_tunnel_command_without_stall.should == "ssh -f -L 123:127.0.0.1:456 example.com"
84
+ # end
85
+ #
86
+ # it "combines the tunnel command without stall and the stall command into the final command" do
87
+ # @tunnel.should_receive(:ssh_tunnel_command_without_stall).and_return('ssh command')
88
+ # @tunnel.should_receive(:ssh_stall_command).and_return('sleep 123')
89
+ # @tunnel.ssh_tunnel_command.should == 'ssh command "sleep 123"'
90
+ # end
91
+ #
92
+ # it "ssh_tunnel_command request that the port be set" do
93
+ # @tunnel.should_receive(:tunnel_options).at_least(:once).and_return(:local_port => nil)
94
+ # lambda { @tunnel.ssh_tunnel_command }.should raise_error(Rush::SshTunnel::NoPortSelectedYet)
95
+ # end
96
+ #
97
+ #
98
+ # it "push_credentials uses ssh to append to remote host's passwords file" do
99
+ # @tunnel.should_receive(:ssh_append_to_credentials).and_return(true)
100
+ # @tunnel.push_credentials
101
+ # end
102
+ #
103
+ # it "launches rushd on the remote host via ssh" do
104
+ # @tunnel.should_receive(:ssh) do |cmd|
105
+ # cmd.should match(/rushd/)
106
+ # end
107
+ # @tunnel.launch_rushd
108
+ # end
109
+ #
110
+ # it "tunnel_alive? checks whether a tunnel is still up" do
111
+ # @tunnel.should_receive(:tunnel_count_command).and_return("echo 1")
112
+ # @tunnel.tunnel_alive?.should be_true
113
+ # end
114
+ #
115
+ # it "tunnel_count_command greps ps to find the ssh tunnel" do
116
+ # @tunnel.should_receive(:ssh_tunnel_command_without_stall).and_return('ssh command')
117
+ # command = @tunnel.tunnel_count_command
118
+ # command.should match(/ps/)
119
+ # command.should match(/grep/)
120
+ # command.should match(/ssh command/)
121
+ # end
122
+ # end