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,499 +1,488 @@
1
- require 'spec_helper'
2
- require 'fakefs/safe'
1
+ require "spec_helper"
3
2
 
4
- describe CF::App::Create do
5
- let(:inputs) { {} }
6
- let(:given) { {} }
7
- let(:global) { { :color => false, :quiet => true } }
3
+ module CF
4
+ module App
5
+ describe Create do
6
+ let(:inputs) { {} }
7
+ let(:given) { {} }
8
+ let(:global) { {:color => false, :quiet => true} }
8
9
 
9
- let(:service_instances) { fake_list(:service_instance, 5) }
10
- let(:lucid64) { fake :stack, :name => "lucid64" }
10
+ let(:service_instances) { fake_list(:service_instance, 5) }
11
+ let(:lucid64) { fake :stack, :name => "lucid64" }
11
12
 
12
- let(:client) do
13
- fake_client(:service_instances => service_instances, :stacks => [lucid64])
14
- end
15
-
16
- before do
17
- any_instance_of(CF::CLI) do |cli|
18
- stub(cli).client { client }
19
- end
20
- end
21
-
22
- let(:path) { "some-path" }
23
-
24
- subject(:create) do
25
- command = Mothership.commands[:push]
26
- create = CF::App::Push.new(command)
27
- create.path = path
28
- create.input = Mothership::Inputs.new(command, create, inputs, given, global)
29
- create.extend CF::App::PushInteractions
30
- create
31
- end
13
+ let(:client) do
14
+ fake_client(:service_instances => service_instances, :stacks => [lucid64])
15
+ end
32
16
 
33
- describe '#get_inputs' do
34
- subject { create.get_inputs }
35
-
36
- let(:given) do
37
- { :name => "some-name",
38
- :instances => "1",
39
- :plan => "100",
40
- :memory => "1G",
41
- :command => "ruby main.rb",
42
- :buildpack => "git://example.com",
43
- :stack => "lucid64"
44
- }
45
- end
17
+ before do
18
+ CF::CLI.any_instance.stub(:client).and_return(client)
19
+ end
46
20
 
47
- context 'when all the inputs are given' do
48
- its([:name]) { should eq "some-name" }
49
- its([:total_instances]) { should eq 1 }
50
- its([:space]) { should eq client.current_space }
51
- its([:command]) { should eq "ruby main.rb" }
52
- its([:memory]) { should eq 1024 }
53
- its([:stack]) { should eq lucid64 }
54
- end
21
+ let(:path) { "some-path" }
55
22
 
56
- context 'when the command is given' do
57
- context "and there is a Procfile in the application's root" do
58
- before do
59
- FakeFS.activate!
60
- Dir.mkdir(path)
23
+ subject(:create) do
24
+ command = Mothership.commands[:push]
25
+ create = CF::App::Push.new(command)
26
+ create.path = path
27
+ create.input = Mothership::Inputs.new(command, create, inputs, given, global)
28
+ create.extend CF::App::PushInteractions
29
+ create
30
+ end
61
31
 
62
- File.open("#{path}/Procfile", "w") do |file|
63
- file.write("this is a procfile")
64
- end
32
+ describe "#get_inputs" do
33
+ subject { create.get_inputs }
34
+
35
+ let(:given) do
36
+ {:name => "some-name",
37
+ :instances => "1",
38
+ :plan => "100",
39
+ :memory => "1G",
40
+ :command => "ruby main.rb",
41
+ :buildpack => "git://example.com",
42
+ :stack => "lucid64"
43
+ }
65
44
  end
66
45
 
67
- after do
68
- FakeFS.deactivate!
69
- FakeFS::FileSystem.clear
46
+ context "when all the inputs are given" do
47
+ its([:name]) { should eq "some-name" }
48
+ its([:total_instances]) { should eq 1 }
49
+ its([:space]) { should eq client.current_space }
50
+ its([:command]) { should eq "ruby main.rb" }
51
+ its([:memory]) { should eq 1024 }
52
+ its([:stack]) { should eq lucid64 }
70
53
  end
71
54
 
72
- its([:command]) { should eq "ruby main.rb" }
73
- end
74
- end
55
+ context "when the command is given" do
56
+ context "and there is a Procfile in the application's root" do
57
+ before do
58
+ FakeFS.activate!
59
+ Dir.mkdir(path)
75
60
 
