adamwiggins-rush 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/README.rdoc +87 -0
  2. data/Rakefile +61 -0
  3. data/VERSION +1 -0
  4. data/bin/rush +13 -0
  5. data/bin/rushd +7 -0
  6. data/lib/rush/access.rb +130 -0
  7. data/lib/rush/array_ext.rb +19 -0
  8. data/lib/rush/box.rb +112 -0
  9. data/lib/rush/commands.rb +55 -0
  10. data/lib/rush/config.rb +154 -0
  11. data/lib/rush/dir.rb +160 -0
  12. data/lib/rush/embeddable_shell.rb +26 -0
  13. data/lib/rush/entry.rb +185 -0
  14. data/lib/rush/exceptions.rb +31 -0
  15. data/lib/rush/file.rb +85 -0
  16. data/lib/rush/find_by.rb +39 -0
  17. data/lib/rush/fixnum_ext.rb +18 -0
  18. data/lib/rush/head_tail.rb +11 -0
  19. data/lib/rush/local.rb +402 -0
  20. data/lib/rush/process.rb +59 -0
  21. data/lib/rush/process_set.rb +62 -0
  22. data/lib/rush/remote.rb +156 -0
  23. data/lib/rush/search_results.rb +58 -0
  24. data/lib/rush/server.rb +117 -0
  25. data/lib/rush/shell.rb +187 -0
  26. data/lib/rush/ssh_tunnel.rb +122 -0
  27. data/lib/rush/string_ext.rb +3 -0
  28. data/lib/rush.rb +87 -0
  29. data/spec/access_spec.rb +134 -0
  30. data/spec/array_ext_spec.rb +15 -0
  31. data/spec/base.rb +24 -0
  32. data/spec/box_spec.rb +64 -0
  33. data/spec/commands_spec.rb +47 -0
  34. data/spec/config_spec.rb +108 -0
  35. data/spec/dir_spec.rb +164 -0
  36. data/spec/embeddable_shell_spec.rb +17 -0
  37. data/spec/entry_spec.rb +133 -0
  38. data/spec/file_spec.rb +83 -0
  39. data/spec/find_by_spec.rb +58 -0
  40. data/spec/fixnum_ext_spec.rb +19 -0
  41. data/spec/local_spec.rb +352 -0
  42. data/spec/process_set_spec.rb +50 -0
  43. data/spec/process_spec.rb +73 -0
  44. data/spec/remote_spec.rb +140 -0
  45. data/spec/rush_spec.rb +28 -0
  46. data/spec/search_results_spec.rb +44 -0
  47. data/spec/shell_spec.rb +23 -0
  48. data/spec/ssh_tunnel_spec.rb +122 -0
  49. data/spec/string_ext_spec.rb +23 -0
  50. metadata +141 -0
