runssh 0.2.2 → 0.4.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.
@@ -77,7 +77,6 @@ describe 'SshHostDef' do
77
77
  context "to_print" do
78
78
  it "should run correctly without user" do
79
79
  h = RunSSHLib::SshHostDef.new('myhostname')
80
- p h.to_print
81
80
  h.to_print.should match(/^.*host:.*myhostname\n.*login:.*current user$/)
82
81
  end
83
82
 
@@ -87,5 +86,10 @@ describe 'SshHostDef' do
87
86
  })
88
87
  h.to_print.should match(/^.*host:.*myhostname\n.*login:.*me$/)
89
88
  end
89
+
90
+ it "prints abbreviated local tunnel with full path" do
91
+ h = RunSSHLib::SshHostDef.new(:host_name => 'hostname', :local_tunnel => '7070')
92
+ h.to_print.should match(/local tunnel: 7070:localhost:7070/)
93
+ end
90
94
  end
91
95
  end
data/spec/spec_helper.rb CHANGED
@@ -16,75 +16,14 @@
16
16
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
  #
18
18
  require 'rspec'
19
- require 'tmpdir'
19
+ require %Q(#{File.join(File.dirname(__FILE__), "support", "utils")})
20
20
  $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
21
21
 
22
- # got the idea from:
23
- # http://stackoverflow.com/questions/1480537/how-can-i-validate-exits-and-aborts-in-rspec
24
- module ExitCodeMatchers
25
- RSpec::Matchers.define :exit_normaly do
26
- actual = nil
27
- match do |block|
28
- begin
29
- block.call
30
- rescue SystemExit => e
31
- actual = e.status
32
- end
33
- actual and actual == 0
34
- end
35
- failure_message_for_should do |block|
36
- "expected block to exit with code 0 but" +
37
- (actual.nil? ? " exit was not called" : " exited with #{actual}")
38
- end
39
- failure_message_for_should_not do |block|
40
- "expected code not to exit with code 0 but it did"
41
- end
42
- description do
43
- "expect block to exit with code 0"
44
- end
45
- end
46
-
47
- RSpec::Matchers.define :exit_abnormaly do
48
- actual = nil
49
- match do |block|
50
- begin
51
- block.call
52
- rescue SystemExit => e
53
- actual = e.status
54
- end
55
- actual and actual != 0
56
- end
57
- failure_message_for_should do |block|
58
- "expected block to exit with code other then 0 but" +
59
- (actual.nil? ? " exit was not called" : " exited with #{actual}")
60
- end
61
- failure_message_for_should_not do |block|
62
- "expected code not to exit with code different then 0 but it did"
63
- end
64
- description do
65
- "expect block to exit with code different then 0"
66
- end
67
- end
22
+ require 'simplecov'
23
+ SimpleCov.start do
24
+ add_group "Sources", "/lib/"
68
25
  end
69
26
 
70
27
  Rspec.configure do |c|
71
28
  c.mock_with :rspec
72
29
  end
73
-
74
- TMP_FILE = File.join(Dir.tmpdir, 'tempfile')
75
-
76
- def cleanup_tmp_file
77
- File.delete TMP_FILE if File.exists? TMP_FILE
78
- bf = TMP_FILE + '.bak'
79
- File.delete bf if File.exists? bf
80
- end
81
-
82
- def import_fixtures
83
- yml = File.join(File.dirname(__FILE__), 'fixtures', 'runssh.yml')
84
- c = RunSSHLib::ConfigFile.new(TMP_FILE)
85
- c.import(yml)
86
- end
87
-
88
- def dump_config hsh
89
- File.open(TMP_FILE, 'w') { |out| Marshal.dump(hsh, out) }
90
- end
@@ -0,0 +1,149 @@
1
+ #
2
+ # Copyright (C) 2010 Haim Ashkenazi
3
+ #
4
+ # This program is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU General Public License
6
+ # as published by the Free Software Foundation; either version 2
7
+ # of the License, or (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program; if not, write to the Free Software
16
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
+ #
18
+
19
+ require 'tmpdir'
20
+
21
+ # got the idea from:
22
+ # http://stackoverflow.com/questions/1480537/how-can-i-validate-exits-and-aborts-in-rspec
23
+ module ExitCodeMatchers
24
+ RSpec::Matchers.define :exit_normaly do
25
+ actual = nil
26
+ match do |block|
27
+ begin
28
+ block.call
29
+ rescue SystemExit => e
30
+ actual = e.status
31
+ end
32
+ actual and actual == 0
33
+ end
34
+ failure_message_for_should do |block|
35
+ "expected block to exit with code 0 but" +
36
+ (actual.nil? ? " exit was not called" : " exited with #{actual}")
37
+ end
38
+ failure_message_for_should_not do |block|
39
+ "expected code not to exit with code 0 but it did"
40
+ end
41
+ description do
42
+ "expect block to exit with code 0"
43
+ end
44
+ end
45
+
46
+ RSpec::Matchers.define :exit_abnormaly do
47
+ actual = nil
48
+ match do |block|
49
+ begin
50
+ block.call
51
+ rescue SystemExit => e
52
+ actual = e.status
53
+ end
54
+ actual and actual != 0
55
+ end
56
+ failure_message_for_should do |block|
57
+ "expected block to exit with code other then 0 but" +
58
+ (actual.nil? ? " exit was not called" : " exited with #{actual}")
59
+ end
60
+ failure_message_for_should_not do |block|
61
+ "expected code not to exit with code different then 0 but it did"
62
+ end
63
+ description do
64
+ "expect block to exit with code different then 0"
65
+ end
66
+ end
67
+ end
68
+
69
+ # Captures the requested stream (:stdout or :stderr) and
70
+ # returns the result as string. It also populates the @buf
71
+ # instance variable with it so it can be accessed in case
72
+ # of system exit (e.g. die).
73
+ # The stdin parameter is the content of the stdin. It's
74
+ # required for any operation that reads from STDIN as the
75
+ # default is empty.
76
+ # Idea borrowed from the "Thor" gem (spec_help.rb).
77
+ def capture(stream, stdin='')
78
+ begin
79
+ $stdin = StringIO.open(stdin, 'r')
80
+ @buf = ''
81
+ stream = stream.to_s
82
+ eval "$#{stream} = StringIO.open(@buf, 'w')"
83
+ yield
84
+ ensure
85
+ eval("$#{stream} = #{stream.upcase}")
86
+ end
87
+
88
+ @buf
89
+ end
90
+
91
+ TMP_FILE = File.join(Dir.tmpdir, 'tempfile')
92
+ TMP_YML = TMP_FILE + '.yml'
93
+ YML_FIXTURE = File.expand_path('../../fixtures/runssh.yml', __FILE__)
94
+ KNOWN_HOSTS_FILE = File.join(Dir.tmpdir, 'known_hosts')
95
+
96
+ def cleanup_tmp_file
97
+ File.delete TMP_FILE if File.exists? TMP_FILE
98
+ bf = TMP_FILE + '.bak'
99
+ File.delete bf if File.exists? bf
100
+ File.delete TMP_YML if File.exists? TMP_YML
101
+ File.delete KNOWN_HOSTS_FILE if File.exists? KNOWN_HOSTS_FILE
102
+ end
103
+
104
+ def import_fixtures
105
+ c = RunSSHLib::ConfigFile.new(TMP_FILE)
106
+ c.import(YML_FIXTURE)
107
+ end
108
+
109
+ def dump_config hsh
110
+ File.open(TMP_FILE, 'w') { |out| Marshal.dump(hsh, out) }
111
+ end
112
+
113
+ # retrive host definition from the database.
114
+ # group is a string containing the path like in parameters for
115
+ # command line.
116
+ def get_host(group)
117
+ cf = RunSSHLib::ConfigFile.new(TMP_FILE)
118
+ cf.get_host(group.split.map { |e| e.to_sym })
119
+ end
120
+
121
+ # Instead of running 'ssh ...' it prints the command.
122
+ def stub_ssh_exec
123
+ RunSSHLib::SshBackend.stub(:exec) do |_command, *args|
124
+ output = _command
125
+ output + args.join(" ") unless args.empty?
126
+ puts output
127
+ end
128
+ end
129
+
130
+ # known_hosts file for testing (with the specified host)
131
+ def create_known_hosts_file(host)
132
+ File.open(KNOWN_HOSTS_FILE, 'w') do |io|
133
+ io.write("#{host} ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA2f7VLQwGc6cc34HSra6ScQipZflsn59oVhfT0aTR08XYbQwNEbfeCL7IZVk6JWn4/kYUFmxCCwaxm/t47dex+ABnjuCeNboKLzbdDzeCiRvVtXvbjGFnaAgBGPL3Vu+7m4u59+b74a5tPQz+eRvr/jb4/fI0FssiaK+bdwfo37BD0p3c6fXI987+8F1RyDAoLS94G71+Ie47EGlj7xYvBD8RvFXtY5kaC8gNlc+sscuLqDvekJdfkwGD5F9M5kKpFQevneTk8T63+QU8mx7JJ8pNUEAi4ydAULDKRmhp/SteZfOnmcwx+jDk66Q9zXmhVUZDK4P/JwCXz5XFjgxgcw==\n")
134
+ end
135
+ end
136
+
137
+ # Checks whether a bookmark exists in TMP_FILE.
138
+ # bookmark is a string representing a path. e.g,:
139
+ # "some path to host"
140
+ def bookmark_exist? bookmark
141
+ path = bookmark.split.map { |s| s.to_sym }
142
+ c = RunSSHLib::ConfigFile.new(TMP_FILE)
143
+ begin
144
+ result = c.send(:retrieve_path, path, "")
145
+ result ? true : false
146
+ rescue RunSSHLib::ConfigError => e
147
+ false
148
+ end
149
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runssh
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 2
10
- version: 0.2.2
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Haim Ashkenazi
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-05 00:00:00 +02:00
18
+ date: 2011-05-02 00:00:00 +03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -50,86 +50,6 @@ dependencies:
50
50
  version: 1.6.1
51
51
  type: :runtime
52
52
  version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
54
- name: rspec
55
- prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- hash: 11
62
- segments:
63
- - 2
64
- - 1
65
- - 0
66
- version: 2.1.0
67
- type: :development
68
- version_requirements: *id003
69
- - !ruby/object:Gem::Dependency
70
- name: rcov
71
- prerelease: false
72
- requirement: &id004 !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ~>
76
- - !ruby/object:Gem::Version
77
- hash: 41
78
- segments:
79
- - 0
80
- - 9
81
- - 9
82
- version: 0.9.9
83
- type: :development
84
- version_requirements: *id004
85
- - !ruby/object:Gem::Dependency
86
- name: autotest
87
- prerelease: false
88
- requirement: &id005 !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ~>
92
- - !ruby/object:Gem::Version
93
- hash: 39
94
- segments:
95
- - 4
96
- - 4
97
- - 4
98
- version: 4.4.4
99
- type: :development
100
- version_requirements: *id005
101
- - !ruby/object:Gem::Dependency
102
- name: autotest-fsevent
103
- prerelease: false
104
- requirement: &id006 !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ~>
108
- - !ruby/object:Gem::Version
109
- hash: 17
110
- segments:
111
- - 0
112
- - 2
113
- - 3
114
- version: 0.2.3
115
- type: :development
116
- version_requirements: *id006
117
- - !ruby/object:Gem::Dependency
118
- name: autotest-growl
119
- prerelease: false
120
- requirement: &id007 !ruby/object:Gem::Requirement
121
- none: false
122
- requirements:
123
- - - ~>
124
- - !ruby/object:Gem::Version
125
- hash: 27
126
- segments:
127
- - 0
128
- - 2
129
- - 6
130
- version: 0.2.6
131
- type: :development
132
- version_requirements: *id007
133
53
  description: |
134
54
  Runssh is a command line utility to help bookmark many
135
55
  ssh connections in heirarchial groups.
@@ -152,6 +72,19 @@ files:
152
72
  - autotest/discover.rb
153
73
  - bin/runssh
154
74
  - bin/runssh_comp.sh
75
+ - features/add_bookmarks.feature
76
+ - features/cli_help.feature
77
+ - features/copy_id.feature
78
+ - features/delete_bookmarks.feature
79
+ - features/export_bookmarks.feature
80
+ - features/import_bookmarks.feature
81
+ - features/print_bookmarks.feature
82
+ - features/run_shell.feature
83
+ - features/step_definitions/argument_steps.rb
84
+ - features/step_definitions/bookmarks_steps.rb
85
+ - features/step_definitions/output_steps.rb
86
+ - features/support/env.rb
87
+ - features/update_bookmarks.feature
155
88
  - gpl-2.0.txt
156
89
  - lib/runsshlib.rb
157
90
  - lib/runsshlib/cli.rb
@@ -167,6 +100,7 @@ files:
167
100
  - spec/runsshlib/ssh_backend_spec.rb
168
101
  - spec/runsshlib/ssh_host_def_spec.rb
169
102
  - spec/spec_helper.rb
103
+ - spec/support/utils.rb
170
104
  has_rdoc: true
171
105
  homepage: http://github.com/babysnakes/runssh
172
106
  licenses: []
@@ -202,11 +136,24 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
136
  requirements: []
203
137
 
204
138
  rubyforge_project:
205
- rubygems_version: 1.4.2
139
+ rubygems_version: 1.5.2
206
140
  signing_key:
207
141
  specification_version: 3
208
142
  summary: CLI utility to bookmark multiple ssh connections with hierarchy.
209
143
  test_files:
144
+ - features/add_bookmarks.feature
145
+ - features/cli_help.feature
146
+ - features/copy_id.feature
147
+ - features/delete_bookmarks.feature
148
+ - features/export_bookmarks.feature
149
+ - features/import_bookmarks.feature
150
+ - features/print_bookmarks.feature
151
+ - features/run_shell.feature
152
+ - features/step_definitions/argument_steps.rb
153
+ - features/step_definitions/bookmarks_steps.rb
154
+ - features/step_definitions/output_steps.rb
155
+ - features/support/env.rb
156
+ - features/update_bookmarks.feature
210
157
  - spec/fixtures/runssh.yml
211
158
  - spec/fixtures/runssh_v_none.yml
212
159
  - spec/runsshlib/cli_spec.rb
@@ -214,3 +161,4 @@ test_files:
214
161
  - spec/runsshlib/ssh_backend_spec.rb
215
162
  - spec/runsshlib/ssh_host_def_spec.rb
216
163
  - spec/spec_helper.rb
164
+ - spec/support/utils.rb