76
- context 'when certain inputs are not given' do
77
- it 'asks for the name' do
78
- given.delete(:name)
79
- mock_ask("Name") { "some-name" }
80
- subject
81
- end
61
+ File.open("#{path}/Procfile", "w") do |file|
62
+ file.write("this is a procfile")
63
+ end
64
+ end
82
65
 
83
- it 'asks for the total instances' do
84
- given.delete(:instances)
85
- mock_ask("Instances", anything) { 1 }
86
- subject
87
- end
66
+ after do
67
+ FakeFS.deactivate!
68
+ FakeFS::FileSystem.clear
69
+ end
88
70
 
89
- context 'when the command is not given' do
90
- before { given.delete(:command) }
71
+ its([:command]) { should eq "ruby main.rb" }
72
+ end
73
+ end
91
74
 
92
- shared_examples 'an app that can have a custom start command' do
93
- it "asks for a start command with a default as 'none'" do
94
- mock_ask("Custom startup command", :default => "none") do
95
- "abcd"
96
- end
75
+ context "when certain inputs are not given" do
76
+ it "asks for the name" do
77
+ given.delete(:name)
78
+ mock_ask("Name") { "some-name" }
79
+ subject
80
+ end
97
81
 
98
- expect(subject[:command]).to eq "abcd"
82
+ it "asks for the total instances" do
83
+ given.delete(:instances)
84
+ mock_ask("Instances", anything) { 1 }
85
+ subject
99
86
  end
100
87
 
101
- context "when the user enters 'none'" do
102
- it "has the command as nil" do
103
- stub_ask("Custom startup command", :default => "none") do
104
- "none"
88
+ context "when the command is not given" do
89
+ before { given.delete(:command) }
90
+
91
+ shared_examples "an app that can have a custom start command" do
92
+ it "asks for a start command with a default as 'none'" do
93
+ mock_ask("Custom startup command", :default => "none") do
94
+ "abcd"
95
+ end
96
+
97
+ expect(subject[:command]).to eq "abcd"
105
98
  end
106
99
 
107
- expect(subject[:command]).to be_nil
100
+ context "when the user enters 'none'" do
101
+ it "has the command as nil" do
102
+ stub_ask("Custom startup command", :default => "none") do
103
+ "none"
104
+ end
105
+
106
+ expect(subject[:command]).to be_nil
107
+ end
108
+ end
108
109
  end
109
- end
110
- end
111
110
 
112
- include_examples 'an app that can have a custom start command'
111
+ include_examples "an app that can have a custom start command"
113
112
 
114
- describe "getting the start command" do
115
- before do
116
- FakeFS.activate!
117
- Dir.mkdir(path)
118
- end
113
+ describe "getting the start command" do
114
+ before do
115
+ FakeFS.activate!
116
+ Dir.mkdir(path)
117
+ end
119
118
 
120
- after do
121
- FakeFS.deactivate!
122
- FakeFS::FileSystem.clear
123
- end
119
+ after do
120
+ FakeFS.deactivate!
121
+ FakeFS::FileSystem.clear
122
+ end
124
123
 
125
- context "when there is a Procfile in the app's root" do
126
- before do
127
- File.open("#{path}/Procfile", "w") do |file|
128
- file.write("this is a procfile")
124
+ context "when there is a Procfile in the app's root" do
125
+ before do
126
+ File.open("#{path}/Procfile", "w") do |file|
127
+ file.write("this is a procfile")
128
+ end
129
+ end
130
+
131
+ it "does not ask for a start command" do
132
+ dont_allow_ask("Startup command")
133
+ subject
134
+ end
129
135
  end
130
- end
131
136
 
132
- it 'does not ask for a start command' do
133
- dont_allow_ask("Startup command")
134
- subject
137
+ context "when there is no Procfile in the app's root" do
138
+ it "asks for a start command" do
139
+ mock_ask("Custom startup command", :default => "none")
140
+ subject
141
+ end
142
+ end
135
143
  end
136
144
  end
137
145
 
138
- context "when there is no Procfile in the app's root" do
139
- it 'asks for a start command' do
140
- mock_ask("Custom startup command", :default => "none")
141
- subject
142
- end
143
- end
144
- end
145
- end
146
+ it "asks for the memory" do
147
+ given.delete(:memory)
146
148
 
