rhc 1.11.4 → 1.12.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/autocomplete/rhc_bash +39 -23
  2. data/features/domain.feature +8 -3
  3. data/features/lib/rhc_helper/commandify.rb +6 -0
  4. data/features/lib/rhc_helper/domain.rb +1 -1
  5. data/features/step_definitions/domain_steps.rb +9 -4
  6. data/lib/rhc/auth/basic.rb +4 -2
  7. data/lib/rhc/cli.rb +1 -0
  8. data/lib/rhc/commands/apps.rb +2 -4
  9. data/lib/rhc/commands/cartridge.rb +1 -0
  10. data/lib/rhc/commands/domain.rb +25 -11
  11. data/lib/rhc/commands/port_forward.rb +0 -1
  12. data/lib/rhc/commands/sshkey.rb +1 -1
  13. data/lib/rhc/helpers.rb +1 -0
  14. data/lib/rhc/highline_extensions.rb +2 -1
  15. data/lib/rhc/output_helpers.rb +21 -0
  16. data/lib/rhc/rest.rb +4 -2
  17. data/lib/rhc/rest/api.rb +9 -11
  18. data/lib/rhc/rest/application.rb +4 -0
  19. data/lib/rhc/rest/base.rb +11 -1
  20. data/lib/rhc/rest/cartridge.rb +1 -1
  21. data/lib/rhc/rest/client.rb +52 -29
  22. data/lib/rhc/rest/domain.rb +11 -1
  23. data/lib/rhc/rest/httpclient.rb +125 -0
  24. data/lib/rhc/rest/mock.rb +32 -8
  25. data/spec/rhc/auth_spec.rb +29 -22
  26. data/spec/rhc/command_spec.rb +13 -9
  27. data/spec/rhc/commands/account_spec.rb +2 -2
  28. data/spec/rhc/commands/app_spec.rb +9 -9
  29. data/spec/rhc/commands/authorization_spec.rb +11 -11
  30. data/spec/rhc/commands/cartridge_spec.rb +3 -3
  31. data/spec/rhc/commands/domain_spec.rb +51 -1
  32. data/spec/rhc/commands/logout_spec.rb +3 -3
  33. data/spec/rhc/commands/port_forward_spec.rb +7 -7
  34. data/spec/rhc/commands/server_spec.rb +2 -2
  35. data/spec/rhc/commands/setup_spec.rb +6 -6
  36. data/spec/rhc/commands/snapshot_spec.rb +10 -10
  37. data/spec/rhc/helpers_spec.rb +6 -6
  38. data/spec/rhc/rest_application_spec.rb +11 -11
  39. data/spec/rhc/rest_client_spec.rb +148 -36
  40. data/spec/rhc/rest_spec.rb +3 -3
  41. data/spec/rhc/wizard_spec.rb +20 -20
  42. data/spec/spec_helper.rb +52 -3
  43. metadata +5 -4
@@ -56,10 +56,10 @@ describe RHC::Commands::Base do
56
56
  it("should run with wizard") do
57
57
  FakeFS do
58
58
  wizard_run = false
59
- RHC::Wizard.stub!(:new) do |config|
59
+ RHC::Wizard.stub(:new) do |config|
60
60
  RHC::Wizard.unstub!(:new)
61
61
  w = RHC::Wizard.new(config)
62
- w.stub!(:run) { wizard_run = true }
62
+ w.stub(:run) { wizard_run = true }
63
63
  w
64
64
  end
65
65
 
@@ -238,10 +238,10 @@ describe RHC::Commands::Base do
238
238
  before{ RHC::Rest::Client.any_instance.stub(:api_version_negotiated).and_return(1.4) }
239
239
 
240
240
  context "when initializing the object" do
241
- let(:auth){ mock('auth') }
242
- let(:basic_auth){ mock('basic_auth') }
241
+ let(:auth){ double('auth') }
242
+ let(:basic_auth){ double('basic_auth') }
243
243
  before{ RHC::Auth::Basic.should_receive(:new).at_least(1).times.with{ |arg| arg.should == instance.send(:options) }.and_return(basic_auth) }
