cf 1.1.3.rc1 → 1.1.4

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 (59) hide show
  1. data/lib/cf/cli.rb +2 -7
  2. data/lib/cf/cli/organization/delete.rb +4 -6
  3. data/lib/cf/cli/service/create.rb +23 -17
  4. data/lib/cf/cli/space/create.rb +43 -41
  5. data/lib/cf/cli/space/space.rb +49 -46
  6. data/lib/cf/version.rb +1 -1
  7. data/lib/console/console.rb +1 -1
  8. data/spec/cf/cli/app/delete_spec.rb +16 -28
  9. data/spec/cf/cli/app/instances_spec.rb +4 -5
  10. data/spec/cf/cli/app/push/create_spec.rb +362 -373
  11. data/spec/cf/cli/app/push_spec.rb +216 -215
  12. data/spec/cf/cli/app/rename_spec.rb +28 -31
  13. data/spec/cf/cli/app/scale_spec.rb +44 -41
  14. data/spec/cf/cli/app/start_spec.rb +194 -193
  15. data/spec/cf/cli/app/stats_spec.rb +55 -56
  16. data/spec/cf/cli/domain/map_spec.rb +105 -102
  17. data/spec/cf/cli/domain/unmap_spec.rb +60 -56
  18. data/spec/cf/cli/organization/delete_spec.rb +85 -84
  19. data/spec/cf/cli/organization/orgs_spec.rb +80 -83
  20. data/spec/cf/cli/organization/rename_spec.rb +90 -89
  21. data/spec/cf/cli/populators/organization_spec.rb +117 -119
  22. data/spec/cf/cli/populators/space_spec.rb +107 -108
  23. data/spec/cf/cli/populators/target_spec.rb +17 -12
  24. data/spec/cf/cli/route/delete_spec.rb +4 -4
  25. data/spec/cf/cli/route/map_spec.rb +106 -102
  26. data/spec/cf/cli/route/unmap_spec.rb +5 -5
  27. data/spec/cf/cli/service/create_spec.rb +74 -46
  28. data/spec/cf/cli/service/rename_spec.rb +29 -33
  29. data/spec/cf/cli/service/services_spec.rb +48 -48
  30. data/spec/cf/cli/space/base_spec.rb +39 -32
  31. data/spec/cf/cli/space/create_spec.rb +52 -53
  32. data/spec/cf/cli/space/delete_spec.rb +84 -85
  33. data/spec/cf/cli/space/rename_spec.rb +93 -94
  34. data/spec/cf/cli/space/space_spec.rb +60 -60
  35. data/spec/cf/cli/space/spaces_spec.rb +75 -80
  36. data/spec/cf/cli/space/switch_space_spec.rb +45 -48
  37. data/spec/cf/cli/start/info_spec.rb +4 -6
  38. data/spec/cf/cli/start/login_spec.rb +18 -20
  39. data/spec/cf/cli/start/logout_spec.rb +36 -37
  40. data/spec/cf/cli/start/target_spec.rb +86 -89
  41. data/spec/cf/cli/user/create_spec.rb +83 -84
  42. data/spec/cf/cli/user/passwd_spec.rb +87 -86
  43. data/spec/cf/cli/user/register_spec.rb +109 -108
  44. data/spec/cf/cli_spec.rb +305 -310
  45. data/spec/console/console_spec.rb +58 -58
  46. data/spec/factories/cfoundry/v2/domain_factory.rb +8 -0
  47. data/spec/factories/cfoundry/v2/route_factory.rb +8 -0
  48. data/spec/factories/cfoundry/v2/user_factory.rb +7 -0
  49. data/spec/features/org_spec.rb +11 -11
  50. data/spec/manifests/manifests_spec.rb +21 -21
  51. data/spec/manifests/plugin_spec.rb +34 -34
  52. data/spec/spec_helper.rb +1 -2
  53. data/spec/support/cli_helper.rb +5 -14
  54. data/spec/support/factory_girl.rb +6 -0
  55. data/spec/support/interact_helper.rb +5 -15
  56. data/spec/support/shared_examples/errors.rb +1 -1
  57. data/spec/tunnel/plugin_spec.rb +2 -2
  58. data/spec/tunnel/tunnel_spec.rb +5 -5
  59. metadata +36 -28
@@ -1,143 +1,144 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
- describe CF::User::Register do
4
- before do
5
- stub_client_and_precondition
6
- end
3
+ module CF
4
+ module User
5
+ describe Register do
6
+ let(:client) { fake_client }
7
7
 
8
- describe 'metadata' do
9
- let(:command) { Mothership.commands[:register] }
8
+ before do
9
+ stub_client_and_precondition
10
+ end
10
11
 
11
- describe 'command' do
12
- subject { command }
13
- its(:description) { should eq "Create a user and log in" }
14
- it { expect(Mothership::Help.group(:admin, :user)).to include(subject) }
15
- end
12
+ describe "metadata" do
13
+ let(:command) { Mothership.commands[:register] }
14
+
15
+ describe "command" do
16
+ subject { command }
17
+ its(:description) { should eq "Create a user and log in" }
18
+ it { expect(Mothership::Help.group(:admin, :user)).to include(subject) }
19
+ end
16
20
 