147
- it 'asks for the memory' do
148
- given.delete(:memory)
149
+ memory_choices = %w(64M 128M 256M 512M 1G)
150
+ create.stub(:memory_choices).and_return(memory_choices)
149
151
 
150
- memory_choices = %w(64M 128M 256M 512M 1G)
151
- stub(create).memory_choices { memory_choices }
152
+ mock_ask("Memory Limit", anything) do |_, options|
153
+ expect(options[:choices]).to eq memory_choices
154
+ expect(options[:default]).to eq "256M"
155
+ "1G"
156
+ end
152
157
 
153
- mock_ask('Memory Limit', anything) do |_, options|
154
- expect(options[:choices]).to eq memory_choices
155
- expect(options[:default]).to eq "256M"
156
- "1G"
158
+ subject
159
+ end
157
160
  end
158
-
159
- subject
160
161
  end
161
- end
162
- end
163
-
164
- describe '#create_app' do
165
- before { dont_allow_ask }
166
-
167
- let(:app) { fake(:app, :guid => nil) }
168
- let(:space) { fake(:space, :name => "some-space") }
169
-
170
- let(:attributes) do
171
- { :name => "some-app",
172
- :total_instances => 2,
173
- :memory => 1024,
174
- :buildpack => "git://example.com"
175
- }
176
- end
177
162
 
178
- before do
179
- stub(client).app { app }
180
- stub(client).current_space { space }
181
- end
163
+ describe "#create_app" do
164
+ before { dont_allow_ask }
182
165
 
183
- subject { create.create_app(attributes) }
166
+ let(:app) { double(:app, :name => "some-app").as_null_object }
167
+ let(:space) { double(:space, :name => "some-space") }
184
168
 
185
- it 'creates an app based on the resulting inputs' do
186
- mock(create).filter(:create_app, app) { app }
169
+ let(:attributes) do
170
+ {:name => "some-app",
171
+ :total_instances => 2,
172
+ :memory => 1024,
173
+ :buildpack => "git://example.com"
174
+ }
175
+ end
187
176
 
188
- mock(app).create!
177
+ before do
178
+ client.stub(:app).and_return(app)
179
+ client.stub(:current_space).and_return(space)
180
+ end
189
181
 
190
- subject
182
+ subject { create.create_app(attributes) }
191
183
 
192
- attributes.each do |key, val|
193
- expect(app.send(key)).to eq val
194
- end
195
- end
184
+ context "when the user does not have permission to create apps" do
185
+ it "fails with a friendly message" do
186
+ app.stub(:create!).and_raise(CFoundry::NotAuthorized, "foo")
196
187
 
197
- context "when the user does not have permission to create apps" do
198
- it "fails with a friendly message" do
199
- stub(app).create! { raise CFoundry::NotAuthorized, "foo" }
188
+ expect { subject }.to raise_error(
189
+ CF::UserError,
190
+ "You need the Project Developer role in some-space to push.")
191
+ end
192
+ end
200
193
 
201
- expect { subject }.to raise_error(
202
- CF::UserError,
203
- "You need the Project Developer role in some-space to push.")
204
- end
205
- end
194
+ context "with an invalid buildpack" do
195
+ before do
196
+ app.stub(:create!) do
197
+ raise CFoundry::MessageParseError.new(
198
+ "Request invalid due to parse error: Field: buildpack, Error: Value git@github.com:cloudfoundry/heroku-buildpack-ruby.git doesn't match regexp String /GIT_URL_REGEX/",
199
+ 1001)
200
+ end
201
+ end
206
202
 
207
- context "with an invalid buildpack" do
208
- before do
209
- stub(app).create! do
210
- raise CFoundry::MessageParseError.new(
211
- "Request invalid due to parse error: Field: buildpack, Error: Value git@github.com:cloudfoundry/heroku-buildpack-ruby.git doesn't match regexp String /GIT_URL_REGEX/",
212
- 1001)
203
+ it "fails and prints a pretty message" do
204
+ create.stub(:line).with(anything)
205
+ expect { subject }.to raise_error(
206
+ CF::UserError, "Buildpack must be a public git repository URI.")
207
+ end
213
208
  end
214
209
  end
215
210
 