244
- before{ RHC::Auth::Token.should_receive(:new).any_number_of_times.with{ |arg, arg2, arg3| [arg, arg2, arg3].should == [instance.send(:options), basic_auth, instance.send(:token_store)] }.and_return(auth) }
244
+ before{ RHC::Auth::Token.stub(:new).with{ |arg, arg2, arg3| [arg, arg2, arg3].should == [instance.send(:options), basic_auth, instance.send(:token_store)] }.and_return(auth) }
245
245
 
246
246
  context "with no options" do
247
247
  before{ subject.should_receive(:client_from_options).with(:auth => basic_auth) }
@@ -275,7 +275,7 @@ describe RHC::Commands::Base do
275
275
  let(:username){ 'foo' }
276
276
  let(:password){ 'bar' }
277
277
  let(:arguments){ ['test', '-l', username, '--server', mock_uri] }
278
- before{ stub_api(:user => username); stub_user(:user => username, :password => password) }
278
+ before{ stub_api; challenge{ stub_user(:user => username, :password => password) } }
279
279
  before{ basic_auth.should_receive(:ask).and_return(password) }
280
280
  it("asks for password") { rest_client.user }
281
281
  end
@@ -284,7 +284,7 @@ describe RHC::Commands::Base do
284
284
  let(:username){ 'foo' }
285
285
  let(:password){ 'bar' }
286
286
  let(:arguments){ ['test', '--server', mock_uri] }
287
- before{ stub_api; stub_user(:user => username, :password => password) }
287
+ before{ stub_api; challenge{ stub_user(:user => username, :password => password) } }
288
288
  before{ basic_auth.should_receive(:ask).ordered.and_return(username) }
289
289
  before{ basic_auth.should_receive(:ask).ordered.and_return(password) }
290
290
  it("asks for password") { rest_client.user }
@@ -320,7 +320,7 @@ describe RHC::Commands::Base do
320
320
  context "with username and tokens enabled" do
321
321
  let!(:config){ base_config{ |c, d| d.add('use_authorization_tokens', 'true') } }
322
322
  let(:username){ 'foo' }
323
- let(:auth_token){ stub(:token => 'a_token') }
323
+ let(:auth_token){ double(:token => 'a_token') }
324
324
  let(:arguments){ ['test', '-l', username, '--server', mock_uri] }
325
325
  before{ instance.send(:token_store).should_receive(:get).with{ |user, server| user.should == username; server.should == instance.send(:openshift_server) }.and_return(nil) }
326
326
  before{ stub_api(false, true); stub_api_request(:get, 'broker/rest/user', false).to_return{ |request| request.headers['Authorization'] =~ /Bearer/ ? simple_user(username) : {:status => 401} } }
@@ -335,7 +335,11 @@ describe RHC::Commands::Base do
335
335
  let(:username){ 'foo' }
336
336
  let(:arguments){ ['test', '-l', username, '--server', mock_uri] }
337
337
  before{ instance.send(:token_store).should_receive(:get).with{ |user, server| user.should == username; server.should == instance.send(:openshift_server) }.and_return(nil) }
338
- before{ stub_api(false, false); stub_api_request(:get, 'broker/rest/user', false).to_return{ |request| request.headers['Authorization'] =~ /Basic/ ? simple_user(username) : {:status => 401} } }
338
+ before do
339
+ stub_api(false, false)
340
+ stub_api_request(:get, 'broker/rest/user', false).to_return{ |request| request.headers['Authorization'] =~ /Basic/ ? simple_user(username) : {:status => 401, :headers => {'WWW-Authenticate' => 'Basic realm="openshift broker"'} } }
341
+ stub_api_request(:get, 'broker/rest/user', {:user => username, :password => 'password'}).to_return{ simple_user(username) }
342
+ end
339
343
  it("should prompt for password") do
340
344
  basic_auth.should_receive(:ask).once.and_return('password')
341
345
  rest_client.user
@@ -12,8 +12,8 @@ describe RHC::Commands::Account do
12
12
  let(:server) { mock_uri }
13
13
  before{ user_config }
14
14
  before do
15
- stub_api(true)
16
- stub_user
15
+ stub_api
16
+ challenge{ stub_user }
17
17
  end
18
18
 
