rhc 1.6.8 → 1.7.8

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.
Files changed (85) hide show
  1. data/autocomplete/rhc_bash +1167 -0
  2. data/features/README.md +1 -1
  3. data/features/domain.feature +1 -1
  4. data/features/lib/rhc_helper/persistable.rb +4 -1
  5. data/features/multiple_cartridge.feature +4 -3
  6. data/features/sshkey.feature +3 -3
  7. data/features/support/assumptions.rb +3 -3
  8. data/features/support/env.rb +10 -0
  9. data/features/support/platform_support.rb +2 -2
  10. data/lib/rhc.rb +6 -0
  11. data/lib/rhc/auth/token.rb +4 -0
  12. data/lib/rhc/autocomplete.rb +50 -52
  13. data/lib/rhc/autocomplete_templates/{rhc.erb → bash.erb} +8 -2
  14. data/lib/rhc/cartridge_helpers.rb +1 -1
  15. data/lib/rhc/cli.rb +1 -7
  16. data/lib/rhc/command_runner.rb +45 -16
  17. data/lib/rhc/commands.rb +75 -55
  18. data/lib/rhc/commands/account.rb +7 -51
  19. data/lib/rhc/commands/alias.rb +26 -17
  20. data/lib/rhc/commands/app.rb +75 -39
  21. data/lib/rhc/commands/authorization.rb +4 -2
  22. data/lib/rhc/commands/base.rb +31 -29
  23. data/lib/rhc/commands/cartridge.rb +66 -44
  24. data/lib/rhc/commands/domain.rb +20 -8
  25. data/lib/rhc/commands/git_clone.rb +3 -3
  26. data/lib/rhc/commands/logout.rb +51 -0
  27. data/lib/rhc/commands/port_forward.rb +15 -11
  28. data/lib/rhc/commands/setup.rb +25 -0
  29. data/lib/rhc/commands/snapshot.rb +20 -10
  30. data/lib/rhc/commands/sshkey.rb +21 -7
  31. data/lib/rhc/commands/tail.rb +2 -2
  32. data/lib/rhc/commands/threaddump.rb +2 -2
  33. data/lib/rhc/context_helper.rb +0 -4
  34. data/lib/rhc/core_ext.rb +96 -76
  35. data/lib/rhc/exceptions.rb +6 -0
  36. data/lib/rhc/help_formatter.rb +19 -2
  37. data/lib/rhc/helpers.rb +32 -194
  38. data/lib/rhc/highline_extensions.rb +412 -0
  39. data/lib/rhc/output_helpers.rb +31 -67
  40. data/lib/rhc/rest.rb +4 -2
  41. data/lib/rhc/rest/alias.rb +0 -2
  42. data/lib/rhc/rest/application.rb +9 -4
  43. data/lib/rhc/rest/authorization.rb +0 -2
  44. data/lib/rhc/rest/base.rb +1 -1
  45. data/lib/rhc/rest/client.rb +11 -9
  46. data/lib/rhc/rest/domain.rb +5 -1
  47. data/lib/rhc/rest/gear_group.rb +0 -2
  48. data/lib/rhc/rest/key.rb +0 -2
  49. data/lib/rhc/rest/mock.rb +32 -10
  50. data/lib/rhc/ssh_helpers.rb +2 -2
  51. data/lib/rhc/usage_templates/command_help.erb +20 -13
  52. data/lib/rhc/usage_templates/command_syntax_help.erb +1 -3
  53. data/lib/rhc/usage_templates/help.erb +15 -16
  54. data/lib/rhc/usage_templates/options_help.erb +7 -9
  55. data/lib/rhc/wizard.rb +193 -159
  56. data/spec/rest_spec_helper.rb +2 -2
  57. data/spec/rhc/cli_spec.rb +36 -5
  58. data/spec/rhc/command_spec.rb +94 -42
  59. data/spec/rhc/commands/account_spec.rb +1 -75
  60. data/spec/rhc/commands/alias_spec.rb +28 -28
  61. data/spec/rhc/commands/app_spec.rb +141 -33
  62. data/spec/rhc/commands/apps_spec.rb +4 -4
  63. data/spec/rhc/commands/authorization_spec.rb +8 -8
  64. data/spec/rhc/commands/cartridge_spec.rb +18 -9
  65. data/spec/rhc/commands/domain_spec.rb +16 -16
  66. data/spec/rhc/commands/git_clone_spec.rb +3 -3
  67. data/spec/rhc/commands/logout_spec.rb +86 -0
  68. data/spec/rhc/commands/port_forward_spec.rb +9 -9
  69. data/spec/rhc/commands/server_spec.rb +5 -5
  70. data/spec/rhc/commands/setup_spec.rb +19 -5
  71. data/spec/rhc/commands/snapshot_spec.rb +12 -12
  72. data/spec/rhc/commands/sshkey_spec.rb +11 -11
  73. data/spec/rhc/commands/tail_spec.rb +5 -5
  74. data/spec/rhc/commands/threaddump_spec.rb +3 -3
  75. data/spec/rhc/config_spec.rb +6 -6
  76. data/spec/rhc/helpers_spec.rb +72 -219
  77. data/spec/rhc/highline_extensions_spec.rb +269 -0
  78. data/spec/rhc/rest_application_spec.rb +28 -1
  79. data/spec/rhc/rest_client_spec.rb +20 -21
  80. data/spec/rhc/rest_spec.rb +10 -0
  81. data/spec/rhc/wizard_spec.rb +72 -32
  82. data/spec/spec_helper.rb +86 -56
  83. data/spec/wizard_spec_helper.rb +7 -4
  84. metadata +165 -160
  85. data/spec/spec.opts +0 -1