216
- it "fails and prints a pretty message" do
217
- stub(create).line(anything)
218
- expect { subject }.to raise_error(
219
- CF::UserError, "Buildpack must be a public git repository URI.")
220
- end
221
- end
222
- end
211
+ describe "#map_url" do
212
+ let(:app) { double(:app, :space => space).as_null_object }
213
+ let(:space) { double(:space, :domains => domains) }
214
+ let(:domains) { [double(:domain, :name => "foo.com")] }
215
+ let(:hosts) { [app.name] }
223
216
 
224
- describe '#map_url' do
225
- let(:app) { fake(:app, :space => space) }
226
- let(:space) { fake(:space, :domains => domains) }
227
- let(:domains) { [fake(:domain, :name => "foo.com")] }
228
- let(:hosts) { [app.name] }
217
+ subject { create.map_route(app) }
229
218
 
230
- subject { create.map_route(app) }
231
-
232
- it "asks for a subdomain with 'none' as an option" do
233
- mock_ask('Subdomain', anything) do |_, options|
234
- expect(options[:choices]).to eq(hosts + %w(none))
235
- expect(options[:default]).to eq hosts.first
236
- hosts.first
237
- end
219
+ it "asks for a subdomain with 'none' as an option" do
220
+ mock_ask("Subdomain", anything) do |_, options|
221
+ expect(options[:choices]).to eq(hosts + %w(none))
222
+ expect(options[:default]).to eq hosts.first
223
+ hosts.first
224
+ end
238
225
 
239
- stub_ask("Domain", anything) { domains.first }
226
+ stub_ask("Domain", anything) { domains.first }
240
227
 
241
- stub(create).invoke
228
+ create.stub(:invoke)
242
229
 
243
- subject
244
- end
230
+ subject
231
+ end
245
232
 
246
- it "asks for a domain with 'none' as an option" do
247
- stub_ask("Subdomain", anything) { hosts.first }
233
+ it "asks for a domain with 'none' as an option" do
234
+ stub_ask("Subdomain", anything) { hosts.first }
248
235
 
249
- mock_ask('Domain', anything) do |_, options|
250
- expect(options[:choices]).to eq(domains + %w(none))
251
- expect(options[:default]).to eq domains.first
252
- domains.first
253
- end
236
+ mock_ask("Domain", anything) do |_, options|
237
+ expect(options[:choices]).to eq(domains + %w(none))
238
+ expect(options[:default]).to eq domains.first
239
+ domains.first
240
+ end
254
241
 
255
- stub(create).invoke
242
+ create.stub(:invoke)
256
243
 
257
- subject
258
- end
244
+ subject
245
+ end
259
246
 
260
- it "maps the host and domain after both are given" do
261
- stub_ask('Subdomain', anything) { hosts.first }
262
- stub_ask('Domain', anything) { domains.first }
247
+ it "maps the host and domain after both are given" do
248
+ stub_ask("Subdomain", anything) { hosts.first }
249
+ stub_ask("Domain", anything) { domains.first }
263
250
 
264
- mock(create).invoke(:map,
265
- :app => app, :host => hosts.first,
266
- :domain => domains.first)
251
+ create.should_receive(:invoke).with(:map,
252
+ :app => app, :host => hosts.first,
253
+ :domain => domains.first)
267
254
 
268
- subject
269
- end
255
+ subject
256
+ end
270
257
 
271
- context "when 'none' is given as the host" do
272
- context "and a domain is provided afterwards" do
273
- it "invokes 'map' with an empty host" do
274
- mock_ask('Subdomain', anything) { "none" }
275
- stub_ask('Domain', anything) { domains.first }
258
+ context "when 'none' is given as the host" do
259
+ context "and a domain is provided afterwards" do
260
+ it "invokes 'map' with an empty host" do
261
+ mock_ask("Subdomain", anything) { "none" }
262
+ stub_ask("Domain", anything) { domains.first }
276
263
 
277
- mock(create).invoke(:map,
278
- :host => "", :domain => domains.first, :app => app)
264
+ create.should_receive(:invoke).with(:map,
265
+ :host => "", :domain => domains.first, :app => app)
279
266
 
280
- subject
267
+ subject
268
+ end
269
+ end
281
270
  end
282
- end
283
- end
284
271
 
285
- context "when 'none' is given as the domain" do
286
- it "does not perform any mapping" do
287
- stub_ask('Subdomain', anything) { "foo" }
288
- mock_ask('Domain', anything) { "none" }
272
+ context "when 'none' is given as the domain" do
273
+ it "does not perform any mapping" do
274
+ stub_ask("Subdomain", anything) { "foo" }
275
+ mock_ask("Domain", anything) { "none" }
289
276
 