17
- include_examples 'inputs must have descriptions'
21
+ include_examples "inputs must have descriptions"
18
22
 
19
- describe 'arguments' do
20
- subject { command.arguments }
21
- it 'have the correct commands' do
22
- should eq [
23
- {:type => :optional, :value => nil, :name => :email}
24
- ]
23
+ describe "arguments" do
24
+ subject { command.arguments }
25
+ it "have the correct commands" do
26
+ should eq [
27
+ {:type => :optional, :value => nil, :name => :email}
28
+ ]
29
+ end
30
+ end
25
31
  end
26
- end
27
- end
28
32
 
29
- describe '#register' do
30
- let(:client) { fake_client }
31
- let(:email) { 'a@b.com' }
32
- let(:password) { 'password' }
33
- let(:verify_password) { password }
34
- let(:force) { false }
35
- let(:login) { false }
36
- let(:score) { :strong }
37
-
38
- before do
39
- stub(client).register
40
- stub(client).base.stub!.password_score(password) { score }
41
- end
33
+ describe "#register" do
34
+ let(:email) { "a@b.com" }
35
+ let(:password) { "password" }
36
+ let(:verify_password) { password }
37
+ let(:force) { false }
38
+ let(:login) { false }
39
+ let(:score) { :strong }
40
+
41
+ before do
42
+ client.stub(:register)
43
+ client.base.stub(:password_score) { score }
44
+ end
42
45
 