@@ -10,13 +10,13 @@ describe RHC::Commands::Domain do
10
10
  context 'when run with no domains' do
11
11
  let(:arguments) { ['domain', '--noprompt', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password'] }
12
12
 
13
- it { expect { run }.should exit_with_code(1) }
13
+ it { expect { run }.to exit_with_code(1) }
14
14
  it { run_output.should match(/In order to deploy applications.*rhc domain create/) }
15
15
  end
16
16
  context 'when help is shown' do
17
17
  let(:arguments) { ['domain', '--noprompt', '--help'] }
18
18
 
19
- it { expect { run }.should exit_with_code(0) }
19
+ it { expect { run }.to exit_with_code(0) }
20
20
  it { run_output.should match(/The default action for this resource is 'show'/) }
21
21
  end
22
22
  end
@@ -25,14 +25,14 @@ describe RHC::Commands::Domain do
25
25
  let(:arguments) { ['domain', 'show', '--noprompt', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password'] }
26
26
 
27
27
  context 'when run with no domains' do
28
- it { expect { run }.should exit_with_code(1) }
28
+ it { expect { run }.to exit_with_code(1) }
29
29
  it { run_output.should match(/In order to deploy applications.*rhc domain create/) }
30
30
  end
31
31
 
32
32
  context 'when run with one domain no apps' do
33
33
  before{ rest_client.add_domain("onedomain") }
34
34
 
35
- it { expect { run }.should exit_with_code(0) }
35
+ it { expect { run }.to exit_with_code(0) }
36
36
  it "should match output" do
37
37
  output = run_output
38
38
  output.should match("The domain onedomain exists but has no applications. You can use")
@@ -44,7 +44,7 @@ describe RHC::Commands::Domain do
44
44
  rest_client.add_domain("firstdomain")
45
45
  rest_client.add_domain("seconddomain")
46
46
  end
47
- it { expect { run }.should exit_with_code(0) }
47
+ it { expect { run }.to exit_with_code(0) }
48
48
  it "should match output" do
49
49
  output = run_output
50
50
  output.should match("The domain firstdomain exists but has no applications. You can use")
@@ -61,7 +61,7 @@ describe RHC::Commands::Domain do
61
61
  a.add_cartridge("testcart-2")
62
62
  a.add_cartridge("testcart-3")
63
63
  end
64
- it { expect { run }.should exit_with_code(0) }
64
+ it { expect { run }.to exit_with_code(0) }
65
65
  it "should match output" do
66
66
  output = run_output
67
67
  output.should match("app_no_carts")
@@ -78,7 +78,7 @@ describe RHC::Commands::Domain do
78
78
  d = rest_client.add_domain("appdomain")
79
79
  a = d.add_application("app_no_carts")
80
80
  end
81
- it { expect { run }.should exit_with_code(0) }
81
+ it { expect { run }.to exit_with_code(0) }
82
82
  it "should match output" do
83
83
  output = run_output
84
84
  output.should match("app_no_carts")
@@ -93,7 +93,7 @@ describe RHC::Commands::Domain do
93
93
  context 'when no issues with ' do
94
94
 
95
95
  it "should create a domain" do
96
- expect { run }.should exit_with_code(0)
96
+ expect { run }.to exit_with_code(0)
97
97
  rest_client.domains[0].id.should == 'testnamespace'
98
98
  end
99
99
  it { run_output.should match(/'testnamespace'.*?RESULT:.*?Success/m) }
@@ -107,7 +107,7 @@ describe RHC::Commands::Domain do
107
107
  before{ rest_client.add_domain("olddomain") }
108
108
 
109
109
  it "should update a domain" do
110
- expect { run }.should exit_with_code(0)
110
+ expect { run }.to exit_with_code(0)
111
111
  rest_client.domains[0].id.should == 'alterednamespace'
112
112
  end
113
113
  it { run_output.should match(/Changing namespace 'olddomain' to 'alterednamespace'.*?RESULT:.*?Success/m) }
@@ -115,7 +115,7 @@ describe RHC::Commands::Domain do
115
115
 
116
116
  context 'when there is no domain' do
117
117
  it "should not create a domain" do
118
- expect { run }.should exit_with_code(127)
118
+ expect { run }.to exit_with_code(127)
119
119
  rest_client.domains.empty?.should be_true
120
120
  end
121
121
  it { run_output.should match("not found") }
@@ -129,7 +129,7 @@ describe RHC::Commands::Domain do
129
129
  before{ rest_client.add_domain("olddomain") }
130
130
 
131
131
  it "should update a domain" do
132
- expect { run }.should exit_with_code(0)
132
+ expect { run }.to exit_with_code(0)
133
133
  rest_client.domains[0].id.should == 'alterednamespace'
134
134
  end
135
135
  it { run_output.should match(/Changing namespace 'olddomain' to 'alterednamespace'.*?RESULT:.*?Success/m) }
@@ -143,7 +143,7 @@ describe RHC::Commands::Domain do
143
143
  before{ rest_client.add_domain("deleteme") }
144
144
 
145
145
  it "should delete a domain" do
146
- expect { run }.should exit_with_code(0)
146
+ expect { run }.to exit_with_code(0)
147
147
  rest_client.domains.empty?.should be_true
148
148
  end
149
149
  end
@@ -152,7 +152,7 @@ describe RHC::Commands::Domain do
152
152
  before{ rest_client.add_domain("dontdelete") }
153
153
 
154
154
  it "should error out" do
155
- expect { run }.should exit_with_code(127)
155
+ expect { run }.to exit_with_code(127)
156
156
  rest_client.domains[0].id.should == 'dontdelete'
157
157
  end
158
158
  it { run_output.should match("Domain deleteme not found") }
@@ -164,7 +164,7 @@ describe RHC::Commands::Domain do
164
164
  domain.add_application 'testapp1', 'mock-1.0'
165
165
  end
166
166
  it "should error out" do
167
- expect { run }.should exit_with_code(128)
167
+ expect { run }.to exit_with_code(128)
168
168
  rest_client.domains[0].id.should == 'deleteme'
169
169
  end
170
170
  it { run_output.should match("Domain contains applications.*?Delete applications first.") }
@@ -178,7 +178,7 @@ describe RHC::Commands::Domain do
178
178
  before{ rest_client.add_domain("deleteme") }
179
179
 
180
180
  it "should delete a domain" do
181
- expect { run }.should exit_with_code(0)
181
+ expect { run }.to exit_with_code(0)
182
182
  rest_client.domains.empty?.should be_true
183
183
  end
184
184
  end
@@ -189,7 +189,7 @@ describe RHC::Commands::Domain do
189
189
 
190
190
  context 'help is run' do
191
191
  it "should display help" do
192
- expect { run }.should exit_with_code(0)
192
+ expect { run }.to exit_with_code(0)
193
193
  end
194
194
  it('should output usage') { run_output.should match("Usage: rhc domain") }
195
195
  end
@@ -42,7 +42,7 @@ describe RHC::Commands::GitClone do
42
42
  end
43
43
  end
44
44
 
45
- it { expect { run }.should exit_with_code(0) }
45
+ it { expect { run }.to exit_with_code(0) }
46
46
  it { run_output.should match("Cloned") }
47
47
  end
48
48
 
@@ -65,14 +65,14 @@ describe RHC::Commands::GitClone do
65
65
  FakeFS::FileSystem.find(hook))
66
66
  end
67
67
  end
68
- it { expect { run }.should exit_with_code(0) }
68
+ it { expect { run }.to exit_with_code(0) }
69
69
  it { run_output.should match("Copied") }
70
70
  end
71
71
 
72
72
  context "reports failure" do
73
73
  before{ @instance.stub(:git_clone_repo).and_raise(RHC::GitException) }
74
74
 
75
- it { expect { run }.should exit_with_code(216) }
75
+ it { expect { run }.to exit_with_code(216) }
76
76
  it { run_output.should match("Git returned an error") }
77
77
  end
78
78
  end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+ require 'rest_spec_helper'
3
+ require 'rhc'
4
+ require 'rhc/commands/logout'
5
+
6
+ describe RHC::Commands::Logout do
7
+
8
+ describe '#run' do
9
+ let(:arguments) { ['logout'] }
10
+ let(:username) { 'foo' }
11
+ let(:password) { nil }
12
+ let(:supports_auth) { false }
13
+ let(:server) { mock_uri }
14
+ let!(:token_store) { RHC::Auth::TokenStore.new(Dir.mktmpdir) }
15
+ before{ user_config }
16
+ before do
17
+ stub_api(mock_user_auth, supports_auth)
18
+ stub_user
19
+ RHC::Auth::TokenStore.should_receive(:new).at_least(0).times.and_return(token_store)
20
+ end
21
+
22
+ context "when calling from the alias" do
23
+ let(:arguments){ ['account', 'logout', '-h'] }
24
+ it("should print usage"){ run_output.should match "Usage: rhc logout" }
25
+ end
26
+
27
+ it("should clear the token cache"){ expect{ run }.to call(:clear).on(token_store) }
28
+ it("should exit with success"){ expect{ run }.to exit_with_code(0) }
29
+ it("should display a message"){ run_output.should match("All local sessions removed.") }
30
+
31
+ context "when --all is requested" do
32
+ let(:arguments) { ['account', 'logout', '--all'] }
33
+
34
+ context "if the server does not implement authorizations" do
35
+ it("should display a message"){ run_output.should match(/Deleting all authorizations associated with your account.*not supported/) }
36
+ it("should exit with success"){ expect{ run }.to exit_with_code(0) }
37
+ end
38
+
39
+ context "if the server implements authorizations" do
40
+ let(:supports_auth) { true }
41
+ before{ stub_delete_authorizations }
42
+
43
+ it("should display a message"){ run_output.should match(/Deleting all authorizations associated with your account.*done/) }
44
+ it("should exit with success"){ expect{ run }.to exit_with_code(0) }
45
+ end
46
+ end
47
+
48
+ context "when --token is provided" do
49
+ let(:arguments) { ['account', 'logout', '--token', 'foo'] }
50
+ def user_auth; { :token => 'foo' }; end
51
+
52
+ context "if the server does not implement authorizations" do
53
+ it("should display a message"){ run_output.should match(/Ending session on server.*not supported/) }
54
+ it("should exit with success"){ expect{ run }.to exit_with_code(0) }
55
+ end
56
+
57
+ context "if the server implements authorizations" do
58
+ let(:supports_auth) { true }
59
+
60
+ context "if the server returns successfully" do
61
+ before{ stub_delete_authorization('foo') }
62
+
63
+ it("should display a message"){ run_output.should match(/Ending session on server.*deleted/) }
64
+ it("should exit with success"){ expect{ run }.to exit_with_code(0) }
65
+ it("should clear the token cache"){ expect{ run }.to call(:clear).on(token_store) }
66
+ end
67
+
68
+ context "if the server rejects the token" do
69
+ before{ stub_request(:delete, mock_href('broker/rest/user/authorizations/foo', false)).to_return(:status => 401, :body => {}.to_json) }
70
+
71
+ it("should display a message"){ run_output.should match(/Ending session on server.*already closed/) }
72
+ it("should exit with success"){ expect{ run }.to exit_with_code(0) }
73
+ it("should clear the token cache"){ expect{ run }.to call(:clear).on(token_store) }
74
+ end
75
+
76
+ context "if the server returns an unexpected error" do
77
+ before{ stub_request(:delete, mock_href('broker/rest/user/authorizations/foo', false)).to_return(:status => 500, :body => {}.to_json) }
78
+
79
+ it("should display a message"){ run_output.should match(/Ending session on server.*The server did not respond/) }
80
+ it("should exit with success"){ expect{ run }.to exit_with_code(0) }
81
+ it("should clear the token cache"){ expect{ run }.to call(:clear).on(token_store) }
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -26,7 +26,7 @@ describe RHC::Commands::PortForward do
26
26
  @gg.should_receive(:gears).and_return([{'state' => 'stopped', 'id' => 'fakegearid'}])
27
27
  end
28
28
  it "should error out and suggest restarting the application" do
29
- expect { run }.should exit_with_code(1)
29
+ expect { run }.to exit_with_code(1)
30
30
  end
31
31
  it { run_output.should match(/Application \S+ is stopped\..*restart/m) }
32
32
  end
@@ -37,7 +37,7 @@ describe RHC::Commands::PortForward do
37
37
  @ssh.should_receive(:exec!).with("rhc-list-ports").and_yield(nil, :stderr, '127.0.0.1:3306')
38
38
  end
39
39
  it "should error out as no ports to forward" do
40
- expect { run }.should exit_with_code(102)
40
+ expect { run }.to exit_with_code(102)
41
41
  rest_client.domains[0].id.should == 'mockdomain'
42
42
  rest_client.domains[0].applications.size.should == 1
43
43
  rest_client.domains[0].applications[0].name.should == 'mockapp'
@@ -51,7 +51,7 @@ describe RHC::Commands::PortForward do
51
51
  @ssh.should_receive(:exec!).with("rhc-list-ports").and_yield(nil, :stderr, 'permission denied')
52
52
  end
53
53
  it "should error out as permission denied" do
54
- expect { run }.should exit_with_code(129)
54
+ expect { run }.to exit_with_code(129)
55
55
  rest_client.domains[0].id.should == 'mockdomain'
56
56
  rest_client.domains[0].applications.size.should == 1
57
57
  rest_client.domains[0].applications[0].name.should == 'mockapp'
@@ -69,7 +69,7 @@ describe RHC::Commands::PortForward do
69
69
  @ssh.should_receive(:loop)
70
70
  end
71
71
  it "should run successfully" do
72
- expect { run }.should exit_with_code(0)
72
+ expect { run }.to exit_with_code(0)
73
73
  rest_client.domains[0].id.should == 'mockdomain'
74
74
  rest_client.domains[0].applications.size.should == 1
75
75
  rest_client.domains[0].applications[0].name.should == 'mockapp'
@@ -82,7 +82,7 @@ describe RHC::Commands::PortForward do
82
82
  Net::SSH.should_receive(:start).and_raise(Errno::EHOSTUNREACH)
83
83
  end
84
84
  it "should error out" do
85
- expect { run }.should exit_with_code(1)
85
+ expect { run }.to exit_with_code(1)
86
86
  rest_client.domains[0].id.should == 'mockdomain'
87
87
  rest_client.domains[0].applications.size.should == 1
88
88
  rest_client.domains[0].applications[0].name.should == 'mockapp'
@@ -94,7 +94,7 @@ describe RHC::Commands::PortForward do
94
94
  before(:each) do
95
95
  rest_client.should_receive(:find_domain).and_raise(RHC::Rest::ConnectionException)
96
96
  end
97
- it("should error out") { expect { run }.should exit_with_code(1) }
97
+ it("should error out") { expect { run }.to exit_with_code(1) }
98
98
  it{ run_output.should match("Connection.*failed:") }
99
99
  end
100
100
 
@@ -108,7 +108,7 @@ describe RHC::Commands::PortForward do
108
108
  @ssh.should_receive(:loop).and_raise(Interrupt.new)
109
109
  end
110
110
  it "should exit when user interrupts" do
111
- expect { run }.should exit_with_code(0)
111
+ expect { run }.to exit_with_code(0)
112
112
  rest_client.domains[0].id.should == 'mockdomain'
113
113
  rest_client.domains[0].applications.size.should == 1
114
114
  rest_client.domains[0].applications[0].name.should == 'mockapp'
@@ -139,7 +139,7 @@ describe RHC::Commands::PortForward do
139
139
  @ssh.should_receive(:forward).and_raise(Errno::ECONNREFUSED)
140
140
  end
141
141
  it "should error out" do
142
- expect { run }.should exit_with_code(0)
142
+ expect { run }.to exit_with_code(0)
143
143
  end
144
144
  it { run_output.should include("ssh -N") }
145
145
  it { run_output.should include("Error forwarding") }
@@ -164,7 +164,7 @@ describe RHC::Commands::PortForward do
164
164
  @ssh.should_receive(:loop).and_raise(Interrupt.new)
165
165
  end
166
166
  it "should exit when user interrupts" do
167
- expect { run }.should exit_with_code(0)
167
+ expect { run }.to exit_with_code(0)
168
168
  rest_client.domains[0].id.should == 'mockdomain'
169
169
  rest_client.domains[0].applications.size.should == 1
170
170
  rest_client.domains[0].applications[0].name.should == 'mockapp'
@@ -13,13 +13,13 @@ describe RHC::Commands::Server do
13
13
  context 'when server refuses connection' do
14
14
  before { stub_request(:get, 'https://foo.com/broker/rest/api').with(&user_agent_header).with(&expect_authorization(:user => 'person')).to_raise(SocketError) }
15
15
  it('should output an error') { run_output.should =~ /Connected to foo.com.*Unable to connect to the server/m }
16
- it { expect { run }.should exit_with_code(1) }
16
+ it { expect { run }.to exit_with_code(1) }
17
17
  end
18
18
 
19
19
  context 'when API is missing' do
20
20
  before { stub_request(:get, 'https://foo.com/broker/rest/api').with(&user_agent_header).with(&expect_authorization(:user => 'person')).to_return(:status => 404) }
21
21
  it('should output an error') { run_output.should =~ /Connected to foo.com.*server is not responding correctly/m }
22
- it { expect { run }.should exit_with_code(1) }
22
+ it { expect { run }.to exit_with_code(1) }
23
23
  end
24
24
 
25
25
  context 'when API is at version 1.2' do
@@ -27,7 +27,7 @@ describe RHC::Commands::Server do
27
27
  rest_client.stub(:api_version_negotiated).and_return('1.2')
28
28
  end
29
29
  it('should output an error') { run_output.should =~ /Connected to foo.com.*Using API version 1.2/m }
30
- it { expect { run }.should exit_with_code(0) }
30
+ it { expect { run }.to exit_with_code(0) }
31
31
  end
32
32
  end
33
33
 
@@ -38,7 +38,7 @@ describe RHC::Commands::Server do
38
38
  context 'when no issues' do
39
39
  before { stub_request(:get, 'https://openshift.redhat.com/app/status/status.json').with(&user_agent_header).to_return(:body => {'issues' => []}.to_json) }
40
40
  it('should output success') { run_output.should =~ /All systems running fine/ }
41
- it { expect { run }.should exit_with_code(0) }
41
+ it { expect { run }.to exit_with_code(0) }
42
42
  end
43
43
 
44
44
  context 'when 1 issue' do
@@ -55,7 +55,7 @@ describe RHC::Commands::Server do
55
55
  }]
56
56
  }}]}.to_json)