290
- dont_allow(create).invoke(:map, anything)
277
+ create.should_not_receive(:invoke).with(:map, anything)
291
278
 
292
- subject
293
- end
294
- end
279
+ subject
280
+ end
281
+ end
295
282
 
296
- context "when mapping fails" do
297
- before do
298
- mock_ask('Subdomain', anything) { "foo" }
299
- mock_ask('Domain', anything) { domains.first }
283
+ context "when mapping fails" do
284
+ before do
285
+ mock_ask("Subdomain", anything) { "foo" }
286
+ mock_ask("Domain", anything) { domains.first }
300
287
 
301
- mock(create).invoke(:map,
302
- :host => "foo", :domain => domains.first, :app => app) do
303
- raise CFoundry::RouteHostTaken.new("foo", 1234)
304
- end
305
- end
288
+ create.should_receive(:invoke).with(:map,
289
+ :host => "foo", :domain => domains.first, :app => app) do
290
+ raise CFoundry::RouteHostTaken.new("foo", 1234)
291
+ end
292
+ end
306
293
 
307
- it "asks again" do
308
- stub(create).line
294
+ it "asks again" do
295
+ create.stub(:line)
309
296
 
310
- mock_ask('Subdomain', anything) { hosts.first }
311
- mock_ask('Domain', anything) { domains.first }
297
+ mock_ask("Subdomain", anything) { hosts.first }
298
+ mock_ask("Domain", anything) { domains.first }
312
299
 
313
- stub(create).invoke
300
+ create.stub(:invoke)
314
301
 
315
- subject
316
- end
302
+ subject
303
+ end
317
304
 
318
- it "reports the failure message" do
319
- mock(create).line "foo"
320
- mock(create).line
305
+ it "reports the failure message" do
306
+ create.should_receive(:line).with("foo")
307
+ create.should_receive(:line)
321
308
 
322
- stub_ask('Subdomain', anything) { hosts.first }
323
- stub_ask('Domain', anything) { domains.first }
309
+ stub_ask("Subdomain", anything) { hosts.first }
310
+ stub_ask("Domain", anything) { domains.first }
324
311
 
325
- stub(create).invoke
312
+ create.stub(:invoke)
326
313
 
327
- subject
314
+ subject
315
+ end
316
+ end
328
317
  end
329
- end
330
- end
331
318
 
332
- describe '#create_services' do
333
- let(:app) { fake(:app) }
334
- subject { create.create_services(app) }
319
+ describe "#create_services" do
320
+ let(:app) { fake(:app) }
321
+ subject { create.create_services(app) }
335
322
 
336
- context 'when forcing' do
337
- let(:inputs) { {:force => true} }
323
+ context "when forcing" do
324
+ let(:inputs) { {:force => true} }
338
325
 
339
- it "does not ask to create any services" do
340
- dont_allow_ask("Create services for application?", anything)
341
- subject
342
- end
326
+ it "does not ask to create any services" do
327
+ dont_allow_ask("Create services for application?", anything)
328
+ subject
329
+ end
343
330
 
344
- it "does not create any services" do
345
- dont_allow(create).invoke(:create_service, anything)
346
- subject
347
- end
348
- end
331
+ it "does not create any services" do
332
+ create.should_not_receive(:invoke).with(:create_service, anything)
333
+ subject
334
+ end
335
+ end
349
336
 
350
- context 'when not forcing' do
351
- let(:inputs) { { :force => false } }
337
+ context "when not forcing" do
338
+ let(:inputs) { {:force => false} }
352
339
 
353
- it 'does not create the service if asked not to' do
354
- mock_ask("Create services for application?", anything) { false }
355
- dont_allow(create).invoke(:create_service, anything)
340
+ it "does not create the service if asked not to" do
341
+ mock_ask("Create services for application?", anything) { false }
342
+ create.should_not_receive(:invoke).with(:create_service, anything)
356
343
 
357
- subject
358
- end
344
+ subject
345
+ end
359
346
 