19
19
  it('should display the correct user') { run_output.should =~ /Login:\s*#{username}/ }
@@ -55,8 +55,8 @@ describe RHC::Commands::App do
55
55
  end
56
56
 
57
57
  describe '#check_domain!' do
58
- let(:rest_client){ stub('RestClient') }
59
- let(:domain){ stub('Domain', :id => 'test') }
58
+ let(:rest_client){ double('RestClient') }
59
+ let(:domain){ double('Domain', :id => 'test') }
60
60
  before{ subject.stub(:rest_client).and_return(rest_client) }
61
61
  let(:interactive){ false }
62
62
  before{ subject.stub(:interactive?).and_return(interactive) }
@@ -83,7 +83,7 @@ describe RHC::Commands::App do
83
83
  context "when interactive and no domains" do
84
84
  let(:interactive){ true }
85
85
  before{ rest_client.should_receive(:domains).twice.and_return([]) }
86
- before{ RHC::DomainWizard.should_receive(:new).and_return(stub(:run => true)) }
86
+ before{ RHC::DomainWizard.should_receive(:new).and_return(double(:run => true)) }
87
87
  it("should raise if the wizard doesn't set the option"){ expect{ subject.send(:check_domain!) }.to raise_error(RHC::Rest::DomainNotFoundException) }
88
88
  after{ subject.send(:options).namespace.should be_nil }
89
89
  end
@@ -115,7 +115,7 @@ describe RHC::Commands::App do
115
115
 
116
116
  context "when dealing with config" do
117
117
  subject{ described_class.new(Commander::Command::Options.new(options)) }
118
- let(:wizard){ s = stub('Wizard'); RHC::EmbeddedWizard.should_receive(:new).and_return(s); s }
118
+ let(:wizard){ s = double('Wizard'); RHC::EmbeddedWizard.should_receive(:new).and_return(s); s }
119
119
  let(:options){ nil }
120
120
  let(:interactive){ true }
121
121
  before{ subject.should_receive(:interactive?).at_least(1).times.and_return(interactive) }
@@ -142,7 +142,7 @@ describe RHC::Commands::App do
142
142
 
143
143
  context "when dealing with ssh keys" do
144
144
  subject{ described_class.new(options) }
145
- let(:wizard){ s = stub('Wizard'); RHC::SSHWizard.should_receive(:new).and_return(s); s }
145
+ let(:wizard){ s = double('Wizard'); RHC::SSHWizard.should_receive(:new).and_return(s); s }
146
146
  let(:options){ Commander::Command::Options.new(:server => 'foo.com', :rhlogin => 'test') }
147
147
  let(:interactive){ true }
148
148
  before{ subject.should_receive(:interactive?).at_least(1).times.and_return(interactive) }
@@ -300,7 +300,7 @@ describe RHC::Commands::App do
300
300
  before(:each) do
301
301
  domain = rest_client.add_domain("mockdomain")
302
302
  end
303
- it { expect { run }.to_not raise_error(ArgumentError, /The --no-dns option can't be used in conjunction with --enable-jenkins/) }
303
+ it { expect { run }.to_not raise_error }
304
304
  end
305
305
  end
306
306
 
@@ -504,8 +504,8 @@ describe RHC::Commands::App do
504
504
  let(:server){ mock_uri }
505
505
  let(:arguments){ ['delete-app', 'foo', '--confirm', '--trace'] }
506
506
  before do
507
- stub_api(true)
508
- stub_one_domain('test')
507
+ stub_api
508
+ challenge{ stub_one_domain('test') }
509
509
  stub_one_application('test', 'foo')
510
510
  end
511
511
  before do
@@ -703,7 +703,7 @@ describe RHC::Commands::App do
703
703
  describe "#create_app" do
704
704
  it("should list cartridges when a server error happens") do
705
705
  subject.should_receive(:list_cartridges)
706
- domain = stub
706
+ domain = double
707
707
  domain.stub(:add_application).and_raise(RHC::Rest::ValidationException.new('Foo', :cartridges, 109))
708
708
  expect{ subject.send(:create_app, 'name', 'jenkins-1.4', domain) }.to raise_error(RHC::Rest::ValidationException)
709
709
  end
@@ -10,14 +10,14 @@ describe RHC::Commands::Authorization do
10
10
  let(:password) { 'pass' }
11
11
  let(:server) { mock_uri }
12
12
  before{ user_config }
13
- before{ stub_api(true, true) }
13
+ before{ stub_api(false, true) }
14
14
  end
15
15
  def self.without_authorization
16
16
  let(:username) { 'foo' }
17
17
  let(:password) { 'pass' }
18
18
  let(:server) { mock_uri }
19
19
  before{ user_config }
20
- before{ stub_api(true, false) }
20
+ before{ stub_api(false, false) }
21
21
  end
22
22
  def self.expect_an_unsupported_message
23
23
  context "without authorizations" do
@@ -31,7 +31,7 @@ describe RHC::Commands::Authorization do
31
31
  let(:arguments) { ['authorization'] }
32
32
  context "with authorizations" do
33
33
  with_authorization
34
- before{ stub_authorizations }
34
+ before{ challenge{ stub_authorizations } }
35
35
  it('should display the note') { run_output.should =~ /an_authorization/ }
36
36
  it('should display the token') { run_output.should =~ /Token:\s+a_token_value/ }
37
37
  it('should display the expiration') { run_output.should =~ /Expires In:\s+1 minute/ }
@@ -46,8 +46,8 @@ describe RHC::Commands::Authorization do
46
46
  describe '#run' do
47
47
  let(:arguments) { ['authorization', '--h']}
48
48
  context 'given --h' do
49
- it 'should not raise SystemStackError' do
50
- expect{ run }.to_not raise_error(SystemStackError)
49
+ it 'should not raise' do
50
+ expect{ run }.to_not raise_error
51
51
  end
52
52
  end
53
53
  end
@@ -56,7 +56,7 @@ describe RHC::Commands::Authorization do
56
56
  let(:arguments) { ['authorization', 'list'] }
57
57
  context "with authorizations" do
58
58
  with_authorization
59
- before{ stub_authorizations }
59
+ before{ challenge{ stub_authorizations } }
60
60
  it('should display the note') { run_output.should =~ /an_authorization/ }
61
61
  it('should display the token') { run_output.should =~ /Token:\s+a_token_value/ }
62
62
  it('should display the expiration') { run_output.should =~ /Expires In:\s+1 minute/ }
@@ -73,8 +73,8 @@ describe RHC::Commands::Authorization do
73
73
 
74
74
  context "with authorizations" do
75
75
  with_authorization
76
- before{ stub_delete_authorization('foo') }
77
- before{ stub_delete_authorization('bar') }
76
+ before{ challenge{ stub_delete_authorization('foo') } }
77
+ before{ challenge{ stub_delete_authorization('bar') } }
78
78
  it('should display success') { run_output.should =~ /Deleting auth.*done/ }
79
79
  it{ expect{ run }.to exit_with_code(0) }
80
80
  after{ a_request(:delete, mock_href('broker/rest/user/authorizations/foo', true)).should have_been_made }
@@ -95,7 +95,7 @@ describe RHC::Commands::Authorization do
95
95
 
96
96
  context "with authorizations" do
97
97
  with_authorization
98
- before{ stub_delete_authorizations }
98
+ before{ challenge{ stub_delete_authorizations } }
99
99
  it('should display success') { run_output.should =~ /Deleting all auth.*done/ }
100
100
  it{ expect{ run }.to exit_with_code(0) }
101
101
  after{ a_request(:delete, mock_href('broker/rest/user/authorizations', true)).should have_been_made }
@@ -105,7 +105,7 @@ describe RHC::Commands::Authorization do
105
105
  end
106
106
 
107
107
  describe "#scope_help" do
108
- let(:rest_client){ stub(:authorization_scope_list => [['scope_1', 'A description'], ['scope_2', 'Another description']]) }
108
+ let(:rest_client){ double(:authorization_scope_list => [['scope_1', 'A description'], ['scope_2', 'Another description']]) }
109
109
  before{ subject.should_receive(:rest_client).and_return(rest_client) }
110
110
  it{ capture{ subject.send(:scope_help) }.should =~ /scope_1.*A description/ }
111
111
  it{ capture{ subject.send(:scope_help) }.should =~ /scope_2.*Another description/ }
@@ -129,7 +129,7 @@ describe RHC::Commands::Authorization do
129
129
  context "with options" do
130
130
  let(:arguments) { ['authorization', 'add', '--scope', 'foo,bar', '--note', 'a_note', '--expires-in', '300'] }
131
131
  with_authorization
132
- before{ stub_add_authorization(:note => 'a_note', :scope => 'foo,bar', :expires_in => '300') }
132
+ before{ challenge{ stub_add_authorization(:note => 'a_note', :scope => 'foo,bar', :expires_in => '300') } }
133
133
 
134
134
  it('should display success') { run_output.should =~ /Adding authorization.*done/ }
135
135
  it('should display the note') { run_output.should =~ /a_note/ }
@@ -53,7 +53,7 @@ describe RHC::Commands::Cartridge do
53
53
  it{ expect{ run }.to exit_with_code(0) }
54
54
 
55
55
  context 'with verbose list' do
56
- let(:arguments){ ['cartridge', 'list', '--verbose'] }
56
+ let(:arguments){ ['cartridge', 'list', '--verbose', '--trace'] }
57
57
  it{ run_output.should match /Mock1 Cart.*\[mock_standalone_cart\-1\] \(web\)/ }
58
58
  it{ run_output.should match /mock_standalone_cart\-2 \(web\)/ }
59
59
  it{ run_output.should match "Mock2 description\n\n" }
@@ -217,8 +217,8 @@ describe RHC::Commands::Cartridge do
217
217
  let(:server){ mock_uri }
218
218
  let(:arguments){ ['remove-cartridge', 'jenkins-1.4', '-a', 'foo', '--confirm', '--trace'] }
219
219
  before do
220
- stub_api(true)
221
- stub_one_domain('test')
220
+ stub_api(false)
221
+ challenge{ stub_one_domain('test') }
222
222
  stub_one_application('test', 'foo').with(:query => {:include => 'cartridges'})
223
223
  stub_application_cartridges('test', 'foo', [{:name => 'php-5.3'}, {:name => 'jenkins-1.4'}])
224
224
  end
@@ -17,7 +17,7 @@ describe RHC::Commands::Domain do
17
17
  let(:arguments) { ['domain', '--noprompt', '--help'] }
18
18
 
19
19
  it { expect { run }.to exit_with_code(0) }
20
- it { run_output.should match(/The default action for this resource is 'show'/) }
20
+ it { run_output.should match(/The default action for this resource is 'list'/) }
21
21
  end
22
22
  end
23
23
 
@@ -87,6 +87,56 @@ describe RHC::Commands::Domain do
87
87
  end
88
88
  end
89
89
 
90
+
91
+ describe 'list' do
92
+ let(:arguments) { ['domain', 'list'] }
93
+
94
+ context 'when run with no domains' do
95
+ it { expect { run }.to exit_with_code(1) }
96
+ it { run_output.should match(/In order to deploy applications.*rhc create-domain/) }
97
+ end
98
+
99
+ context 'when run with one domain no apps' do
100
+ before{ rest_client.add_domain("onedomain") }
101
+
102
+ it { expect { run }.to exit_with_code(0) }
103
+ it "should match output" do
104
+ output = run_output
105
+ output.should match("You have access to 1 domain\\.")
106
+ output.should match("onedomain")
107
+ end
108
+ end
109
+
110
+ context 'when run with one owned domain' do
111
+ let(:arguments) { ['domains', '--mine'] }
112
+ before{ d = rest_client.add_domain('mine', true); rest_client.stub(:owned_domains).and_return([d]) }
113
+
114
+ it { expect { run }.to exit_with_code(0) }
115
+ it "should match output" do
116
+ output = run_output
117
+ output.should match("You have access to 1 domain\\.")
118
+ output.should match("mine")
119
+ output.should match("Created")
120
+ output.should match("Allowed Gear Sizes: small")
121
+ end
122
+ end
123
+
124
+ context 'when run with multiple domains and extra domain info' do
125
+ before(:each) do
126
+ rest_client.add_domain("firstdomain")
127
+ rest_client.add_domain("seconddomain", true)
128
+ end
129
+ it { expect { run }.to exit_with_code(0) }
130
+ it "should match output" do
131
+ output = run_output
132
+ output.should match("You have access to 2 domains")
133
+ output.should match("seconddomain \\(owned by a_user_name\\)")
134
+ output.should match("Created")
135
+ output.should match("Allowed Gear Sizes: small")
136
+ end
137
+ end
138
+ end
139
+
90
140
  describe 'create' do
91
141
  let(:arguments) { ['domain', 'create', '--noprompt', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password', 'testnamespace'] }
92
142
 
@@ -14,9 +14,9 @@ describe RHC::Commands::Logout do
14
14
  let!(:token_store) { RHC::Auth::TokenStore.new(Dir.mktmpdir) }
15
15
  before{ user_config }
16
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)
17
+ stub_api(false, supports_auth)
18
+ challenge{ stub_user }
19
+ RHC::Auth::TokenStore.stub(:new).and_return(token_store)
20
20
  end
21
21
 
22
22
  context "when calling from the alias" do
@@ -14,7 +14,7 @@ describe RHC::Commands::PortForward do
14
14
  @domain = rest_client.add_domain("mockdomain")
15
15
  @app = @domain.add_application 'mockapp', 'mock-1.0'
16
16
  @uri = URI.parse @app.ssh_url
17
- @ssh = mock(Net::SSH)
17
+ @ssh = double(Net::SSH)
18
18
  end
19
19
 
20
20
  context 'when port forwarding for a down appl' do
@@ -63,7 +63,7 @@ describe RHC::Commands::PortForward do
63
63
  before(:each) do
64
64
  Net::SSH.should_receive(:start).with(@uri.host, @uri.user).and_yield(@ssh).twice
65
65
  @ssh.should_receive(:exec!).with("rhc-list-ports").and_yield(nil, :stderr, 'mysql -> 127.0.0.1:3306')
66
- forward = mock(Net::SSH::Service::Forward)
66
+ forward = double(Net::SSH::Service::Forward)
67
67
  @ssh.should_receive(:forward).and_return(forward)
68
68
  forward.should_receive(:local).with(3306, '127.0.0.1', 3306)
69
69
  @ssh.should_receive(:loop)
@@ -102,7 +102,7 @@ describe RHC::Commands::PortForward do
102
102
  before(:each) do
103
103
  Net::SSH.should_receive(:start).with(@uri.host, @uri.user).and_yield(@ssh).twice
104
104
  @ssh.should_receive(:exec!).with("rhc-list-ports").and_yield(nil, :stderr, 'mysql -> 127.0.0.1:3306')
105
- forward = mock(Net::SSH::Service::Forward)
105
+ forward = double(Net::SSH::Service::Forward)
106
106
  @ssh.should_receive(:forward).and_return(forward)
107
107
  forward.should_receive(:local).with(3306, '127.0.0.1', 3306)
108
108
  @ssh.should_receive(:loop).and_raise(Interrupt.new)
@@ -120,7 +120,7 @@ describe RHC::Commands::PortForward do
120
120
  before(:each) do
121
121
  Net::SSH.should_receive(:start).with(@uri.host, @uri.user).and_yield(@ssh).twice
122
122
  @ssh.should_receive(:exec!).with("rhc-list-ports").and_yield(nil, :stderr, 'mysql -> 127.0.0.1:3306')
123
- forward = mock(Net::SSH::Service::Forward)
123
+ forward = double(Net::SSH::Service::Forward)
124
124
  @ssh.should_receive(:forward).at_least(2).and_return(forward)
125
125
  forward.should_receive(:local).with(3306, '127.0.0.1', 3306).and_raise(Errno::EACCES)
126
126
  forward.should_receive(:local).with(3307, '127.0.0.1', 3306)
@@ -135,7 +135,7 @@ describe RHC::Commands::PortForward do
135
135
  before(:each) do
136
136
  Net::SSH.should_receive(:start).with(@uri.host, @uri.user).and_yield(@ssh).twice
137
137
  @ssh.should_receive(:exec!).with("rhc-list-ports").and_yield(nil, :stderr, 'mysql -> 127.0.0.1:3306')
138
- forward = mock(Net::SSH::Service::Forward)
138
+ forward = double(Net::SSH::Service::Forward)
139
139
  @ssh.should_receive(:forward).and_raise(Errno::ECONNREFUSED)
140
140
  end
141
141
  it "should error out" do
@@ -154,7 +154,7 @@ describe RHC::Commands::PortForward do
154
154
  Net::SSH.should_receive(:start).with(@uri.host, @uri.user).and_yield(@ssh).twice
155
155
  @ssh.should_receive(:exec!).with("rhc-list-ports").
156
156
  and_yield(nil, :stderr, "httpd -> #{haproxy_host_1}:8080\nhttpd -> #{haproxy_host_2}:8080\nmongodb -> #{mongo_host}:35541\nmysqld -> #{ipv6_host}:3306")
157
- forward = mock(Net::SSH::Service::Forward)
157
+ forward = double(Net::SSH::Service::Forward)
158
158
  @ssh.should_receive(:forward).at_least(3).times.and_return(forward)
159
159
  forward.should_receive(:local).with(8080, haproxy_host_1, 8080)
160
160
  forward.should_receive(:local).with(8080, haproxy_host_2, 8080).and_raise(Errno::EADDRINUSE)
@@ -183,7 +183,7 @@ describe RHC::Commands::PortForward do
183
183
 
184
184
  @ssh.should_receive(:exec!).with("rhc-list-ports --exclude-remote").
185
185
  and_yield(nil, :stderr, "mongodb -> #{gear_host}:35541")
186
- forward = mock(Net::SSH::Service::Forward)
186
+ forward = double(Net::SSH::Service::Forward)
187
187
  @ssh.should_receive(:forward).and_return(forward)
188
188
  forward.should_receive(:local).with(35541, gear_host, 35541)
189
189
  @ssh.should_receive(:loop).and_raise(Interrupt.new)
@@ -11,13 +11,13 @@ describe RHC::Commands::Server do
11
11
  let(:arguments) { ['server', '--server', 'foo.com', '-l', 'person', '-p', ''] }
12
12
 
13
13
  context 'when server refuses connection' do
14
- before { stub_request(:get, 'https://foo.com/broker/rest/api').with(&user_agent_header).with(&expect_authorization(:user => 'person')).to_raise(SocketError) }
14
+ before { stub_request(:get, 'https://foo.com/broker/rest/api').with(&user_agent_header).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
16
  it { expect { run }.to exit_with_code(1) }
17
17
  end
18
18
 
19
19
  context 'when API is missing' do
20
- before { stub_request(:get, 'https://foo.com/broker/rest/api').with(&user_agent_header).with(&expect_authorization(:user => 'person')).to_return(:status => 404) }
20
+ before { stub_request(:get, 'https://foo.com/broker/rest/api').with(&user_agent_header).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
22
  it { expect { run }.to exit_with_code(1) }
23
23
  end
@@ -17,9 +17,9 @@ describe RHC::Commands::Setup do
17
17
  let(:arguments) { ['setup', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password'] }
18
18
 
19
19
  before(:each) do
20
- @wizard = mock('wizard')
21
- @wizard.stub!(:run).and_return(true)
22
- RHC::RerunWizard.stub!(:new){ @wizard }
20
+ @wizard = double('wizard')
21
+ @wizard.stub(:run).and_return(true)
22
+ RHC::RerunWizard.stub(:new){ @wizard }
23
23
  end
24
24
 
25
25
  context 'when no issues' do
@@ -30,7 +30,7 @@ describe RHC::Commands::Setup do
30
30
 
31
31
  context 'when there is an issue' do
32
32
  it "should exit 1" do
33
- @wizard.stub!(:run).and_return(false)
33
+ @wizard.stub(:run).and_return(false)
34
34
  expect { run }.to exit_with_code(1)
35
35
  end
36
36
  end
@@ -54,7 +54,7 @@ describe RHC::Commands::Setup do
54
54
  end
55
55
 
56
56
  =begin context 'when libra_server is set' do
57
- before{ ENV.should_receive(:[]).any_number_of_times.with('LIBRA_SERVER').and_return('bar.com') }
57
+ before{ ENV.stub(:[]).with('LIBRA_SERVER').and_return('bar.com') }
58
58
  it{ command_for('setup').config['libra_server'].should == 'bar.com' }
59
59
  it{ command_for('setup').options.server.should == 'bar.com' }
60
60
  it{ command_for('setup', '--server', 'foo.com').options.server.should == 'foo.com' }
@@ -95,7 +95,7 @@ describe RHC::Commands::Setup do
95
95
 
96
96
  context 'help is run' do
97
97
  it "should display help" do
98
- @wizard.stub!(:run).and_return(true)
98
+ @wizard.stub(:run).and_return(true)
99
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") }
@@ -51,7 +51,7 @@ describe RHC::Commands::Snapshot do
51
51
  RHC::Helpers.stub(:windows?) do ; true; end
52
52
  RHC::Helpers.stub(:jruby?) do ; false ; end
53
53
  RHC::Helpers.stub(:linux?) do ; false ; end
54
- ssh = mock(Net::SSH)
54
+ ssh = double(Net::SSH)
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
@@ -64,7 +64,7 @@ describe RHC::Commands::Snapshot do
64
64
  RHC::Helpers.stub(:windows?) do ; true; end
65
65
  RHC::Helpers.stub(:jruby?) do ; false ; end
66
66
  RHC::Helpers.stub(:linux?) do ; false ; end
67
- ssh = mock(Net::SSH)
67
+ ssh = double(Net::SSH)
68
68
  Net::SSH.should_receive(:start).with(@ssh_uri.host, @ssh_uri.user).and_raise(Timeout::Error)
69
69
  end
70
70
  it { expect { run }.to exit_with_code(130) }
@@ -77,8 +77,8 @@ describe RHC::Commands::Snapshot do
77
77
 
78
78
  context 'when restoring a snapshot' do
79
79
  before(:each) do
80
- File.stub!(:exists?).and_return(true)
81
- RHC::TarGz.stub!(:contains).and_return(true)
80
+ File.stub(:exists?).and_return(true)
81
+ RHC::TarGz.stub(:contains).and_return(true)
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
@@ -87,8 +87,8 @@ describe RHC::Commands::Snapshot do
87
87
 
88
88
  context 'when restoring a snapshot and failing to ssh' do
89
89
  before(:each) do
90
- File.stub!(:exists?).and_return(true)
91
- RHC::TarGz.stub!(:contains).and_return(true)
90
+ File.stub(:exists?).and_return(true)
91
+ RHC::TarGz.stub(:contains).and_return(true)
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
@@ -100,9 +100,9 @@ describe RHC::Commands::Snapshot do
100
100
  RHC::Helpers.stub(:windows?) do ; true; end
101
101
  RHC::Helpers.stub(:jruby?) do ; false ; end
102
102
  RHC::Helpers.stub(:linux?) do ; false ; end
103
- ssh = mock(Net::SSH)
104
- session = mock(Net::SSH::Connection::Session)
105
- channel = mock(Net::SSH::Connection::Channel)
103
+ ssh = double(Net::SSH)
104
+ session = double(Net::SSH::Connection::Session)
105
+ channel = double(Net::SSH::Connection::Channel)
106
106
  Net::SSH.should_receive(:start).with(@ssh_uri.host, @ssh_uri.user).and_return(session)
107
107
  session.should_receive(:open_channel).and_yield(channel)
108
108
  channel.should_receive(:exec).with("restore INCLUDE_GIT").and_yield(nil, nil)
@@ -127,7 +127,7 @@ describe RHC::Commands::Snapshot do
127
127
  RHC::Helpers.stub(:windows?) do ; true; end
128
128
  RHC::Helpers.stub(:jruby?) do ; false ; end
129
129
  RHC::Helpers.stub(:linux?) do ; false ; end
130
- ssh = mock(Net::SSH)
130
+ ssh = double(Net::SSH)
131
131
  Net::SSH.should_receive(:start).with(@ssh_uri.host, @ssh_uri.user).and_raise(Timeout::Error)
132
132
  end
133
133
  it { expect { run }.to exit_with_code(130) }