57
57
  end
58
- it { expect { run }.should exit_with_code(1) }
58
+ it { expect { run }.to exit_with_code(1) }
59
59
  it('should output message') { run_output.should =~ /1 open issue/ }
60
60
  it('should output title') { run_output.should =~ /Root cause/ }
61
61
  it('should contain update') { run_output.should =~ /Working on update/ }
@@ -24,14 +24,14 @@ describe RHC::Commands::Setup do
24
24
 
25
25
  context 'when no issues' do
26
26
  it "should exit 0" do
27
- expect { run }.should exit_with_code(0)
27
+ expect { run }.to exit_with_code(0)
28
28
  end
29
29
  end
30
30
 
31
31
  context 'when there is an issue' do
32
32
  it "should exit 1" do
33
33
  @wizard.stub!(:run).and_return(false)
34
- expect { run }.should exit_with_code(1)
34
+ expect { run }.to exit_with_code(1)
35
35
  end
36
36
  end
37
37
  end
@@ -72,7 +72,7 @@ describe RHC::Commands::Setup do
72
72
  let(:input) { ['', 'y', '', ''] }
73
73
  let!(:rest_client){ MockRestClient.new }
74
74
 
75
- it("succeeds"){ FakeFS{ expect { run input }.should exit_with_code 0 } }
75
+ it("succeeds"){ FakeFS{ expect { run input }.to exit_with_code 0 } }
76
76
  it("the output includes debug output") do