360
- it 'asks again to create a service' do
361
- mock_ask("Create services for application?", anything) { true }
362
- mock(create).invoke(:create_service, { :app => app }, :plan => :interact).ordered
347
+ it "asks again to create a service" do
348
+ mock_ask("Create services for application?", anything) { true }
349
+ create.should_receive(:invoke).with(:create_service, {:app => app}, :plan => :interact).ordered
363
350
 
364
- mock_ask("Create another service?", :default => false) { true }
365
- mock(create).invoke(:create_service, { :app => app }, :plan => :interact).ordered
351
+ mock_ask("Create another service?", :default => false) { true }
352
+ create.should_receive(:invoke).with(:create_service, {:app => app}, :plan => :interact).ordered
366
353
 
367
- mock_ask("Create another service?", :default => false) { true }
368
- mock(create).invoke(:create_service, { :app => app }, :plan => :interact).ordered
354
+ mock_ask("Create another service?", :default => false) { true }
355
+ create.should_receive(:invoke).with(:create_service, {:app => app}, :plan => :interact).ordered
369
356
 
370
- mock_ask("Create another service?", :default => false) { false }
371
- dont_allow(create).invoke(:create_service, anything).ordered
357
+ mock_ask("Create another service?", :default => false) { false }
358
+ create.should_not_receive(:invoke).with(:create_service, anything).ordered
372
359
 
373
- subject
360
+ subject
361
+ end
362
+ end
374
363
  end
375
- end
376
- end
377
364
 
378
- describe '#bind_services' do
379
- let(:app) { fake(:app) }
365
+ describe "#bind_services" do
366
+ let(:app) { double(:app).as_null_object }
380
367
 
381
- subject { create.bind_services(app) }
368
+ subject { create.bind_services(app) }
382
369
 
383
- context 'when forcing' do
384
- let(:global) { { :force => true, :color => false, :quiet => true } }
370
+ context "when forcing" do
371
+ let(:global) { {:force => true, :color => false, :quiet => true} }
385
372
 
386
- it "does not ask to bind any services" do
387
- dont_allow_ask("Bind other services to application?", anything)
388
- subject
389
- end
373
+ it "does not ask to bind any services" do
374
+ dont_allow_ask("Bind other services to application?", anything)
375
+ subject
376
+ end
390
377
 
391
- it "does not bind any services" do
392
- dont_allow(create).invoke(:bind_service, anything)
393
- subject
394
- end
395
- end
378
+ it "does not bind any services" do
379
+ create.should_not_receive(:invoke).with(:bind_service, anything)
380
+ subject
381
+ end
382
+ end
396
383
 
397
- context 'when not forcing' do
398
- it 'does not bind the service if asked not to' do
399
- mock_ask("Bind other services to application?", anything) { false }
400
- dont_allow(create).invoke(:bind_service, anything)
384
+ context "when not forcing" do
385
+ it "does not bind the service if asked not to" do
386
+ mock_ask("Bind other services to application?", anything) { false }
387
+ create.should_not_receive(:invoke).with(:bind_service, anything)
401
388
 
402
- subject
403
- end
389
+ subject
390
+ end
404
391
 
405
- it 'asks again to bind a service' do
406
- bind_times = 3
407
- call_count = 0
392
+ it "asks again to bind a service" do
393
+ bind_times = 3
394
+ call_count = 0
408
395
 
409
- mock_ask("Bind other services to application?", anything) { true }
396
+ mock_ask("Bind other services to application?", anything) { true }
410
397
 
411
- mock(create).invoke(:bind_service, :app => app).times(bind_times) do
412
- call_count += 1
413
- stub(app).services { service_instances.first(call_count) }
414
- end
398
+ create.should_receive(:invoke).with(:bind_service, :app => app).exactly(bind_times).times do
399
+ call_count += 1
400
+ app.stub(:services).and_return(service_instances.first(call_count))
401
+ end
415
402
 
416
- mock_ask("Bind another service?", anything).times(bind_times) do
417
- call_count < bind_times
418
- end
403
+ mock_ask("Bind another service?", anything).exactly(bind_times).times do
404
+ call_count < bind_times
405
+ end
419
406
 
420
- subject
421
- end
407
+ subject
408
+ end
422
409
 
423
- it 'stops asking if there are no more services to bind' do
424
- bind_times = service_instances.size
425
- call_count = 0
410
+ it "stops asking if there are no more services to bind" do
411
+ bind_times = service_instances.size
412
+ call_count = 0
426
413
 