43
- subject { cf %W[register --email #{email} --password #{password} --verify #{verify_password} --#{bool_flag(:login)} --#{bool_flag(:force)}] }
46
+ subject { cf %W[register --email #{email} --password #{password} --verify #{verify_password} --#{bool_flag(:login)} --#{bool_flag(:force)}] }
44
47
 
45
- context 'when the passwords dont match' do
46
- let(:verify_password) { "other_password" }
48
+ context "when the passwords dont match" do
49
+ let(:verify_password) { "other_password" }
47
50
 
48
- it { should eq 1 }
51
+ it { should eq 1 }
49
52
 
50
- it 'fails' do
51
- subject
52
- expect(error_output).to say("Passwords do not match.")
53
- end
53
+ it "fails" do
54
+ subject
55
+ expect(error_output).to say("Passwords do not match.")
56
+ end
54
57
 
55
- it "doesn't print out the score" do
56
- subject
57
- expect(output).to_not say("strength")
58
- end
58
+ it "doesn't print out the score" do
59
+ subject
60
+ expect(output).to_not say("strength")
61
+ end
59
62
 
60
- it "doesn't log in or register" do
61
- dont_allow(client).register
62
- dont_allow_invoke
63
- subject
64
- end
63
+ it "doesn't log in or register" do
64
+ client.should_not_receive(:register)
65
+ dont_allow_invoke
66
+ subject
67
+ end
65
68
 
66
- context 'and the force flag is passed' do
67
- let(:force) { true }
69
+ context "and the force flag is passed" do
70
+ let(:force) { true }
68
71
 
69
- it "doesn't verify the password" do
70
- mock(client).register(email, password)
71
- subject
72
- expect(error_output).to_not say("Passwords do not match.")
72
+ it "doesn't verify the password" do
73
+ client.should_receive(:register).with(email, password)
74
+ subject
75
+ expect(error_output).to_not say("Passwords do not match.")
76
+ end
77
+ end
73
78
  end
74
- end
75
- end
76
79
 
77
- context 'when the password is good or strong' do
78
- it { should eq 0 }
80
+ context "when the password is good or strong" do
81
+ it { should eq 0 }
79
82
 
80
- it 'prints out the password score' do
81
- subject
82
- expect(stdout.string).to include "Your password strength is: strong"
83
- end
83
+ it "prints out the password score" do
84
+ subject
85
+ expect(stdout.string).to include "Your password strength is: strong"
86
+ end
84
87
 
85
- it 'registers the user' do
86
- mock(client).register(email, password)
87
- subject
88
- end
88
+ it "registers the user" do
89
+ client.should_receive(:register).with(email, password)
90
+ subject
91
+ end
89
92
 
90
- context 'and the login flag is true' do
91
- let(:login) { true }
93
+ context "and the login flag is true" do
94
+ let(:login) { true }
92
95
 
93
- it 'logs in' do
94
- any_instance_of(described_class) do |register|
95
- mock(register).invoke(:login, :username => email, :password => password)
96
+ it "logs in" do
97
+ described_class.any_instance.should_receive(:invoke).with(:login, :username => email, :password => password)
98
+ subject
99
+ end
96
100
  end
97
- subject
98
- end
99
- end
100
101
 
101
- context 'and the login flag is false' do
102
- it "doesn't log in" do
103
- any_instance_of(described_class) do |register|
104
- dont_allow(register).invoke(:login, :username => email, :password => password)
102
+ context "and the login flag is false" do
103
+ it "doesn't log in" do
104
+ described_class.any_instance.should_not_receive(:invoke)
105
+ subject
106
+ end
105
107
  end
106
- subject
107
108
  end
108
- end
109
- end
110
109
 
111
- context 'when the password is weak' do
112
- let(:score) { :weak }
113
- let(:login) { true }
110
+ context "when the password is weak" do
111
+ let(:score) { :weak }
112
+ let(:login) { true }
114
113
 
115
- it { should eq 1 }
114
+ it { should eq 1 }
116
115
 
117
- it 'prints out the password score' do
118
- subject
119
- expect(error_output).to say("Your password strength is: weak")
120
- end
116
+ it "prints out the password score" do
117
+ subject
118
+ expect(error_output).to say("Your password strength is: weak")
119
+ end
121
120
 
122
- it "doesn't register" do
123
- dont_allow(client).register(email, password)
124
- subject
125
- end
121
+ it "doesn't register" do
122
+ client.should_not_receive(:register).with(email, password)
123
+ subject
124
+ end
126
125
 
127
- it "doesn't log in" do
128
- dont_allow_invoke :login
129
- subject
130
- end
131
- end
126
+ it "doesn't log in" do
127
+ dont_allow_invoke :login
128
+ subject
129
+ end
130
+ end
132
131
 
133
- context 'when arguments are not passed in the command line' do
134
- subject { cf %W[register --no-force --no-login] }
132
+ context "when arguments are not passed in the command line" do
133
+ subject { cf %W[register --no-force --no-login] }
135
134
 
136
- it 'asks for the email, password and confirm password' do
137
- mock_ask("Email") { email }
138
- mock_ask("Password", anything) { password }
139
- mock_ask("Confirm Password", anything) { verify_password }
140
- subject
135
+ it "asks for the email, password and confirm password" do
136
+ mock_ask("Email") { email }
137
+ mock_ask("Password", anything) { password }
138
+ mock_ask("Confirm Password", anything) { verify_password }
139
+ subject
140
+ end
141
+ end
141
142
  end
142
143
  end
143
144
  end
@@ -1,446 +1,441 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
- describe CF::CLI do
4
- let(:context) { CF::CLI.new }
5
- let(:command) { nil }
3
+ module CF
4
+ describe CLI do
5
+ let(:context) { CF::CLI.new }
6
+ let(:command) { nil }
6
7
 
7
- let(:fake_home_dir) { nil }
8
- stub_home_dir_with { fake_home_dir }
8
+ let(:fake_home_dir) { nil }
9
+ stub_home_dir_with { fake_home_dir }
9
10
 
10
- describe "#wrap_errors" do
11
- let(:inputs) { {} }
11
+ describe "#wrap_errors" do
12
+ let(:inputs) { {} }
12
13
 
13
- subject do
14
- capture_output do
15
- stub(context).input { inputs }
16
- context.wrap_errors { action.call }
14
+ subject do
15
+ capture_output do
16
+ context.stub(:input) { inputs }
17
+ context.wrap_errors { action.call }
18
+ end
17
19
  end
18
- end
19
20
 
20
- context "with a CFoundry::Timeout" do
21
- let(:action) { proc { raise CFoundry::Timeout.new(123, "fizzbuzz") } }
21
+ context "with a CFoundry::Timeout" do
22
+ let(:action) { proc { raise CFoundry::Timeout.new(123, "fizzbuzz") } }
22
23
 
23
- it_behaves_like "an error that's obvious to the user",
24
- :with_message => "fizzbuzz"
25
- end
24
+ it_behaves_like "an error that's obvious to the user", :with_message => "fizzbuzz"
25
+ end
26
26
 
27
- context "with a UserError" do
28
- let(:action) { proc { context.fail "foo bar" } }
27
+ context "with a UserError" do
28
+ let(:action) { proc { context.fail "foo bar" } }
29
29
 
30
- it_behaves_like "an error that's obvious to the user",
31
- :with_message => "foo bar"
30
+ it_behaves_like "an error that's obvious to the user",
31
+ :with_message => "foo bar"
32
32
 
33
- it "saves it in the crashlog" do
34
- mock(context).log_error(anything)
35
- subject
33
+ it "saves it in the crashlog" do
34
+ context.should_receive(:log_error)
35
+ subject
36
+ end
36
37
  end
37
- end
38
-
39
- context "with a UserFriendlyError" do
40
- let(:action) { proc { raise CF::UserFriendlyError.new("user friendly") } }
41
-
42
- it_behaves_like "an error that's obvious to the user",
43
- :with_message => "user friendly"
44
- end
45
38
 
46
- context "with a SystemExit" do
47
- let(:action) { proc { exit 1 } }
39
+ context "with a UserFriendlyError" do
40
+ let(:action) { proc { raise CF::UserFriendlyError.new("user friendly") } }
48
41
 
49
- it_behaves_like "an error that gets passed through",
50
- :with_exception => SystemExit
51
- end
42
+ it_behaves_like "an error that's obvious to the user",
43
+ :with_message => "user friendly"
44
+ end
52
45
 
53
- context "with a Mothership::Error" do
54
- let(:action) { proc { raise Mothership::Error } }
46
+ context "with a SystemExit" do
47
+ let(:action) { proc { exit 1 } }
55
48
 
56
- it_behaves_like "an error that gets passed through",
57
- :with_exception => Mothership::Error
58
- end
49
+ it_behaves_like "an error that gets passed through",
50
+ :with_exception => SystemExit
51
+ end
59
52
 
60
- context "with an Interrupt" do
61
- let(:action) { proc { raise Interrupt } }
53
+ context "with a Mothership::Error" do
54
+ let(:action) { proc { raise Mothership::Error } }
62
55
 
63
- it "sets the exit code to 130" do
64
- mock(context).exit_status(130)
65
- subject
56
+ it_behaves_like "an error that gets passed through",
57
+ :with_exception => Mothership::Error
66
58
  end
67
- end
68
59
 
69
- context "when CC can't decode the auth token" do
70
- let(:action) { proc { raise CFoundry::InvalidAuthToken.new("foo bar") } }
71
- let(:asked) { false }
60
+ context "with an Interrupt" do
61
+ let(:action) { proc { raise Interrupt } }
72
62
 
73
- before do
74
- $cf_asked_auth = asked
63
+ it "sets the exit code to 130" do
64
+ context.should_receive(:exit_status).with(130)
65
+ subject
66
+ end
75
67
  end
76
68
 
77
- it "tells the user they are not authenticated" do
78
- subject
79
- expect(stdout.string).to include "Invalid authentication token. Try logging in again with 'cf login'. If problems continue, please contact your Cloud Operator."
80
- end
69
+ context "when CC can't decode the auth token" do
70
+ let(:action) { proc { raise CFoundry::InvalidAuthToken.new("foo bar") } }
71
+ let(:asked) { false }
81
72
 
82
- it "exits without attempting to login again" do
83
- dont_allow(context).invoke(:login)
84
- subject
85
- end
86
- end
73
+ before do
74
+ $cf_asked_auth = asked
75
+ end
87
76
 
88
- context "with a CFoundry authentication error" do
89
- let(:action) { proc { raise CFoundry::Forbidden.new("foo bar") } }
90
- let(:asked) { false }
77
+ it "tells the user they are not authenticated" do
78
+ subject
79
+ expect(stdout.string).to include "Invalid authentication token. Try logging in again with 'cf login'. If problems continue, please contact your Cloud Operator."
80
+ end
91
81
 
92
- before do
93
- $cf_asked_auth = asked
82
+ it "exits without attempting to login again" do
83
+ context.should_not_receive(:invoke)
84
+ subject
85
+ end
94
86
  end
95
87
 
96
- it "tells the user they are not authenticated" do
97
- stub(context).invoke(:login)
98
- subject
99
- expect(stdout.string).to include "Not authenticated! Try logging in:"
100
- expect($cf_asked_auth).to be_true
101
- end
88
+ context "with a CFoundry authentication error" do
89
+ let(:action) { proc { raise CFoundry::Forbidden.new("foo bar") } }
90
+ let(:asked) { false }
102
91
 
103
- it "asks the user to log in" do
104
- mock(context).invoke(:login)
105
- subject
106
- end
92
+ before do
93
+ $cf_asked_auth = asked
94
+ end
107
95
 
108
- context "and after logging in they got another authentication error" do
109
- let(:asked) { true }
96
+ it "tells the user they are not authenticated" do
97
+ context.stub(:invoke)
98
+ subject
99
+ expect(stdout.string).to include "Not authenticated! Try logging in:"
100
+ expect($cf_asked_auth).to be_true
101
+ end
110
102
 
111
- it "does not ask them to log in" do
112
- dont_allow(context).invoke(:login)
103
+ it "asks the user to log in" do
104
+ context.should_receive(:invoke).with(:login)
113
105
  subject
114
106
  end
115
107
 
116
- it_behaves_like "an error that's obvious to the user",
117
- :with_message => "Denied: foo bar"
118
- end
119
- end
108
+ context "and after logging in they got another authentication error" do
109
+ let(:asked) { true }
120
110
 
121
- context "with an arbitrary exception" do
122
- let(:action) { proc { raise "foo bar" } }
111
+ it "does not ask them to log in" do
112
+ context.should_not_receive(:invoke)
113
+ subject
114
+ end
123
115
 
124
- it "logs the error" do
125
- mock(context).log_error(anything)
126
- subject
116
+ it_behaves_like "an error that's obvious to the user",
117
+ :with_message => "Denied: foo bar"
118
+ end
127
119
  end
128
120
 
129
- it "prints the message" do
130
- subject
131
- expect(stderr.string).to include "RuntimeError: foo bar"
132
- end
121
+ context "with an arbitrary exception" do
122
+ let(:action) { proc { raise "foo bar" } }
133
123
 
134
- it "sets the exit code to 1" do
135
- mock(context).exit_status(1)
136
- subject
137
- end
124
+ it "logs the error" do
125
+ context.should_receive(:log_error).with(anything)
126
+ subject
127
+ end
138
128
 
139
- it "tells the user to check ~/.cf/crash" do
140
- subject
141
- expect(stderr.string).to include CF::CRASH_FILE
142
- end
129
+ it "prints the message" do
130
+ subject
131
+ expect(stderr.string).to include "RuntimeError: foo bar"
132
+ end
143
133
 
144
- context "when we are debugging" do
145
- let(:inputs) { {:debug => true} }
134
+ it "sets the exit code to 1" do
135
+ context.should_receive(:exit_status).with(1)
136
+ subject
137
+ end
146
138
 
147
- it_behaves_like "an error that gets passed through",
148
- :with_exception => RuntimeError
149
- end
150
- end
151
- end
139
+ it "tells the user to check ~/.cf/crash" do
140
+ subject
141
+ expect(stderr.string).to include CF::CRASH_FILE
142
+ end
152
143
 
153
- describe '#execute' do
154
- let(:inputs) { {} }
155
- let(:client) { fake_client }
144
+ context "when we are debugging" do
145
+ let(:inputs) { {:debug => true} }
156
146
 
157
- before do
158
- any_instance_of(CF::CLI) do |cli|
159
- stub(cli).client { client }
147
+ it_behaves_like "an error that gets passed through",
148
+ :with_exception => RuntimeError
149
+ end
160
150
  end
161
151
  end
162
152
 
163
- subject do
164
- capture_output do
165
- stub(context).input { inputs }
166
- context.execute(command, [])
167
- end
168
- end
153
+ describe "#execute" do
154
+ let(:inputs) { {} }
155
+ let(:client) { fake_client }
169
156
 
170
- describe "token refreshing" do
171
- let(:context) { TokenRefreshDummy.new }
172
- let(:command) { Mothership.commands[:refresh_token] }
173
- let(:auth_token) { CFoundry::AuthToken.new("old-header") }
174
- let(:new_auth_token) { CFoundry::AuthToken.new("new-header") }
157
+ before do
158
+ stub_client
159
+ end
175
160
 
176
- class TokenRefreshDummy < CF::CLI
177
- class << self
178
- attr_accessor :new_token
161
+ subject do
162
+ capture_output do
163
+ context.stub(:input) { inputs }
164
+ context.execute(command, [])
179
165
  end
166
+ end
180
167
 
181
- def precondition;
182
- end
168
+ describe "token refreshing" do
169
+ let(:context) { TokenRefreshDummy.new }
170
+ let(:command) { Mothership.commands[:refresh_token] }
171
+ let(:auth_token) { CFoundry::AuthToken.new("old-header") }
172
+ let(:new_auth_token) { CFoundry::AuthToken.new("new-header") }
183
173
 
184
- desc "XXX"
185
- def refresh_token
186
- if client
187
- client.token = self.class.new_token
174
+ class TokenRefreshDummy < CF::CLI
175
+ class << self
176
+ attr_accessor :new_token
188
177
  end
189
- end
190
- end
191
178
 
192
- context "when there is a target" do
193
- before do
194
- TokenRefreshDummy.new_token = nil
195
- client.token = auth_token
179
+ def precondition;
180
+ end
181
+
182
+ desc "XXX"
183
+
184
+ def refresh_token
185
+ if client
186
+ client.token = self.class.new_token
187
+ end
188
+ end
196
189
  end
197
190
 
198
- context "when the token refreshes" do
199
- it "saves to the target file" do
200
- any_instance_of(TokenRefreshDummy) do |trd|
201
- trd.new_token = new_auth_token
191
+ context "when there is a target" do
192
+ before do
193
+ TokenRefreshDummy.new_token = nil
194
+ client.token = auth_token
195
+ end
202
196
 
203
- stub(trd).target_info { {} }
204
- mock(trd).save_target_info(anything) do |info|
197
+ context "when the token refreshes" do
198
+ it "saves to the target file" do
199
+ TokenRefreshDummy.any_instance.stub(:target_info) { {} }
200
+ TokenRefreshDummy.any_instance.stub(:save_target_info).with(anything) do |info|
205
201
  expect(info[:token]).to eq new_auth_token.auth_header
206
202
  end
207
- end
208
203
 
209
- subject
204
+ subject
205
+ end
210
206
  end
211
- end
212
207
 
213
- context "but there is no token initially" do
214
- let(:auth_token) { nil }
208
+ context "but there is no token initially" do
209
+ let(:auth_token) { nil }
215
210
 
216
- it "doesn't save the new token because something else probably did" do
217
- dont_allow(context).save_target_info(anything)
218
- subject
211
+ it "doesn't save the new token because something else probably did" do
212
+ context.should_not_receive(:save_target_info)
213
+ subject
214
+ end
219
215
  end
220
- end
221
216
 
222
- context "and the token becomes nil" do
223
- let(:new_auth_token) { nil }
217
+ context "and the token becomes nil" do
218
+ let(:new_auth_token) { nil }
224
219
 
225
- it "doesn't save the nil token" do
226
- dont_allow(context).save_target_info(anything)
227
- subject
220
+ it "doesn't save the nil token" do
221
+ context.should_not_receive(:save_target_info)
222
+ subject
223
+ end
228
224
  end
229
225
  end
230
- end
231
226
 
232
- context "when there is no target" do
233
- let(:client) { nil }
227
+ context "when there is no target" do
228
+ let(:client) { nil }
234
229
 
235
- it "doesn't try to compare the tokens" do
236
- expect { subject }.to_not raise_error
230
+ it "doesn't try to compare the tokens" do
231
+ expect { subject }.to_not raise_error
232
+ end
237
233
  end
238
234
  end
239
235
  end
240
- end
241
-
242
- describe '#log_error' do
243
- subject do
244
- context.log_error(exception)
245
- File.read(File.expand_path(CF::CRASH_FILE))
246
- end
247
236
 
248
- context 'when the exception is a normal error' do
249
- let(:exception) do
250
- error = StandardError.new("gemfiles are kinda hard")
251
- error.set_backtrace(["fo/gems/bar", "baz quick"])
252
- error
237
+ describe "#log_error" do
238
+ subject do
239
+ context.log_error(exception)
240
+ File.read(File.expand_path(CF::CRASH_FILE))
253
241
  end
254
242
 
255
- it { should include "Time of crash:" }
256
- it { should include "gemfiles are kinda hard" }
257
- it { should include "bar" }
258
- it { should_not include "fo/gems/bar" }
259
- it { should include "baz quick" }
260
- end
243
+ context "when the exception is a normal error" do
244
+ let(:exception) do
245
+ error = StandardError.new("gemfiles are kinda hard")
246
+ error.set_backtrace(["fo/gems/bar", "baz quick"])
247
+ error
248
+ end
261
249
 
262
- context 'when the exception is an APIError' do
263
- let(:request) { {:method => "GET", :url => "http://api.cloudfoundry.com/foo", :headers => {}, :body => nil} }
264
- let(:response) { {:status => 404, :body => "bar", :headers => {}} }
265
- let(:exception) do
266
- error = CFoundry::APIError.new(nil, nil, request, response)
267
- error.set_backtrace(["fo/gems/bar", "baz quick"])
268
- error
250
+ it { should include "Time of crash:" }
251
+ it { should include "gemfiles are kinda hard" }
252
+ it { should include "bar" }
253
+ it { should_not include "fo/gems/bar" }
254
+ it { should include "baz quick" }
269
255
  end
270
256
 
271
- before do
272
- stub(response).body { "Response Body" }
273
- end
257
+ context "when the exception is an APIError" do
258
+ let(:request) { {:method => "GET", :url => "http://api.cloudfoundry.com/foo", :headers => {}, :body => nil} }
259
+ let(:response) { {:status => 404, :body => "bar", :headers => {}} }
260
+ let(:exception) do
261
+ error = CFoundry::APIError.new(nil, nil, request, response)
262
+ error.set_backtrace(["fo/gems/bar", "baz quick"])
263
+ error
264
+ end
265
+
266
+ before do
267
+ response.stub(:body) { "Response Body" }
268
+ end
274
269
 
275
- it { should include "REQUEST: " }
276
- it { should include "RESPONSE: " }
270
+ it { should include "REQUEST: " }
271
+ it { should include "RESPONSE: " }
272
+ end
277
273
  end
278
- end
279
274
 
280
- describe "#client_target" do
281
- subject { context.client_target }
275
+ describe "#client_target" do
276
+ subject { context.client_target }
282
277
 
283
- context "when a ~/.cf/target exists" do
284
- let(:fake_home_dir) { "#{SPEC_ROOT}/fixtures/fake_home_dirs/new" }
278
+ context "when a ~/.cf/target exists" do
279
+ let(:fake_home_dir) { "#{SPEC_ROOT}/fixtures/fake_home_dirs/new" }
285
280
 
286
- it "returns the target in that file" do
287
- expect(subject).to eq "https://api.some-domain.com"
281
+ it "returns the target in that file" do
282
+ expect(subject).to eq "https://api.some-domain.com"
283
+ end
288
284
  end
289
- end
290
285
 
291
- context "when no target file exists" do
292
- let(:fake_home_dir) { "#{SPEC_ROOT}/fixtures/fake_home_dirs/no_config" }
286
+ context "when no target file exists" do
287
+ let(:fake_home_dir) { "#{SPEC_ROOT}/fixtures/fake_home_dirs/no_config" }
293
288
 
294
- it "returns nil" do
295
- expect(subject).to eq nil
289
+ it "returns nil" do
290
+ expect(subject).to eq nil
291
+ end
296
292
  end
297
293
  end
298
- end
299
294
 
300
- describe "#targets_info" do
301
- subject { context.targets_info }
295
+ describe "#targets_info" do
296
+ subject { context.targets_info }
302
297
 
303
- context "when a ~/.cf/tokens.yml exists" do
304
- let(:fake_home_dir) { "#{SPEC_ROOT}/fixtures/fake_home_dirs/new" }
298
+ context "when a ~/.cf/tokens.yml exists" do
299
+ let(:fake_home_dir) { "#{SPEC_ROOT}/fixtures/fake_home_dirs/new" }
305
300
 
306
- it "returns the file's contents as a hash" do
307
- expect(subject).to eq({
308
- "https://api.some-domain.com" => {
309
- :token => "bearer some-token",
310
- :version => 2
311
- }
312
- })
301
+ it "returns the file's contents as a hash" do
302
+ expect(subject).to eq({
303
+ "https://api.some-domain.com" => {
304
+ :token => "bearer some-token",
305
+ :version => 2
306
+ }
307
+ })
308
+ end
313
309
  end
314
- end
315
310
 
316
- context "when no token file exists" do
317
- let(:fake_home_dir) { "#{SPEC_ROOT}/fixtures/fake_home_dirs/no_config" }
311
+ context "when no token file exists" do
312
+ let(:fake_home_dir) { "#{SPEC_ROOT}/fixtures/fake_home_dirs/no_config" }
318
313
 
319
- it "returns an empty hash" do
320
- expect(subject).to eq({})
314
+ it "returns an empty hash" do
315
+ expect(subject).to eq({})
316
+ end
321
317
  end
322
318
  end
323
- end
324
319
 
325
- describe "#target_info" do
326
- subject { CF::CLI.new.target_info("https://api.some-domain.com") }
320
+ describe "#target_info" do
321
+ subject { CF::CLI.new.target_info("https://api.some-domain.com") }
327
322
 
328
- context "when a ~/.cf/tokens.yml exists" do
329
- let(:fake_home_dir) { "#{SPEC_ROOT}/fixtures/fake_home_dirs/new" }
323
+ context "when a ~/.cf/tokens.yml exists" do
324
+ let(:fake_home_dir) { "#{SPEC_ROOT}/fixtures/fake_home_dirs/new" }
330
325
 
331
- it "returns the info for the given url" do
332
- expect(subject).to eq({
333
- :token => "bearer some-token",
334
- :version => 2
335
- })
326
+ it "returns the info for the given url" do
327
+ expect(subject).to eq({
328
+ :token => "bearer some-token",
329
+ :version => 2
330
+ })
331
+ end
336
332
  end
337
- end
338
333
 
339
- context "when no token file exists" do
340
- let(:fake_home_dir) { "#{SPEC_ROOT}/fixtures/fake_home_dirs/no_config" }
334
+ context "when no token file exists" do
335
+ let(:fake_home_dir) { "#{SPEC_ROOT}/fixtures/fake_home_dirs/no_config" }
341
336
 
342
- it "returns an empty hash" do
343
- expect(subject).to eq({})
337
+ it "returns an empty hash" do
338
+ expect(subject).to eq({})
339
+ end
344
340
  end
345
341
  end
346
- end
347
342
 
348
- describe "methods that update the token info" do
349
- before do
350
- stub(context).targets_info do
351
- {
352
- "https://api.some-domain.com" => {:token => "bearer token1"},
353
- "https://api.some-other-domain.com" => {:token => "bearer token2"}
354
- }
343
+ describe "methods that update the token info" do
344
+ before do
345
+ context.stub(:targets_info) do
346
+ {
347
+ "https://api.some-domain.com" => {:token => "bearer token1"},
348
+ "https://api.some-other-domain.com" => {:token => "bearer token2"}
349
+ }
350
+ end
355
351
  end
356
- end
357
352
 
358
- describe "#save_target_info" do
359
- it "adds the given target info, and writes the result to ~/.cf/tokens.yml" do
360
- context.save_target_info({:token => "bearer token3"}, "https://api.some-domain.com")
361
- YAML.load_file(File.expand_path("~/.cf/tokens.yml")).should == {
362
- "https://api.some-domain.com" => {:token => "bearer token3"},
363
- "https://api.some-other-domain.com" => {:token => "bearer token2"}
364
- }
353
+ describe "#save_target_info" do
354
+ it "adds the given target info, and writes the result to ~/.cf/tokens.yml" do
355
+ context.save_target_info({:token => "bearer token3"}, "https://api.some-domain.com")
356
+ YAML.load_file(File.expand_path("~/.cf/tokens.yml")).should == {
357
+ "https://api.some-domain.com" => {:token => "bearer token3"},
358
+ "https://api.some-other-domain.com" => {:token => "bearer token2"}
359
+ }
360
+ end
365
361
  end
366
- end
367
362
 
368
- describe "#remove_target_info" do
369
- it "removes the given target, and writes the result to ~/.cf/tokens.yml" do
370
- context.remove_target_info("https://api.some-domain.com")
371
- YAML.load_file(File.expand_path("~/.cf/tokens.yml")).should == {
372
- "https://api.some-other-domain.com" => {:token => "bearer token2"}
373
- }
363
+ describe "#remove_target_info" do
364
+ it "removes the given target, and writes the result to ~/.cf/tokens.yml" do
365
+ context.remove_target_info("https://api.some-domain.com")
366
+ YAML.load_file(File.expand_path("~/.cf/tokens.yml")).should == {
367
+ "https://api.some-other-domain.com" => {:token => "bearer token2"}
368
+ }
369
+ end
374
370
  end
375
371
  end
376
- end
377
372
 
378
- describe "#client" do
379
- let(:fake_home_dir) { "#{SPEC_ROOT}/fixtures/fake_home_dirs/new" }
373
+ describe "#client" do
374
+ let(:fake_home_dir) { "#{SPEC_ROOT}/fixtures/fake_home_dirs/new" }
380
375
 
381
- before { stub(context).input { {} } }
376
+ before { context.stub(:input).and_return({}) }
382
377
 
383
- describe "the client's token" do
384
- it "constructs an AuthToken object with the data from the tokens.yml file" do
385
- expect(context.client.token).to be_a(CFoundry::AuthToken)
386
- expect(context.client.token.auth_header).to eq("bearer some-token")
387
- end
378
+ describe "the client's token" do
379
+ it "constructs an AuthToken object with the data from the tokens.yml file" do
380
+ expect(context.client.token).to be_a(CFoundry::AuthToken)
381
+ expect(context.client.token.auth_header).to eq("bearer some-token")
382
+ end
388
383
 
389
- it "does not assign an AuthToken on the client if there is no token stored" do
390
- mock(context).target_info("some-fake-target") { {:version => 2} }
391
- expect(context.client("some-fake-target").token).to be_nil
384
+ it "does not assign an AuthToken on the client if there is no token stored" do
385
+ context.should_receive(:target_info).with("some-fake-target") { {:version => 2} }
386
+ expect(context.client("some-fake-target").token).to be_nil
387
+ end
392
388
  end
393
- end
394
389
 
395
- describe "the client's version" do
396
- it "uses the version stored in the yml file" do
397
- expect(context.client.version).to eq(2)
390
+ describe "the client's version" do
391
+ it "uses the version stored in the yml file" do
392
+ expect(context.client.version).to eq(2)
393
+ end
398
394
  end
399
- end
400
395
 
401
- context "when there is no target" do
402
- let(:fake_home_dir) { "#{SPEC_ROOT}/fixtures/fake_home_dirs/no_config" }
396
+ context "when there is no target" do
397
+ let(:fake_home_dir) { "#{SPEC_ROOT}/fixtures/fake_home_dirs/no_config" }
403
398
 
404
- it "returns nil" do
405
- expect(context.client).to eq(nil)
399
+ it "returns nil" do
400
+ expect(context.client).to eq(nil)
401
+ end
406
402
  end
407
- end
408
403
 
409
- context "with a cloud controller" do
410
- before do
411
- stub(context).target_info { {:version => 2} }
412
- end
404
+ context "with a cloud controller" do
405
+ before do
406
+ context.stub(:target_info) { {:version => 2} }
407
+ end
413
408
 
414
- it "connects using the v2 api" do
415
- expect(context.client).to be_a(CFoundry::V2::Client)
416
- end
409
+ it "connects using the v2 api" do
410
+ expect(context.client).to be_a(CFoundry::V2::Client)
411
+ end
417
412
 
418
- %w{https_proxy HTTPS_PROXY http_proxy HTTP_PROXY}.each do |variable|
419
- proxy_name = variable.downcase.to_sym
413
+ %w{https_proxy HTTPS_PROXY http_proxy HTTP_PROXY}.each do |variable|
414
+ proxy_name = variable.downcase.to_sym
420
415
 
421
- context "when ENV['#{variable}'] is set" do
422
- before { ENV[variable] = "http://lower.example.com:80" }
423
- after { ENV.delete(variable) }
416
+ context "when ENV['#{variable}'] is set" do
417
+ before { ENV[variable] = "http://lower.example.com:80" }
418
+ after { ENV.delete(variable) }
424
419
 
425
- it "uses the #{proxy_name} proxy URI on the environment variable" do
426
- expect(context.client.send(proxy_name)).to eq('http://lower.example.com:80')
420
+ it "uses the #{proxy_name} proxy URI on the environment variable" do
421
+ expect(context.client.send(proxy_name)).to eq("http://lower.example.com:80")
422
+ end
427
423
  end
428
424
  end
429
- end
430
425
 
431
- context 'when both input and environment variable are provided' do
432
- before do
433
- ENV['HTTPS_PROXY'] = "http://should.be.overwritten.example.com:80"
434
- stub(context).input { {:https_proxy => 'http://arg.example.com:80'} }
435
- end
426
+ context "when both input and environment variable are provided" do
427
+ before do
428
+ ENV["HTTPS_PROXY"] = "http://should.be.overwritten.example.com:80"
429
+ context.stub(:input) { {:https_proxy => "http://arg.example.com:80"} }
430
+ end
436
431
 
437
- after { ENV.delete('HTTPS_PROXY') }
432
+ after { ENV.delete("HTTPS_PROXY") }
438
433
 
439
- it "uses the provided https proxy URI" do
440
- expect(context.client.https_proxy).to eq('http://arg.example.com:80')
434
+ it "uses the provided https proxy URI" do
435
+ expect(context.client.https_proxy).to eq("http://arg.example.com:80")
436
+ end
441
437
  end
442
438
  end
443
439
  end
444
440
  end
445
441
  end
446
-