77
77
  FakeFS{ run_output( input ).should match 'DEBUG' }
78
78
  end
@@ -84,7 +84,7 @@ describe RHC::Commands::Setup do
84
84
  let(:input) { ['', 'y', '', ''] }
85
85
  let!(:rest_client){ MockRestClient.new }
86
86
 
87
- it("succeeds"){ FakeFS{ expect { run input }.should exit_with_code 0 } }
87
+ it("succeeds"){ FakeFS{ expect { run input }.to exit_with_code 0 } }
88
88
  it("sets the user name to the value given by the command line") do
89
89
  FakeFS{ run_output( input ).should match 'test@test.foo' }
90
90
  end
@@ -96,9 +96,23 @@ describe RHC::Commands::Setup do
96
96
  context 'help is run' do
97
97
  it "should display help" do
98
98
  @wizard.stub!(:run).and_return(true)
99
- expect { run }.should exit_with_code(0)
99
+ expect { run }.to exit_with_code(0)
100
100
  end
101
101
  it('should output usage') { run_output.should match("Connects to an OpenShift server to get you started. Will") }
102
102
  end
103
103
  end
104
+
105
+ describe '--autocomplete' do
106
+ let(:arguments) { ['setup', '--autocomplete'] }
107
+ before do
108
+ path = File.join(Gem.loaded_specs['rhc'].full_gem_path, "autocomplete")
109
+ FakeFS::FileUtils.mkdir_p(path)
110
+ FakeFS::FileUtils.touch(File.join(path, "rhc_bash"))
111
+ end
112
+
113
+ context 'is passed' do
114
+ it('should output information') { FakeFS{ run_output.should match("To enable tab-completion") } }
115
+ it('should output the gem path') { FakeFS{ run_output.should match File.join(RHC::Config.home_conf_dir, 'bash_autocomplete') } }
116
+ end
117
+ end
104
118
  end