427
- mock_ask("Bind other services to application?", anything) { true }
414
+ mock_ask("Bind other services to application?", anything) { true }
428
415
 
429
- mock(create).invoke(:bind_service, :app => app).times(bind_times) do
430
- call_count += 1
431
- stub(app).services { service_instances.first(call_count) }
432
- end
416
+ create.should_receive(:invoke).with(:bind_service, :app => app).exactly(bind_times).times do
417
+ call_count += 1
418
+ app.stub(:services).and_return(service_instances.first(call_count))
419
+ end
433
420
 
434
- mock_ask("Bind another service?", anything).times(bind_times - 1) { true }
421
+ mock_ask("Bind another service?", anything).exactly(bind_times-1).times { true }
435
422
 
436
- subject
437
- end
423
+ subject
424
+ end
438
425
 
439
- context 'when there are no services' do
440
- let(:service_instances) { [] }
426
+ context "when there are no services" do
427
+ let(:service_instances) { [] }
441
428
 
442
- it 'does not ask to bind anything' do
443
- dont_allow_ask
444
- subject
429
+ it "does not ask to bind anything" do
430
+ dont_allow_ask
431
+ subject
432
+ end
433
+ end
445
434
  end
446
435
  end
447
- end
448
- end
449
436
 
450
- describe '#start_app' do
451
- let(:app) { fake(:app) }
452
- subject { create.start_app(app) }
437
+ describe "#start_app" do
438
+ let(:app) { fake(:app) }
439
+ subject { create.start_app(app) }
453
440
 
454
- context 'when the start flag is provided' do
455
- let(:inputs) { {:start => true} }
441
+ context "when the start flag is provided" do
442
+ let(:inputs) { {:start => true} }
456
443
 
457
- it 'invokes the start command' do
458
- mock(create).invoke(:start, :app => app)
459
- subject
460
- end
461
- end
444
+ it "invokes the start command" do
445
+ create.should_receive(:invoke).with(:start, :app => app)
446
+ subject
447
+ end
448
+ end
462
449
 
463
- context 'when the start flag is not provided' do
464
- let(:inputs) { {:start => false} }
450
+ context "when the start flag is not provided" do
451
+ let(:inputs) { {:start => false} }
465
452
 
466
- it 'invokes the start command' do
467
- dont_allow(create).invoke(:start, anything)
468
- subject
453
+ it "invokes the start command" do
454
+ create.should_not_receive(:invoke).with(:start, anything)
455
+ subject
456
+ end
457
+ end
469
458
  end
470
- end
471
- end
472
459
 
473
- describe '#memory_choices' do
474
- let(:info) { {} }
460
+ describe "#memory_choices" do
461
+ let(:info) { {} }
475
462
 
476
- before do
477
- stub(client).info { info }
478
- end
463
+ before do
464
+ client.stub(:info).and_return(info)
465
+ end
479
466
 
480
- context "when the user has usage information" do
481
- let(:info) do
482
- { :usage => { :memory => 512 },
483
- :limits => { :memory => 2048 }
484
- }
485
- end
467
+ context "when the user has usage information" do
468
+ let(:info) do
469
+ {:usage => {:memory => 512},
470
+ :limits => {:memory => 2048}
471
+ }
472
+ end
486
473
 
487
- it "asks for the memory with the ceiling taking the memory usage into account" do
488
- expect(subject.memory_choices).to eq(%w[64M 128M 256M 512M 1G])
489
- end
490
- end
474
+ it "asks for the memory with the ceiling taking the memory usage into account" do
475
+ expect(subject.memory_choices).to eq(%w[64M 128M 256M 512M 1G])
476
+ end
477
+ end
491
478
 
492
- context "when the user does not have usage information" do
493
- let(:info) { {:limits => { :memory => 2048 } } }
479
+ context "when the user does not have usage information" do
480
+ let(:info) { {:limits => {:memory => 2048}} }
494
481
 
495
- it "asks for the memory with the ceiling as their overall limit" do
496
- expect(subject.memory_choices).to eq(%w[64M 128M 256M 512M 1G 2G])
482
+ it "asks for the memory with the ceiling as their overall limit" do
483
+ expect(subject.memory_choices).to eq(%w[64M 128M 256M 512M 1G 2G])
484
+ end
485
+ end
497
486
  end
498
487
  end
499
488
  end