rush 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__) + '/base'
2
+ require 'shell'
3
+
4
+ describe Rush::Shell do
5
+ before do
6
+ @shell = Rush::Shell.new
7
+ end
8
+
9
+ it "matches open path commands for readline tab completion" do
10
+ @shell.path_parts("dir['app").should == [ "dir", "'", "app" ]
11
+ end
12
+ end
@@ -0,0 +1,106 @@
1
+ require File.dirname(__FILE__) + '/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.and_return('7771') # avoid infinite loop
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
+ :stall_command => 'sleep 9000'
63
+ }
64
+ end
65
+
66
+ it "constructs the bash ssh command from the options hash" do
67
+ @tunnel.should_receive(:tunnel_options).at_least(:once).and_return(
68
+ :local_port => 123,
69
+ :remote_port => 456,
70
+ :ssh_host => 'example.com',
71
+ :stall_command => 'stall'
72
+ )
73
+ @tunnel.ssh_tunnel_command.should == "ssh -f -L 123:127.0.0.1:456 example.com \"stall\""
74
+ end
75
+
76
+ it "ssh_tunnel_command request that the port be set" do
77
+ @tunnel.should_receive(:tunnel_options).at_least(:once).and_return(:local_port => nil)
78
+ lambda { @tunnel.ssh_tunnel_command }.should raise_error(Rush::SshTunnel::NoPortSelectedYet)
79
+ end
80
+
81
+
82
+ it "push_credentials uses ssh to append to remote host's passwords file" do
83
+ @tunnel.should_receive(:ssh_append_to_credentials).and_return(true)
84
+ @tunnel.push_credentials
85
+ end
86
+
87
+ it "launches rushd on the remote host via ssh" do
88
+ @tunnel.should_receive(:ssh) do |cmd|
89
+ cmd.should match(/rushd/)
90
+ end
91
+ @tunnel.launch_rushd
92
+ end
93
+
94
+ it "tunnel_alive? checks whether a tunnel is still up" do
95
+ @tunnel.should_receive(:tunnel_count_command).and_return("echo 1")
96
+ @tunnel.tunnel_alive?.should be_true
97
+ end
98
+
99
+ it "tunnel_count_command greps ps to find the ssh tunnel" do
100
+ @tunnel.should_receive(:ssh_tunnel_command_without_stall).and_return('ssh command')
101
+ command = @tunnel.tunnel_count_command
102
+ command.should match(/ps/)
103
+ command.should match(/grep/)
104
+ command.should match(/ssh command/)
105
+ end
106
+ end
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + '/base'
2
+
3
+ describe String do
4
+ before do
5
+ @string = "abc"
6
+ end
7
+
8
+ it "heads from the front of the string" do
9
+ @string.head(1).should == 'a'
10
+ end
11
+
12
+ it "tails from the back of the string" do
13
+ @string.tail(1).should == 'c'
14
+ end
15
+
16
+ it "gives the whole string when head exceeds length" do
17
+ @string.head(999).should == @string
18
+ end
19
+
20
+ it "gives the whole string when tail exceeds length" do
21
+ @string.tail(999).should == @string
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rush
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - Adam Wiggins
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-02-20 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: A Ruby replacement for bash+ssh, providing both an interactive shell and a library. Manage both local and remote unix systems from a single client.
17
+ email: adam@heroku.com
18
+ executables:
19
+ - rush
20
+ - rushd
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - Rakefile
27
+ - bin/rush
28
+ - bin/rushd
29
+ - lib/rush
30
+ - lib/rush/array_ext.rb
31
+ - lib/rush/box.rb
32
+ - lib/rush/commands.rb
33
+ - lib/rush/config.rb
34
+ - lib/rush/dir.rb
35
+ - lib/rush/entry.rb
36
+ - lib/rush/file.rb
37
+ - lib/rush/fixnum_ext.rb
38
+ - lib/rush/head_tail.rb
39
+ - lib/rush/local.rb
40
+ - lib/rush/process.rb
41
+ - lib/rush/remote.rb
42
+ - lib/rush/search_results.rb
43
+ - lib/rush/server.rb
44
+ - lib/rush/shell.rb
45
+ - lib/rush/ssh_tunnel.rb
46
+ - lib/rush/string_ext.rb
47
+ - lib/rush.rb
48
+ - spec/array_ext_spec.rb
49
+ - spec/base.rb
50
+ - spec/box_spec.rb
51
+ - spec/commands_spec.rb
52
+ - spec/config_spec.rb
53
+ - spec/dir_spec.rb
54
+ - spec/entry_spec.rb
55
+ - spec/file_spec.rb
56
+ - spec/fixnum_ext_spec.rb
57
+ - spec/local_spec.rb
58
+ - spec/process_spec.rb
59
+ - spec/remote_spec.rb
60
+ - spec/search_results_spec.rb
61
+ - spec/shell_spec.rb
62
+ - spec/ssh_tunnel_spec.rb
63
+ - spec/string_ext_spec.rb
64
+ has_rdoc: true
65
+ homepage: http://rush.heroku.com/
66
+ post_install_message:
67
+ rdoc_options: []
68
+
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ requirements: []
84
+
85
+ rubyforge_project: ruby-shell
86
+ rubygems_version: 1.0.1
87
+ signing_key:
88
+ specification_version: 2
89
+ summary: A Ruby replacement for bash+ssh.
90
+ test_files: []
91
+