@@ -9,7 +9,7 @@ describe RHC::Commands::Snapshot do
9
9
  APP_NAME = 'mockapp'
10
10
 
11
11
  let!(:rest_client) { MockRestClient.new }
12
- before(:each) do
12
+ before do
13
13
  user_config
14
14
  @app = rest_client.add_domain("mockdomain").add_application APP_NAME, 'mock-1.0'
15
15
  @ssh_uri = URI.parse @app.ssh_url
@@ -17,14 +17,14 @@ describe RHC::Commands::Snapshot do
17
17
  FileUtils.cp(File.expand_path('../../assets/targz_sample.tar.gz', __FILE__), filename)
18
18
  end
19
19
 
20
- after(:each) do
20
+ after do
21
21
  filename = APP_NAME + '.tar.gz'
22
22
  File.delete filename if File.exist? filename
23
23
  end
24
24
 
25
25
  describe 'snapshot without an action' do
26
26
  let(:arguments) {['snapshot', '--trace', '--noprompt']}
27
- it('should raise') { expect{ run }.should raise_error(ArgumentError, /Please specify an action to take/) }
27
+ it('should raise') { expect{ run }.to raise_error(ArgumentError, /Please specify an action to take/) }
28
28
  end
29
29
 
30
30
  describe 'snapshot save' do
