rhc 1.6.8 → 1.7.8
Sign up to get free protection for your applications and to get access to all the features.
- data/autocomplete/rhc_bash +1167 -0
- data/features/README.md +1 -1
- data/features/domain.feature +1 -1
- data/features/lib/rhc_helper/persistable.rb +4 -1
- data/features/multiple_cartridge.feature +4 -3
- data/features/sshkey.feature +3 -3
- data/features/support/assumptions.rb +3 -3
- data/features/support/env.rb +10 -0
- data/features/support/platform_support.rb +2 -2
- data/lib/rhc.rb +6 -0
- data/lib/rhc/auth/token.rb +4 -0
- data/lib/rhc/autocomplete.rb +50 -52
- data/lib/rhc/autocomplete_templates/{rhc.erb → bash.erb} +8 -2
- data/lib/rhc/cartridge_helpers.rb +1 -1
- data/lib/rhc/cli.rb +1 -7
- data/lib/rhc/command_runner.rb +45 -16
- data/lib/rhc/commands.rb +75 -55
- data/lib/rhc/commands/account.rb +7 -51
- data/lib/rhc/commands/alias.rb +26 -17
- data/lib/rhc/commands/app.rb +75 -39
- data/lib/rhc/commands/authorization.rb +4 -2
- data/lib/rhc/commands/base.rb +31 -29
- data/lib/rhc/commands/cartridge.rb +66 -44
- data/lib/rhc/commands/domain.rb +20 -8
- data/lib/rhc/commands/git_clone.rb +3 -3
- data/lib/rhc/commands/logout.rb +51 -0
- data/lib/rhc/commands/port_forward.rb +15 -11
- data/lib/rhc/commands/setup.rb +25 -0
- data/lib/rhc/commands/snapshot.rb +20 -10
- data/lib/rhc/commands/sshkey.rb +21 -7
- data/lib/rhc/commands/tail.rb +2 -2
- data/lib/rhc/commands/threaddump.rb +2 -2
- data/lib/rhc/context_helper.rb +0 -4
- data/lib/rhc/core_ext.rb +96 -76
- data/lib/rhc/exceptions.rb +6 -0
- data/lib/rhc/help_formatter.rb +19 -2
- data/lib/rhc/helpers.rb +32 -194
- data/lib/rhc/highline_extensions.rb +412 -0
- data/lib/rhc/output_helpers.rb +31 -67
- data/lib/rhc/rest.rb +4 -2
- data/lib/rhc/rest/alias.rb +0 -2
- data/lib/rhc/rest/application.rb +9 -4
- data/lib/rhc/rest/authorization.rb +0 -2
- data/lib/rhc/rest/base.rb +1 -1
- data/lib/rhc/rest/client.rb +11 -9
- data/lib/rhc/rest/domain.rb +5 -1
- data/lib/rhc/rest/gear_group.rb +0 -2
- data/lib/rhc/rest/key.rb +0 -2
- data/lib/rhc/rest/mock.rb +32 -10
- data/lib/rhc/ssh_helpers.rb +2 -2
- data/lib/rhc/usage_templates/command_help.erb +20 -13
- data/lib/rhc/usage_templates/command_syntax_help.erb +1 -3
- data/lib/rhc/usage_templates/help.erb +15 -16
- data/lib/rhc/usage_templates/options_help.erb +7 -9
- data/lib/rhc/wizard.rb +193 -159
- data/spec/rest_spec_helper.rb +2 -2
- data/spec/rhc/cli_spec.rb +36 -5
- data/spec/rhc/command_spec.rb +94 -42
- data/spec/rhc/commands/account_spec.rb +1 -75
- data/spec/rhc/commands/alias_spec.rb +28 -28
- data/spec/rhc/commands/app_spec.rb +141 -33
- data/spec/rhc/commands/apps_spec.rb +4 -4
- data/spec/rhc/commands/authorization_spec.rb +8 -8
- data/spec/rhc/commands/cartridge_spec.rb +18 -9
- data/spec/rhc/commands/domain_spec.rb +16 -16
- data/spec/rhc/commands/git_clone_spec.rb +3 -3
- data/spec/rhc/commands/logout_spec.rb +86 -0
- data/spec/rhc/commands/port_forward_spec.rb +9 -9
- data/spec/rhc/commands/server_spec.rb +5 -5
- data/spec/rhc/commands/setup_spec.rb +19 -5
- data/spec/rhc/commands/snapshot_spec.rb +12 -12
- data/spec/rhc/commands/sshkey_spec.rb +11 -11
- data/spec/rhc/commands/tail_spec.rb +5 -5
- data/spec/rhc/commands/threaddump_spec.rb +3 -3
- data/spec/rhc/config_spec.rb +6 -6
- data/spec/rhc/helpers_spec.rb +72 -219
- data/spec/rhc/highline_extensions_spec.rb +269 -0
- data/spec/rhc/rest_application_spec.rb +28 -1
- data/spec/rhc/rest_client_spec.rb +20 -21
- data/spec/rhc/rest_spec.rb +10 -0
- data/spec/rhc/wizard_spec.rb +72 -32
- data/spec/spec_helper.rb +86 -56
- data/spec/wizard_spec_helper.rb +7 -4
- metadata +165 -160
- data/spec/spec.opts +0 -1
@@ -13,7 +13,7 @@ describe RHC::Commands::Sshkey do
|
|
13
13
|
context "when run with list command" do
|
14
14
|
let(:arguments) { %w[sshkey list --noprompt --config test.conf -l test@test.foo -p password --trace] }
|
15
15
|
|
16
|
-
it { expect { run }.
|
16
|
+
it { expect { run }.to exit_with_code(0) }
|
17
17
|
it { run_output.should match(/mockkey1 \(type: ssh-rsa\)/) }
|
18
18
|
end
|
19
19
|
end
|
@@ -22,7 +22,7 @@ describe RHC::Commands::Sshkey do
|
|
22
22
|
context "when run with show command" do
|
23
23
|
let(:arguments) { %w[sshkey show mockkey1 --noprompt --config test.conf -l test@test.foo -p password --trace] }
|
24
24
|
|
25
|
-
it { expect { run }.
|
25
|
+
it { expect { run }.to exit_with_code(0) }
|
26
26
|
it { run_output.should match(/mockkey1 \(type: ssh-rsa\)/) }
|
27
27
|
end
|
28
28
|
end
|
@@ -38,7 +38,7 @@ describe RHC::Commands::Sshkey do
|
|
38
38
|
File.open('id_rsa.pub', 'w') do |f|
|
39
39
|
f << 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCnCOqK7/mmvZ9AtCAerxjAasJ1rSpfuWT4vNm1+O/Fh0Di3chTWjY9a0M2hEnqkqnVG589L9CqCUeT0kdc3Vgw3JEcacSUr1z7tLr9kO+p/D5lSdQYzDGGRFOZ0H6lc/y8iNxWV1VO/sJvKx6cr5zvKIn8Q6GvhVNOxlai0IOb9FJxLGK95GLpZ+elzh8Tc9giy7KfwheAwhV2JoF9uRltE5JP/CNs7w/E29i1Z+jlueuu8RVotLmhSVNJm91Ey7OCtoI1iBE0Wv/SucFe32Qi08RWTM/MaGGz93KQNOVRGjNkosJjPmP1qU6WGBfliDkJAZXB0b6sEcnx1fbVikwZ'
|
40
40
|
end
|
41
|
-
expect { run }.
|
41
|
+
expect { run }.to exit_with_code(0)
|
42
42
|
rest_client.sshkeys.length.should == num_keys + 1
|
43
43
|
end
|
44
44
|
end
|
@@ -54,7 +54,7 @@ describe RHC::Commands::Sshkey do
|
|
54
54
|
File.open('id_rsa.pub', 'w') do |f|
|
55
55
|
f << 'ssh-rsa AADAQABAAABAQCnCOqK7/mmvZ9AtCAerxjAasJ1rSpfuWT4vNm1+O/Fh0Di3chTWjY9a0M2hEnqkqnVG589L9CqCUeT0kdc3Vgw3JEcacSUr1z7tLr9kO+p/D5lSdQYzDGGRFOZ0H6lc/y8iNxWV1VO/sJvKx6cr5zvKIn8Q6GvhVNOxlai0IOb9FJxLGK95GLpZ+elzh8Tc9giy7KfwheAwhV2JoF9uRltE5JP/CNs7w/E29i1Z+jlueuu8RVotLmhSVNJm91Ey7OCtoI1iBE0Wv/SucFe32Qi08RWTM/MaGGz93KQNOVRGjNkosJjPmP1qU6WGBfliDkJAZXB0b6sEcnx1fbVikwZ'
|
56
56
|
end
|
57
|
-
expect { run }.
|
57
|
+
expect { run }.to exit_with_code(128)
|
58
58
|
expect { run_output.should match(/Name:.* mockkey/) }
|
59
59
|
rest_client.sshkeys.length.should == num_keys
|
60
60
|
end
|
@@ -67,7 +67,7 @@ describe RHC::Commands::Sshkey do
|
|
67
67
|
File.open('id_rsa.pub', 'w') do |f|
|
68
68
|
f << ''
|
69
69
|
end
|
70
|
-
expect { run }.
|
70
|
+
expect { run }.to exit_with_code(128)
|
71
71
|
expect { run_output.should match(/Name:.* mockkey/) }
|
72
72
|
rest_client.sshkeys.length.should == num_keys
|
73
73
|
end
|
@@ -75,7 +75,7 @@ describe RHC::Commands::Sshkey do
|
|
75
75
|
|
76
76
|
it "exits with status code Errno::EACCES::Errno" do
|
77
77
|
IO.should_receive(:read).and_return("ssh_foo bar")
|
78
|
-
expect { run }.
|
78
|
+
expect { run }.to exit_with_code(128)
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
@@ -89,7 +89,7 @@ describe RHC::Commands::Sshkey do
|
|
89
89
|
File.open('id_rsa.pub', 'w') do |f|
|
90
90
|
f << 'ssh-rsa AADAQABAAABAQCnCOqK7/mmvZ9AtCAerxjAasJ1rSpfuWT4vNm1+O/Fh0Di3chTWjY9a0M2hEnqkqnVG589L9CqCUeT0kdc3Vgw3JEcacSUr1z7tLr9kO+p/D5lSdQYzDGGRFOZ0H6lc/y8iNxWV1VO/sJvKx6cr5zvKIn8Q6GvhVNOxlai0IOb9FJxLGK95GLpZ+elzh8Tc9giy7KfwheAwhV2JoF9uRltE5JP/CNs7w/E29i1Z+jlueuu8RVotLmhSVNJm91Ey7OCtoI1iBE0Wv/SucFe32Qi08RWTM/MaGGz93KQNOVRGjNkosJjPmP1qU6WGBfliDkJAZXB0b6sEcnx1fbVikwZ'
|
91
91
|
end
|
92
|
-
expect { run }.
|
92
|
+
expect { run }.to exit_with_code(0)
|
93
93
|
expect { run_output.should match("key you are uploading is not recognized") }
|
94
94
|
rest_client.sshkeys.length.should == num_keys + 1
|
95
95
|
end
|
@@ -100,7 +100,7 @@ describe RHC::Commands::Sshkey do
|
|
100
100
|
let(:arguments) { %w[sshkey add --noprompt --config test.conf -l test@test.foo -p password foobar id_rsa.pub] }
|
101
101
|
|
102
102
|
it "exits with status code Errno::ENOENT::Errno" do
|
103
|
-
expect { run }.
|
103
|
+
expect { run }.to exit_with_code(128)
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
@@ -119,7 +119,7 @@ describe RHC::Commands::Sshkey do
|
|
119
119
|
|
120
120
|
it "exits with status code Errno::EACCES::Errno" do
|
121
121
|
IO.should_receive(:read).and_raise(Errno::EACCES)
|
122
|
-
expect { run }.
|
122
|
+
expect { run }.to exit_with_code(128)
|
123
123
|
end
|
124
124
|
|
125
125
|
end
|
@@ -132,7 +132,7 @@ describe RHC::Commands::Sshkey do
|
|
132
132
|
it 'deletes the key' do
|
133
133
|
keys = rest_client.sshkeys
|
134
134
|
num_keys = keys.length
|
135
|
-
expect
|
135
|
+
expect{ run }.to exit_with_code(0)
|
136
136
|
rest_client.sshkeys.length.should == num_keys - 1
|
137
137
|
end
|
138
138
|
end
|
@@ -143,7 +143,7 @@ describe RHC::Commands::Sshkey do
|
|
143
143
|
|
144
144
|
it 'leaves keys untouched' do
|
145
145
|
num_keys = @keys.length
|
146
|
-
expect
|
146
|
+
expect{ run }.to exit_with_code(0)
|
147
147
|
rest_client.sshkeys.length.should == num_keys
|
148
148
|
end
|
149
149
|
end
|
@@ -17,7 +17,7 @@ describe RHC::Commands::Tail do
|
|
17
17
|
|
18
18
|
context 'help is run' do
|
19
19
|
it "should display help" do
|
20
|
-
expect { run }.
|
20
|
+
expect { run }.to exit_with_code(0)
|
21
21
|
end
|
22
22
|
it('should output usage') { run_output.should match("Usage: rhc tail") }
|
23
23
|
end
|
@@ -28,24 +28,24 @@ describe RHC::Commands::Tail do
|
|
28
28
|
|
29
29
|
context 'when ssh connects' do
|
30
30
|
before (:each) {Net::SSH.should_receive(:start).with('test.domain.com', 'user') }
|
31
|
-
it { expect { run }.
|
31
|
+
it { expect { run }.to exit_with_code(0) }
|
32
32
|
end
|
33
33
|
|
34
34
|
context 'is run on an unreachable domain' do
|
35
35
|
before (:each) {Net::SSH.should_receive(:start).and_raise(SocketError) }
|
36
|
-
it { expect { run }.
|
36
|
+
it { expect { run }.to exit_with_code(1) }
|
37
37
|
it { run_output.should =~ /The connection to test.domain.com failed: / }
|
38
38
|
end
|
39
39
|
|
40
40
|
context 'is refused' do
|
41
41
|
before (:each) {Net::SSH.should_receive(:start).and_raise(Errno::ECONNREFUSED) }
|
42
|
-
it { expect { run }.
|
42
|
+
it { expect { run }.to exit_with_code(1) }
|
43
43
|
it { run_output.should =~ /The server test.domain.com refused a connection with user user/ }
|
44
44
|
end
|
45
45
|
|
46
46
|
context 'succeeds and exits on Interrupt' do
|
47
47
|
before (:each) { rest_client.stub(:find_domain) { raise Interrupt } }
|
48
|
-
it { expect { run }.
|
48
|
+
it { expect { run }.to raise_error(Interrupt) }
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
@@ -63,7 +63,7 @@ describe RHC::Commands::Threaddump do
|
|
63
63
|
|
64
64
|
context 'help is run' do
|
65
65
|
it "should display help" do
|
66
|
-
expect { run }.
|
66
|
+
expect { run }.to exit_with_code(0)
|
67
67
|
end
|
68
68
|
it('should output usage') { run_output.should match("Usage: rhc threaddump") }
|
69
69
|
end
|
@@ -71,14 +71,14 @@ describe RHC::Commands::Threaddump do
|
|
71
71
|
|
72
72
|
describe 'threaddump' do
|
73
73
|
let(:arguments) { ['threaddump', 'mock_app_0'] }
|
74
|
-
it { expect { run }.
|
74
|
+
it { expect { run }.to exit_with_code(0) }
|
75
75
|
it { run_output.should =~ /Application test thread dump complete/ }
|
76
76
|
end
|
77
77
|
|
78
78
|
describe 'threaddump no args' do
|
79
79
|
let(:arguments) { ['threaddump'] }
|
80
80
|
context 'args not supplied' do
|
81
|
-
it { expect { run }.
|
81
|
+
it { expect { run }.to exit_with_code(1) }
|
82
82
|
end
|
83
83
|
end
|
84
84
|
end
|
data/spec/rhc/config_spec.rb
CHANGED
@@ -4,7 +4,7 @@ require 'net/http'
|
|
4
4
|
|
5
5
|
describe RHC::Config do
|
6
6
|
subject{ RHC::Config }
|
7
|
-
before
|
7
|
+
before do
|
8
8
|
ENV['LIBRA_SERVER'] = nil
|
9
9
|
ENV['HTTP_PROXY'] = nil
|
10
10
|
ENV['http_proxy'] = nil
|
@@ -14,10 +14,12 @@ describe RHC::Config do
|
|
14
14
|
FakeFS::FileSystem.clear
|
15
15
|
end
|
16
16
|
|
17
|
-
after
|
17
|
+
after do
|
18
18
|
FakeFS.deactivate!
|
19
19
|
ENV['HTTP_PROXY'] = nil
|
20
20
|
ENV['http_proxy'] = nil
|
21
|
+
ENV['LIBRA_SERVER'] = nil
|
22
|
+
RHC::Config.send(:instance_variable_set, :@default, nil)
|
21
23
|
end
|
22
24
|
|
23
25
|
describe "class" do
|
@@ -86,6 +88,7 @@ describe RHC::Config do
|
|
86
88
|
end
|
87
89
|
|
88
90
|
context "Config values with /etc/openshift/express.conf" do
|
91
|
+
|
89
92
|
it "should have only a global config" do
|
90
93
|
ConfigHelper.write_out_config(ConfigHelper.global_config_path, "global.openshift.redhat.com", "global@redhat.com")
|
91
94
|
subject.initialize
|
@@ -260,11 +263,8 @@ describe RHC::Config do
|
|
260
263
|
end
|
261
264
|
|
262
265
|
context "Debug options" do
|
263
|
-
after(:all) do
|
264
|
-
FakeFS::FileSystem.clear
|
265
|
-
end
|
266
|
-
|
267
266
|
it "should show debug as false because nothing is set" do
|
267
|
+
subject.initialize
|
268
268
|
ConfigHelper.check_legacy_debug({}).should be_false
|
269
269
|
end
|
270
270
|
|
data/spec/rhc/helpers_spec.rb
CHANGED
@@ -1,35 +1,34 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'rhc
|
2
|
+
require 'rhc'
|
3
3
|
require 'rhc/ssh_helpers'
|
4
4
|
require 'rhc/cartridge_helpers'
|
5
5
|
require 'rhc/git_helpers'
|
6
6
|
require 'rhc/core_ext'
|
7
|
-
require 'highline/import'
|
8
7
|
require 'rhc/config'
|
9
|
-
require 'rhc/helpers'
|
10
8
|
require 'date'
|
11
9
|
require 'resolv'
|
10
|
+
require 'ostruct'
|
11
|
+
|
12
|
+
class MockHelpers
|
13
|
+
include RHC::Helpers
|
14
|
+
include RHC::SSHHelpers
|
15
|
+
include RHC::CartridgeHelpers
|
16
|
+
|
17
|
+
def config
|
18
|
+
@config ||= RHC::Config.new
|
19
|
+
end
|
20
|
+
def options
|
21
|
+
@options ||= OpenStruct.new(:server => nil)
|
22
|
+
end
|
23
|
+
end
|
12
24
|
|
13
25
|
describe RHC::Helpers do
|
14
|
-
before
|
26
|
+
before do
|
15
27
|
mock_terminal
|
16
28
|
user_config
|
17
29
|
end
|
18
30
|
|
19
|
-
subject
|
20
|
-
Class.new(Object) do
|
21
|
-
include RHC::Helpers
|
22
|
-
include RHC::SSHHelpers
|
23
|
-
|
24
|
-
def config
|
25
|
-
@config ||= RHC::Config.new
|
26
|
-
end
|
27
|
-
def options
|
28
|
-
@options ||= OpenStruct.new(:server => nil)
|
29
|
-
end
|
30
|
-
end.new
|
31
|
-
end
|
32
|
-
let(:tests) { OutputTests.new }
|
31
|
+
subject{ MockHelpers.new }
|
33
32
|
|
34
33
|
its(:openshift_server) { should == 'openshift.redhat.com' }
|
35
34
|
its(:openshift_url) { should == 'https://openshift.redhat.com' }
|
@@ -47,7 +46,7 @@ describe RHC::Helpers do
|
|
47
46
|
|
48
47
|
shared_examples_for "colorized output" do
|
49
48
|
it("should be colorized") do
|
50
|
-
message = "this is #{_color}"
|
49
|
+
message = "this is #{_color} -"
|
51
50
|
output = capture{ subject.send(method,message) }
|
52
51
|
output.should be_colorized(message,_color)
|
53
52
|
end
|
@@ -77,7 +76,7 @@ describe RHC::Helpers do
|
|
77
76
|
it("should draw a table") do
|
78
77
|
subject.table([[10,2], [3,40]]) do |i|
|
79
78
|
i.map(&:to_s)
|
80
|
-
end.should == ['10 2','3 40']
|
79
|
+
end.to_a.should == ['10 2','3 40']
|
81
80
|
end
|
82
81
|
|
83
82
|
context "error output" do
|
@@ -87,7 +86,7 @@ describe RHC::Helpers do
|
|
87
86
|
end
|
88
87
|
|
89
88
|
it("should output a table") do
|
90
|
-
subject.send(:
|
89
|
+
subject.send(:format_no_info, 'test').to_a.should == ['This test has no information to show']
|
91
90
|
end
|
92
91
|
|
93
92
|
it "should parse an RFC3339 date" do
|
@@ -163,7 +162,7 @@ describe RHC::Helpers do
|
|
163
162
|
Class.new(Object){ include RHC::Helpers }.new
|
164
163
|
end
|
165
164
|
|
166
|
-
it("should raise on config"){ expect{ subject.config }.
|
165
|
+
it("should raise on config"){ expect{ subject.config }.to raise_error }
|
167
166
|
end
|
168
167
|
|
169
168
|
context "with a bad timeout value" do
|
@@ -238,71 +237,11 @@ describe RHC::Helpers do
|
|
238
237
|
it{ run_output.should match("The certificate 'not_a_file' cannot be loaded: No such file or directory ") }
|
239
238
|
end
|
240
239
|
|
241
|
-
|
242
|
-
it{
|
240
|
+
context "#get_properties" do
|
241
|
+
it{ subject.send(:get_properties, stub(:plan_id => 'free'), :plan_id).should == [[:plan_id, 'Free']] }
|
243
242
|
context "when an error is raised" do
|
244
|
-
|
245
|
-
it{
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
context "Formatter" do
|
250
|
-
before{ tests.reset }
|
251
|
-
|
252
|
-
it "should print out a paragraph with open endline on the same line" do
|
253
|
-
tests.section_same_line
|
254
|
-
$terminal.read.should == "section 1 word\n"
|
255
|
-
end
|
256
|
-
|
257
|
-
it "should print out a section without any line breaks" do
|
258
|
-
tests.section_no_breaks
|
259
|
-
$terminal.read.should == "section 1 \n"
|
260
|
-
end
|
261
|
-
|
262
|
-
it "should print out a section with trailing line break" do
|
263
|
-
tests.section_one_break
|
264
|
-
$terminal.read.should == "section 1\n"
|
265
|
-
end
|
266
|
-
|
267
|
-
it "should print out 2 sections with matching bottom and top margins generating one space between" do
|
268
|
-
tests.sections_equal_bottom_top
|
269
|
-
$terminal.read.should == "section 1\n\nsection 2\n"
|
270
|
-
end
|
271
|
-
|
272
|
-
it "should print out 2 sections with larger bottom margin generating two spaces between" do
|
273
|
-
tests.sections_larger_bottom
|
274
|
-
$terminal.read.should == "section 1\n\n\nsection 2\n"
|
275
|
-
end
|
276
|
-
|
277
|
-
it "should print out 2 sections with larger top margin generating two spaces between" do
|
278
|
-
tests.sections_larger_top
|
279
|
-
$terminal.read.should == "section 1\n\n\nsection 2\n"
|
280
|
-
end
|
281
|
-
|
282
|
-
it "should print out 4 sections and not collapse open sections" do
|
283
|
-
tests.sections_four_on_three_lines
|
284
|
-
$terminal.read.should == "section 1\n\nsection 2 \nsection 3\n\nsection 4\n"
|
285
|
-
end
|
286
|
-
|
287
|
-
it "should show the equivilance of paragaph to section(:top => 1, :bottom => 1)" do
|
288
|
-
tests.section_1_1
|
289
|
-
section_1_1 = $terminal.read
|
290
|
-
tests.reset
|
291
|
-
tests.section_paragraph
|
292
|
-
paragraph = $terminal.read
|
293
|
-
|
294
|
-
section_1_1.should == paragraph
|
295
|
-
|
296
|
-
tests.reset
|
297
|
-
tests.section_1_1
|
298
|
-
tests.section_paragraph
|
299
|
-
|
300
|
-
$terminal.read.should == "section\n\nsection\n"
|
301
|
-
end
|
302
|
-
|
303
|
-
it "should not collapse explicit newline sections" do
|
304
|
-
tests.outside_newline
|
305
|
-
$terminal.read.should == "section 1\n\n\nsection 2\n"
|
243
|
+
let(:bar){ stub.tap{ |s| s.should_receive(:foo).and_raise(::Exception) } }
|
244
|
+
it{ subject.send(:get_properties, bar, :foo).should == [[:foo, '<error>']] }
|
306
245
|
end
|
307
246
|
end
|
308
247
|
|
@@ -331,7 +270,7 @@ describe RHC::Helpers do
|
|
331
270
|
let(:stderr){ 'fatal: error' }
|
332
271
|
let(:exit_status){ 1 }
|
333
272
|
|
334
|
-
it { capture{ expect{ subject.git_clone_repo("url", "repo") }.
|
273
|
+
it { capture{ expect{ subject.git_clone_repo("url", "repo") }.to raise_error(RHC::GitException) } }
|
335
274
|
it { capture_all{ subject.git_clone_repo("url", "repo") rescue nil }.should match("fake git clone") }
|
336
275
|
it { capture_all{ subject.git_clone_repo("url", "repo") rescue nil }.should match("fatal: error") }
|
337
276
|
end
|
@@ -340,14 +279,14 @@ describe RHC::Helpers do
|
|
340
279
|
let(:stderr){ "fatal: destination path 'foo' already exists and is not an empty directory." }
|
341
280
|
let(:exit_status){ 1 }
|
342
281
|
|
343
|
-
it { capture{ expect{ subject.git_clone_repo("url", "repo") }.
|
282
|
+
it { capture{ expect{ subject.git_clone_repo("url", "repo") }.to raise_error(RHC::GitDirectoryExists) } }
|
344
283
|
end
|
345
284
|
|
346
285
|
context "permission denied" do
|
347
286
|
let(:stderr){ "Permission denied (publickey,gssapi-mic)." }
|
348
287
|
let(:exit_status){ 1 }
|
349
288
|
|
350
|
-
it { capture{ expect{ subject.git_clone_repo("url", "repo") }.
|
289
|
+
it { capture{ expect{ subject.git_clone_repo("url", "repo") }.to raise_error(RHC::GitPermissionDenied) } }
|
351
290
|
end
|
352
291
|
end
|
353
292
|
end
|
@@ -373,6 +312,48 @@ describe RHC::Helpers do
|
|
373
312
|
end
|
374
313
|
end
|
375
314
|
|
315
|
+
describe "#wrap" do
|
316
|
+
it{ "abc".wrap(1).should == "a\nb\nc" }
|
317
|
+
end
|
318
|
+
|
319
|
+
describe "#textwrap_ansi" do
|
320
|
+
it{ "".textwrap_ansi(80).should == [] }
|
321
|
+
it{ "\n".textwrap_ansi(80).should == ["",""] }
|
322
|
+
it{ "a".textwrap_ansi(1).should == ['a'] }
|
323
|
+
it{ "ab".textwrap_ansi(1).should == ['a','b'] }
|
324
|
+
it{ "ab".textwrap_ansi(2).should == ['ab'] }
|
325
|
+
it{ "ab cd".textwrap_ansi(4).should == ['ab', 'cd'] }
|
326
|
+
it{ " ab".textwrap_ansi(2).should == [' a','b'] }
|
327
|
+
it{ "a b".textwrap_ansi(1).should == ['a','b'] }
|
328
|
+
it{ "a w b".textwrap_ansi(2).should == ['a','w','b'] }
|
329
|
+
it{ "a w b".textwrap_ansi(3).should == ['a w','b'] }
|
330
|
+
it{ "a\nb".textwrap_ansi(1).should == ['a','b'] }
|
331
|
+
it{ "\e[1m".textwrap_ansi(1).should == ["\e[1m\e[0m"] }
|
332
|
+
it{ "\e[31;1m".textwrap_ansi(1).should == ["\e[31;1m\e[0m"] }
|
333
|
+
it{ "\e[1ma".textwrap_ansi(1).should == ["\e[1ma\e[0m"] }
|
334
|
+
it{ "a\e[12m".textwrap_ansi(1).should == ["a\e[12m\e[0m"] }
|
335
|
+
it{ "a\e[12m\e[34mb".textwrap_ansi(1).should == ["a\e[12m\e[34m\e[0m","\e[12m\e[34mb\e[0m"] }
|
336
|
+
it{ "\e[12;34ma".textwrap_ansi(1).should == ["\e[12;34ma\e[0m"] }
|
337
|
+
it{ "\e[1m\e[1m".textwrap_ansi(1).should == ["\e[1m\e[1m\e[0m"] }
|
338
|
+
it{ "\e[1m \e[1m".textwrap_ansi(1).should == ["\e[1m\e[0m", "\e[1m\e[1m\e[0m"] }
|
339
|
+
it{ "\e[1ma\nb".textwrap_ansi(80).should == ["\e[1ma","b"] }
|
340
|
+
|
341
|
+
it{ "ab".textwrap_ansi(1,false).should == ['ab'] }
|
342
|
+
it{ " abc".textwrap_ansi(3,false).should == [' abc'] }
|
343
|
+
it{ "abcd".textwrap_ansi(3,false).should == ['abcd'] }
|
344
|
+
it{ "abcd\e[1m".textwrap_ansi(3,false).should == ["abcd\e[1m\e[0m"] }
|
345
|
+
it{ "abcd efg a".textwrap_ansi(3,false).should == ['abcd', 'efg', 'a'] }
|
346
|
+
it('next line'){ "abcd e a".textwrap_ansi(5,false).should == ['abcd', 'e a'] }
|
347
|
+
it{ "abcd efgh a".textwrap_ansi(3,false).should == ['abcd', 'efgh', 'a'] }
|
348
|
+
it{ " abcd efg a".textwrap_ansi(3,false).should == [' abcd', 'efg', 'a'] }
|
349
|
+
end
|
350
|
+
|
351
|
+
describe "#strip_ansi" do
|
352
|
+
it{ "\e[1m \e[1m".strip_ansi.should == " " }
|
353
|
+
it{ "\eiei0".strip_ansi.should == "\eiei0" }
|
354
|
+
it{ "\e[iei0]".strip_ansi.should == "\e[iei0]" }
|
355
|
+
end
|
356
|
+
|
376
357
|
context "Resolv helper" do
|
377
358
|
let(:resolver) { Object.new }
|
378
359
|
let(:existent_host) { 'real_host' }
|
@@ -400,86 +381,6 @@ describe RHC::Helpers do
|
|
400
381
|
end
|
401
382
|
end
|
402
383
|
end
|
403
|
-
|
404
|
-
class OutputTests
|
405
|
-
include RHC::Helpers
|
406
|
-
include RHC::SSHHelpers
|
407
|
-
include RHC::OutputHelpers
|
408
|
-
|
409
|
-
def initialize
|
410
|
-
@print_num = 0
|
411
|
-
@options = Commander::Command::Options.new
|
412
|
-
end
|
413
|
-
|
414
|
-
def config
|
415
|
-
@config ||= RHC::Config
|
416
|
-
end
|
417
|
-
|
418
|
-
def next_print_num
|
419
|
-
@print_num += 1
|
420
|
-
end
|
421
|
-
|
422
|
-
def output
|
423
|
-
say "section #{next_print_num}"
|
424
|
-
end
|
425
|
-
|
426
|
-
def output_no_breaks
|
427
|
-
say "section #{next_print_num} "
|
428
|
-
end
|
429
|
-
|
430
|
-
def section_same_line
|
431
|
-
section { output_no_breaks; say 'word' }
|
432
|
-
end
|
433
|
-
|
434
|
-
def section_no_breaks
|
435
|
-
section { output_no_breaks }
|
436
|
-
end
|
437
|
-
|
438
|
-
def section_one_break
|
439
|
-
section { output }
|
440
|
-
end
|
441
|
-
|
442
|
-
def sections_equal_bottom_top
|
443
|
-
section(:bottom => 1) { output }
|
444
|
-
section(:top => 1) { output }
|
445
|
-
end
|
446
|
-
|
447
|
-
def sections_larger_bottom
|
448
|
-
section(:bottom => 2) { output }
|
449
|
-
section(:top => 1) { output }
|
450
|
-
end
|
451
|
-
|
452
|
-
def sections_larger_top
|
453
|
-
section(:bottom => 1) { output }
|
454
|
-
section(:top => 2) { output }
|
455
|
-
end
|
456
|
-
|
457
|
-
def sections_four_on_three_lines
|
458
|
-
section { output }
|
459
|
-
section(:top => 1) { output_no_breaks }
|
460
|
-
section(:bottom => 1) { output }
|
461
|
-
section(:top => 1) { output }
|
462
|
-
end
|
463
|
-
|
464
|
-
def outside_newline
|
465
|
-
section(:bottom => -1) { output }
|
466
|
-
say "\n"
|
467
|
-
section(:top => 1) { output }
|
468
|
-
end
|
469
|
-
|
470
|
-
def section_1_1
|
471
|
-
section(:top => 1, :bottom => 1) { say "section" }
|
472
|
-
end
|
473
|
-
|
474
|
-
def section_paragraph
|
475
|
-
paragraph { say "section" }
|
476
|
-
end
|
477
|
-
|
478
|
-
# call section without output to reset spacing to 0
|
479
|
-
def reset
|
480
|
-
RHC::Helpers.send(:class_variable_set, :@@margin, nil)
|
481
|
-
end
|
482
|
-
end
|
483
384
|
end
|
484
385
|
|
485
386
|
describe RHC::Helpers::StringTee do
|
@@ -525,66 +426,18 @@ describe OpenURI do
|
|
525
426
|
end
|
526
427
|
end
|
527
428
|
|
528
|
-
describe HighLine do
|
529
|
-
it "should wrap the terminal" do
|
530
|
-
$terminal.wrap_at = 10
|
531
|
-
say "Lorem ipsum dolor sit amet"
|
532
|
-
output = $terminal.read
|
533
|
-
output.should match "Lorem\nipsum\ndolor sit\namet"
|
534
|
-
end
|
535
|
-
it "should wrap the terminal" do
|
536
|
-
$terminal.wrap_at = 16
|
537
|
-
say "Lorem ipsum dolor sit amet"
|
538
|
-
output = $terminal.read
|
539
|
-
output.should match "Lorem ipsum\ndolor sit amet"
|
540
|
-
end
|
541
|
-
it "should not wrap the terminal" do
|
542
|
-
$terminal.wrap_at = 50
|
543
|
-
say "Lorem ipsum dolor sit amet"
|
544
|
-
output = $terminal.read
|
545
|
-
output.should match "Lorem ipsum dolor sit amet"
|
546
|
-
end
|
547
|
-
it "should wrap the terminal when using color codes" do
|
548
|
-
$terminal.wrap_at = 10
|
549
|
-
say $terminal.color("Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet", :red)
|
550
|
-
output = $terminal.read
|
551
|
-
output.should match "Lorem\nipsum\ndolor sit\namet Lorem\nipsum\ndolor sit\namet"
|
552
|
-
end
|
553
|
-
it "should wrap the terminal with other escape characters" do
|
554
|
-
$terminal.wrap_at = 10
|
555
|
-
say "Lorem ipsum dolor sit am\eet"
|
556
|
-
output = $terminal.read
|
557
|
-
output.should match "Lorem\nipsum\ndolor sit\nam\eet"
|
558
|
-
end
|
559
|
-
it "should wrap the terminal when words are smaller than wrap length" do
|
560
|
-
$terminal.wrap_at = 3
|
561
|
-
say "Antidisestablishmentarianism"
|
562
|
-
output = $terminal.read
|
563
|
-
output.should match "Ant\nidi\nses\ntab\nlis\nhme\nnta\nria\nnis\nm"
|
564
|
-
end
|
565
|
-
end
|
566
|
-
|
567
429
|
describe RHC::CartridgeHelpers do
|
568
430
|
before(:each) do
|
569
431
|
mock_terminal
|
570
432
|
end
|
571
433
|
|
572
|
-
subject
|
573
|
-
Class.new(Object) do
|
574
|
-
include RHC::Helpers
|
575
|
-
include RHC::CartridgeHelpers
|
576
|
-
|
577
|
-
def config
|
578
|
-
@config ||= RHC::Config.new
|
579
|
-
end
|
580
|
-
end.new
|
581
|
-
end
|
434
|
+
subject{ MockHelpers.new }
|
582
435
|
|
583
436
|
describe '#check_cartridges' do
|
584
437
|
let(:cartridges){ [] }
|
585
438
|
let(:find_cartridges){ [] }
|
586
439
|
context "with a generic object" do
|
587
|
-
it { expect{ subject.send(:check_cartridges, 'foo', :from => cartridges) }.
|
440
|
+
it { expect{ subject.send(:check_cartridges, 'foo', :from => cartridges) }.to raise_error(RHC::CartridgeNotFoundException, 'There are no cartridges that match \'foo\'.') }
|
588
441
|
end
|
589
442
|
end
|
590
443
|
describe '#web_carts_only' do
|