data/spec/rush_spec.rb ADDED
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + '/base'
2
+
3
+ describe Rush do
4
+ it "fetches a local file path" do
5
+ Rush['/etc/hosts'].full_path.should == '/etc/hosts'
6
+ end
7
+
8
+ it "fetches the dir of __FILE__" do
9
+ Rush.dir(__FILE__).name.should == 'spec'
10
+ end
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
16
+
17
+ it "runs a bash command" do
18
+ Rush.bash('echo hi').should == "hi\n"
19
+ end
20
+
21
+ it "gets the list of local processes" do
22
+ Rush.processes.should be_kind_of(Rush::ProcessSet)
23
+ end
24
+
25
+ it "gets my process" do
26
+ Rush.my_process.pid.should == Process.pid
27
+ end
28
+ end
@@ -0,0 +1,44 @@
1
+ require File.dirname(__FILE__) + '/base'
2
+
3
+ describe Rush::SearchResults do
4
+ before do
5
+ @results = Rush::SearchResults.new(/pat/)
6
+ @file = Rush::File.new("file")
7
+ end
8
+
9
+ it "returns its list of entries" do
10
+ @results.add(@file, %w(a))
11
+ @results.entries.should == [ @file ]
12
+ end
13
+
14
+ it "only returns each entry once no matter how many line matches it has" do
15
+ @results.add(@file, %w(a b))
16
+ @results.entries.should == [ @file ]
17
+ end
18
+
19
+ it "returns its list of matched lines" do
20
+ @results.add(@file, %w(a b))
21
+ @results.lines.should == %w(a b)
22
+ end
23
+
24
+ it "returns all lines for each entry in a flattened form" do
25
+ file2 = Rush::File.new("another file")
26
+ @results.add(@file, %w(a b))
27
+ @results.add(file2, %w(c d))
28
+ @results.lines.should == %w(a b c d)
29
+ end
30
+
31
+ it "returns a hash of entries_with_lines" do
32
+ @results.add(@file, %w(a))
33
+ @results.entries_with_lines.should == { @file => %w(a) }
34
+ end
35
+
36
+ it "mixes in Commands to operate like a dir or entry array" do
37
+ @results.methods.include?("search").should be_true
38
+ end
39
+
40
+ it "mixes in Enumerable to behave like an array" do
41
+ @results.add(@file, %w(a))
42
+ @results.map { |e| e }.should == [ @file ]
43
+ end
44
+ end
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + '/base'
2
+ require 'rush/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
+ @shell.path_parts('dir/"app').should == [ "dir", "/", '"', "app", "" ]
12
+ end
13
+
14
+ it "matches open path commands on globals for readline tab completion" do
15
+ @shell.path_parts("$dir['app").should == [ "$dir", "[", "'", "app", "" ]
16
+ @shell.path_parts('$dir/"app').should == [ "$dir", "/", '"', "app", "" ]
17
+ end
18
+
19
+ it "matches open path commands on instance vars for readline tab completion" do
20
+ @shell.path_parts("@dir['app").should == [ "@dir", "[", "'", "app", "" ]
21
+ @shell.path_parts('@dir/"app').should == [ "@dir", "/", '"', "app", "" ]
22
+ end
23
+ end
@@ -0,0 +1,122 @@
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
+ }
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
@@ -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,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: adamwiggins-rush
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.1
5
+ platform: ruby
6
+ authors:
7
+ - Adam Wiggins
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-20 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mongrel
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: session
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ 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.
36
+ email: adam@heroku.com
37
+ executables:
38
+ - rush
39
+ - rushd
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - README.rdoc
44
+ files:
45
+ - README.rdoc
46
+ - Rakefile
47
+ - VERSION
48
+ - bin/rush
49
+ - bin/rushd
50
+ - lib/rush.rb
51
+ - lib/rush/access.rb
52
+ - lib/rush/array_ext.rb
53
+ - lib/rush/box.rb
54
+ - lib/rush/commands.rb
55
+ - lib/rush/config.rb
56
+ - lib/rush/dir.rb
57
+ - lib/rush/embeddable_shell.rb
58
+ - lib/rush/entry.rb
59
+ - lib/rush/exceptions.rb
60
+ - lib/rush/file.rb
61
+ - lib/rush/find_by.rb
62
+ - lib/rush/fixnum_ext.rb
63
+ - lib/rush/head_tail.rb
64
+ - lib/rush/local.rb
65
+ - lib/rush/process.rb
66
+ - lib/rush/process_set.rb
67
+ - lib/rush/remote.rb
68
+ - lib/rush/search_results.rb
69
+ - lib/rush/server.rb
70
+ - lib/rush/shell.rb
71
+ - lib/rush/ssh_tunnel.rb
72
+ - lib/rush/string_ext.rb
73
+ - spec/access_spec.rb
74
+ - spec/array_ext_spec.rb
75
+ - spec/base.rb
76
+ - spec/box_spec.rb
77
+ - spec/commands_spec.rb
78
+ - spec/config_spec.rb
79
+ - spec/dir_spec.rb
80
+ - spec/embeddable_shell_spec.rb
81
+ - spec/entry_spec.rb
82
+ - spec/file_spec.rb
83
+ - spec/find_by_spec.rb
84
+ - spec/fixnum_ext_spec.rb
85
+ - spec/local_spec.rb
86
+ - spec/process_set_spec.rb
87
+ - spec/process_spec.rb
88
+ - spec/remote_spec.rb
89
+ - spec/rush_spec.rb
90
+ - spec/search_results_spec.rb
91
+ - spec/shell_spec.rb
92
+ - spec/ssh_tunnel_spec.rb
93
+ - spec/string_ext_spec.rb
94
+ has_rdoc: true
95
+ homepage: http://rush.heroku.com/
96
+ post_install_message:
97
+ rdoc_options:
98
+ - --charset=UTF-8
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: "0"
106
+ version:
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: "0"
112
+ version:
113
+ requirements: []
114
+
115
+ rubyforge_project: ruby-shell
116
+ rubygems_version: 1.2.0
117
+ signing_key:
118
+ specification_version: 2
119
+ summary: A Ruby replacement for bash+ssh.
120
+ test_files:
121
+ - spec/access_spec.rb
122
+ - spec/array_ext_spec.rb
123
+ - spec/base.rb
124
+ - spec/box_spec.rb
125
+ - spec/commands_spec.rb
126
+ - spec/config_spec.rb
127
+ - spec/dir_spec.rb
128
+ - spec/embeddable_shell_spec.rb
129
+ - spec/entry_spec.rb
130
+ - spec/file_spec.rb
131
+ - spec/find_by_spec.rb
132
+ - spec/fixnum_ext_spec.rb
133
+ - spec/local_spec.rb
134
+ - spec/process_set_spec.rb
135
+ - spec/process_spec.rb
136
+ - spec/remote_spec.rb
137
+ - spec/rush_spec.rb
138
+ - spec/search_results_spec.rb
139
+ - spec/shell_spec.rb
140
+ - spec/ssh_tunnel_spec.rb
141
+ - spec/string_ext_spec.rb