@@ -35,7 +35,7 @@ describe RHC::Commands::Snapshot do
35
35
  `(exit 0)`
36
36
  Kernel.should_receive(:`).with("ssh #{@ssh_uri.user}@#{@ssh_uri.host} 'snapshot' > #{@app.name}.tar.gz")
37
37
  end
38
- it { expect { run }.should exit_with_code(0) }
38
+ it { expect { run }.to exit_with_code(0) }
39
39
  end
40
40
 
41
41
  context 'when failing to save a snapshot' do
@@ -43,7 +43,7 @@ describe RHC::Commands::Snapshot do
43
43
  `(exit 1)`
44
44
  Kernel.should_receive(:`).with("ssh #{@ssh_uri.user}@#{@ssh_uri.host} 'snapshot' > #{@app.name}.tar.gz")
45
45
  end
46
- it { expect { run }.should exit_with_code(130) }
46
+ it { expect { run }.to exit_with_code(130) }
47
47
  end
48
48
 
49
49
  context 'when saving a snapshot on windows' do
@@ -55,7 +55,7 @@ describe RHC::Commands::Snapshot do
55
55
  Net::SSH.should_receive(:start).with(@ssh_uri.host, @ssh_uri.user).and_yield(ssh)
56
56
  ssh.should_receive(:exec!).with("snapshot").and_yield(nil, :stdout, 'foo').and_yield(nil, :stderr, 'foo')
57
57
  end
58
- it { expect { run }.should exit_with_code(0) }
58
+ it { expect { run }.to exit_with_code(0) }
59
59
  it { run_output.should match("Success") }
60
60
  end
61
61
 
@@ -67,7 +67,7 @@ describe RHC::Commands::Snapshot do
67
67
  ssh = mock(Net::SSH)
68
68
  Net::SSH.should_receive(:start).with(@ssh_uri.host, @ssh_uri.user).and_raise(Timeout::Error)
69
69
  end
70
- it { expect { run }.should exit_with_code(130) }
70
+ it { expect { run }.to exit_with_code(130) }
71
71
  end
72
72
 
73
73
  end
@@ -82,7 +82,7 @@ describe RHC::Commands::Snapshot do
82
82
  `(exit 0)`
83
83
  Kernel.should_receive(:`).with("cat #{@app.name}.tar.gz | ssh #{@ssh_uri.user}@#{@ssh_uri.host} 'restore INCLUDE_GIT'")
84
84
  end
85
- it { expect { run }.should exit_with_code(0) }
85
+ it { expect { run }.to exit_with_code(0) }
86
86
  end
87
87
 
88
88
  context 'when restoring a snapshot and failing to ssh' do
@@ -92,7 +92,7 @@ describe RHC::Commands::Snapshot do
92
92
  Kernel.should_receive(:`).with("cat #{@app.name}.tar.gz | ssh #{@ssh_uri.user}@#{@ssh_uri.host} 'restore INCLUDE_GIT'")
93
93
  $?.stub(:exitstatus) { 1 }
94
94
  end
95
- it { expect { run }.should exit_with_code(130) }
95
+ it { expect { run }.to exit_with_code(130) }
96
96
  end
97
97
 
98
98
  context 'when restoring a snapshot on windows' do
@@ -119,7 +119,7 @@ describe RHC::Commands::Snapshot do
119
119
  channel.should_receive(:eof!)
120
120
  session.should_receive(:loop)
121
121
  end
122
- it { expect { run }.should exit_with_code(0) }
122
+ it { expect { run }.to exit_with_code(0) }
123
123
  end
124
124
 
125
125
  context 'when timing out on windows' do
@@ -130,7 +130,7 @@ describe RHC::Commands::Snapshot do
130
130
  ssh = mock(Net::SSH)
131
131
  Net::SSH.should_receive(:start).with(@ssh_uri.host, @ssh_uri.user).and_raise(Timeout::Error)
132
132
  end
133
- it { expect { run }.should exit_with_code(130) }
133
+ it { expect { run }.to exit_with_code(130) }
134
134
  end
135
135
 
136
136
  end
@@ -138,7 +138,7 @@ describe RHC::Commands::Snapshot do
138
138
  describe 'snapshot restore file not found' do
139
139
  let(:arguments) {['snapshot', 'restore', '--noprompt', '-l', 'test@test.foo', '-p', 'password', '--app', 'mockapp', '-f', 'foo.tar.gz']}
140
140
  context 'when restoring a snapshot' do
141
- it { expect { run }.should exit_with_code(130) }
141
+ it { expect { run }.to exit_with_code(130) }
142
142
  end
143
143
  end
144
144