cf 1.1.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/lib/cf/cli/start/login.rb +3 -0
  2. data/lib/cf/version.rb +1 -1
  3. data/spec/cf/cli/app/base_spec.rb +2 -2
  4. data/spec/cf/cli/app/delete_spec.rb +150 -129
  5. data/spec/cf/cli/app/instances_spec.rb +56 -51
  6. data/spec/cf/cli/app/push/create_spec.rb +72 -70
  7. data/spec/cf/cli/app/push_spec.rb +46 -43
  8. data/spec/cf/cli/app/rename_spec.rb +13 -6
  9. data/spec/cf/cli/app/scale_spec.rb +9 -4
  10. data/spec/cf/cli/app/start_spec.rb +28 -23
  11. data/spec/cf/cli/app/stats_spec.rb +9 -10
  12. data/spec/cf/cli/domain/map_spec.rb +13 -10
  13. data/spec/cf/cli/domain/unmap_spec.rb +11 -11
  14. data/spec/cf/cli/organization/delete_spec.rb +10 -4
  15. data/spec/cf/cli/organization/orgs_spec.rb +15 -4
  16. data/spec/cf/cli/organization/rename_spec.rb +7 -5
  17. data/spec/cf/cli/populators/organization_spec.rb +40 -29
  18. data/spec/cf/cli/populators/space_spec.rb +51 -40
  19. data/spec/cf/cli/populators/target_spec.rb +4 -2
  20. data/spec/cf/cli/route/delete_spec.rb +6 -4
  21. data/spec/cf/cli/route/map_spec.rb +54 -35
  22. data/spec/cf/cli/route/unmap_spec.rb +21 -15
  23. data/spec/cf/cli/service/create_spec.rb +17 -12
  24. data/spec/cf/cli/service/rename_spec.rb +8 -6
  25. data/spec/cf/cli/service/services_spec.rb +15 -8
  26. data/spec/cf/cli/space/create_spec.rb +5 -9
  27. data/spec/cf/cli/space/delete_spec.rb +9 -8
  28. data/spec/cf/cli/space/rename_spec.rb +15 -8
  29. data/spec/cf/cli/space/space_spec.rb +10 -10
  30. data/spec/cf/cli/space/spaces_spec.rb +11 -5
  31. data/spec/cf/cli/space/switch_space_spec.rb +7 -7
  32. data/spec/cf/cli/start/info_spec.rb +3 -1
  33. data/spec/cf/cli/start/login_spec.rb +1 -1
  34. data/spec/cf/cli/start/logout_spec.rb +1 -1
  35. data/spec/cf/cli/start/target_spec.rb +7 -6
  36. data/spec/cf/cli/user/create_spec.rb +3 -4
  37. data/spec/cf/cli/user/passwd_spec.rb +2 -4
  38. data/spec/cf/cli/user/register_spec.rb +4 -4
  39. data/spec/cf/cli_spec.rb +1 -3
  40. data/spec/factories/cfoundry/v2/apps_factory.rb +12 -0
  41. data/spec/factories/cfoundry/v2/clients_factory.rb +4 -0
  42. data/spec/factories/cfoundry/v2/{domain_factory.rb → domains_factory.rb} +0 -0
  43. data/spec/factories/cfoundry/v2/organizations_factory.rb +12 -0
  44. data/spec/factories/cfoundry/v2/{route_factory.rb → routes_factory.rb} +0 -0
  45. data/spec/factories/cfoundry/v2/service_bindings_factory.rb +11 -0
  46. data/spec/factories/cfoundry/v2/service_instances_factory.rb +12 -0
  47. data/spec/factories/cfoundry/v2/service_plans_factory.rb +13 -0
  48. data/spec/factories/cfoundry/v2/services_factory.rb +14 -0
  49. data/spec/factories/cfoundry/v2/spaces_factory.rb +12 -0
  50. data/spec/factories/cfoundry/v2/stacks_factory.rb +11 -0
  51. data/spec/factories/cfoundry/v2/{user_factory.rb → users_factory.rb} +0 -0
  52. data/spec/features/push_flow_spec.rb +8 -8
  53. data/spec/manifests/manifests_spec.rb +34 -51
  54. data/spec/manifests/plugin_spec.rb +17 -6
  55. data/spec/spec_helper.rb +0 -1
  56. data/spec/support/interact_helper.rb +1 -1
  57. data/spec/tunnel/tunnel_spec.rb +5 -5
  58. metadata +37 -13
@@ -5,11 +5,16 @@ describe CF::Route::Unmap do
5
5
  stub_client_and_precondition
6
6
  end
7
7
 
8
- let(:client) { fake_client :apps => [app] }
8
+ let(:client) do
9
+ build(:client).tap do |client|
10
+ client.stub(:apps).and_return([app])
11
+ client.stub(:apps_by_name).and_return([app])
12
+ end
13
+ end
9
14
 
10
- let(:app){ fake(:app, :space => space, :name => "app-name") }
11
- let(:space) { fake(:space, :name => "space-name", :domains => space_domains) }
12
- let(:domain) { fake(:domain, :name => domain_name ) }
15
+ let(:app){ build(:app, :space => space, :name => "app-name") }
16
+ let(:space) { build(:space, :name => "space-name", :domains => space_domains) }
17
+ let(:domain) { build(:domain, :name => domain_name ) }
13
18
  let(:domain_name) { "some-domain.com" }
14
19
  let(:host_name) { "some-host" }
15
20
  let(:url) { "#{host_name}.#{domain_name}" }
@@ -38,8 +43,8 @@ describe CF::Route::Unmap do
38
43
  subject { cf %W[unmap #{url} #{app.name}] }
39
44
 
40
45
  context "when the given route is mapped to the given app" do
41
- let(:app) { fake(:app, :space => space, :name => "app-name", :routes => [route]) }
42
- let(:route) { fake(:route, :space => space, :host => host_name, :domain => domain) }
46
+ let(:app) { build(:app, :space => space, :name => "app-name", :routes => [route]) }
47
+ let(:route) { build(:route, :space => space, :host => host_name, :domain => domain) }
43
48
 
44
49
  it "unmaps the url from the app" do
45
50
  app.should_receive(:remove_route).with(route)
@@ -49,6 +54,7 @@ describe CF::Route::Unmap do
49
54
 
50
55
  context "when the given route is NOT mapped to the given app" do
51
56
  it "displays an error" do
57
+ app.stub(:routes).and_return([])
52
58
  subject
53
59
  expect(error_output).to say("Unknown route")
54
60
  end
@@ -56,14 +62,14 @@ describe CF::Route::Unmap do
56
62
  end
57
63
 
58
64
  context "when only an app is specified" do
59
- let(:other_route) { fake(:route, :host => "abcd", :domain => domain) }
60
- let(:route) { fake(:route, :host => "efgh", :domain => domain) }
61
- let(:app) { fake(:app, :space => space, :routes => [route, other_route] )}
65
+ let(:other_route) { build(:route, :host => "abcd", :domain => domain) }
66
+ let(:route) { build(:route, :host => "efgh", :domain => domain) }
67
+ let(:app) { build(:app, :space => space, :routes => [route, other_route] )}
62
68
 
63
69
  subject { cf %W[unmap --app #{app.name}] }
64
70
 
65
71
  it "asks the user to select from the app's urls" do
66
- mock_ask("Which URL?", anything) do |_, opts|
72
+ should_ask("Which URL?", anything) do |_, opts|
67
73
  expect(opts[:choices]).to eq [other_route, route]
68
74
  route
69
75
  end
@@ -81,9 +87,9 @@ describe CF::Route::Unmap do
81
87
  end
82
88
 
83
89
  context "when an app is specified and the --all option is given" do
84
- let(:other_route) { fake(:route, :host => "abcd", :domain => domain) }
85
- let(:route) { fake(:route, :host => "efgh", :domain => domain) }
86
- let(:app) { fake(:app, :routes => [route, other_route]) }
90
+ let(:other_route) { build(:route, :host => "abcd", :domain => domain) }
91
+ let(:route) { build(:route, :host => "efgh", :domain => domain) }
92
+ let(:app) { build(:app, :routes => [route, other_route]) }
87
93
 
88
94
  subject { cf %W[unmap --all --app #{app.name}] }
89
95
 
@@ -95,8 +101,8 @@ describe CF::Route::Unmap do
95
101
  end
96
102
 
97
103
  context "when only a url is passed" do
98
- let(:route) { fake(:route, :host => host_name, :domain => domain) }
99
- let(:client) { fake_client :routes => [route] }
104
+ let(:route) { build(:route, :host => host_name, :domain => domain) }
105
+ before { client.stub(:routes).and_return([route]) }
100
106
 
101
107
  subject { cf %W[unmap #{url}] }
102
108
 
@@ -3,6 +3,12 @@ require "spec_helper"
3
3
  module CF
4
4
  module Service
5
5
  describe Create do
6
+ let(:client) { build(:client) }
7
+
8
+ before do
9
+ stub_client_and_precondition
10
+ end
11
+
6
12
  describe "metadata" do
7
13
  let(:command) { Mothership.commands[:create_service] }
8
14
 
@@ -23,23 +29,22 @@ module CF
23
29
  end
24
30
 
25
31
  context "when there are services" do
26
- let(:service_plan) { fake(:service_plan, :name => "F20") }
27
- let(:selected_service) { fake(:service, :label => "Foo Service", :service_plans => [service_plan]) }
32
+ let(:service_plan) { build(:service_plan, :name => "F20") }
33
+ let(:selected_service) { build(:service, :label => "Foo Service", :service_plans => [service_plan]) }
28
34
  let(:command) { Mothership.new.invoke(:create_service, params, {}) }
29
- let(:client) { fake_client(:services => services) }
30
35
  let(:params) { {} }
31
36
 
32
37
  before do
33
- CF::CLI.any_instance.stub(:client).and_return(client)
38
+ client.stub(:services).and_return(services)
34
39
  end
35
40
 
36
41
  describe "when there is at least one service" do
37
42
  let(:services) { [selected_service] }
38
43
 
39
44
  it "asks for the service" do
40
- mock_ask("What kind?", anything) { selected_service }
41
- mock_ask("Name?", anything) { selected_service.label }
42
- mock_ask("Which plan?", anything) { service_plan }
45
+ should_ask("What kind?", anything) { selected_service }
46
+ should_ask("Name?", anything) { selected_service.label }
47
+ should_ask("Which plan?", anything) { service_plan }
43
48
  CFoundry::V2::ServiceInstance.any_instance.stub(:create!)
44
49
 
45
50
  capture_output { command }
@@ -47,12 +52,12 @@ module CF
47
52
  end
48
53
 
49
54
  describe "when there are more than one services" do
50
- let(:services) { [selected_service, fake(:service), fake(:service)] }
55
+ let(:services) { [selected_service, build(:service), build(:service)] }
51
56
 
52
57
  it "asks for the service" do
53
- mock_ask("What kind?", anything) { selected_service }
54
- mock_ask("Name?", anything) { selected_service.label }
55
- mock_ask("Which plan?", anything) { service_plan }
58
+ should_ask("What kind?", anything) { selected_service }
59
+ should_ask("Name?", anything) { selected_service.label }
60
+ should_ask("Which plan?", anything) { service_plan }
56
61
  CFoundry::V2::ServiceInstance.any_instance.stub(:create!)
57
62
 
58
63
  capture_output { command }
@@ -75,7 +80,7 @@ module CF
75
80
  end
76
81
 
77
82
  describe "when entering command line options" do
78
- let(:service_plan) { fake(:service_plan, :name => "f20") }
83
+ let(:service_plan) { build(:service_plan, :name => "f20") }
79
84
  let(:params) { {
80
85
  :name => "my-service-name",
81
86
  :offering => selected_service,
@@ -4,14 +4,17 @@ describe CF::Service::Rename do
4
4
  let(:global) { { :color => false, :quiet => true } }
5
5
  let(:inputs) { {} }
6
6
  let(:given) { {} }
7
- let(:client) { fake_client }
7
+ let(:client) { build(:client) }
8
8
  let(:service) {}
9
+ let(:services) { [] }
9
10
  let(:new_name) { "some-new-name" }
10
11
 
11
12
  subject { Mothership.new.invoke(:rename_service, inputs, given, global) }
12
13
 
13
14
  before do
14
15
  CF::CLI.any_instance.stub(:client).and_return(client)
16
+ client.stub(:service_instances => services)
17
+ client.stub(:service_instances_by_name => services)
15
18
  end
16
19
 
17
20
  describe "metadata" do
@@ -48,14 +51,13 @@ describe CF::Service::Rename do
48
51
  end
49
52
 
50
53
  context "when there are services" do
51
- let(:client) { fake_client(:service_instances => services) }
52
- let(:services) { fake_list(:service_instance, 2) }
54
+ let(:services) { Array.new(2) { build(:service_instance) } }
53
55
  let(:renamed_service) { services.first }
54
56
 
55
57
  context "when the defaults are used" do
56
58
  it "asks for the service and new name and renames" do
57
- mock_ask("Rename which service?", anything) { renamed_service }
58
- mock_ask("New name") { new_name }
59
+ should_ask("Rename which service?", anything) { renamed_service }
60
+ should_ask("New name") { new_name }
59
61
  renamed_service.should_receive(:name=).with(new_name)
60
62
  renamed_service.should_receive(:update!)
61
63
  subject
@@ -67,7 +69,7 @@ describe CF::Service::Rename do
67
69
 
68
70
  it "asks for the new name and renames" do
69
71
  dont_allow_ask("Rename which service?", anything)
70
- mock_ask("New name") { new_name }
72
+ should_ask("New name") { new_name }
71
73
  renamed_service.should_receive(:name=).with(new_name)
72
74
  renamed_service.should_receive(:update!)
73
75
  subject
@@ -33,20 +33,27 @@ module CF
33
33
  let(:global) { {:color => false} }
34
34
  let(:inputs) { {} }
35
35
  let(:given) { {} }
36
- let(:client) { fake_client(:current_space => current_space, :service_instances => service_instances) }
36
+ let(:client) do
37
+ build(:client).tap do |client|
38
+ client.stub(:current_space => current_space, :service_instances => service_instances)
39
+ end
40
+ end
41
+ let(:app) { build(:app) }
37
42
 
38
- let(:service_plan) { fake(:service_plan, :service => fake(:service, :version => "service_version", :provider => "provider")) }
39
- let(:service1) { fake(:service_instance, :service_plan => service_plan) }
43
+ let(:service_plan) { build(:service_plan, :service => build(:service, :version => "service_version", :provider => "provider")) }
44
+ let(:service_binding) { build(:service_binding, :app => app) }
45
+ let(:service1) { build(:service_instance, :service_plan => service_plan, :service_bindings => [service_binding]) }
40
46
 
41
47
  let(:service_instances) { [service1] }
42
- let(:current_space) { fake(:space, :name => "the space") }
48
+ let(:current_space) { build(:space, :name => "the space") }
43
49
 
44
50
  subject do
45
51
  capture_output { Mothership.new.invoke(:services, inputs, given, global) }
46
52
  end
47
53
 
48
54
  before do
49
- CF::CLI.any_instance.stub(:client).and_return(client)
55
+ stub_client_and_precondition
56
+ client.stub(:service_bindings).and_return([service_binding])
50
57
  end
51
58
 
52
59
  it "produces a table of services" do
@@ -57,12 +64,12 @@ module CF
57
64
  expect(output).to match /Getting services in the space.*OK/
58
65
 
59
66
  expect(output).to match /name\s+service\s+provider\s+version\s+plan\s+bound apps/
60
- expect(output).to match /service_instance-.+?\s+ # name
67
+ expect(output).to match /service-instance-.+?\s+ # name
61
68
  service-.*?\s+ # service
62
69
  provider.*?\s+ # provider
63
70
  service_version\s+ # version
64
- service_plan-.*?\s+ # plan
65
- none\s+ # bound apps
71
+ service-plan-.*?\s+ # plan
72
+ app-name-\d+\s+ # bound apps
66
73
  /x
67
74
 
68
75
  end
@@ -3,6 +3,9 @@ require "spec_helper"
3
3
  module CF
4
4
  module Space
5
5
  describe Create do
6
+ let(:client) { build(:client) }
7
+ before { stub_client_and_precondition }
8
+
6
9
  describe "metadata" do
7
10
  let(:command) { Mothership.commands[:create_space] }
8
11
 
@@ -26,13 +29,8 @@ module CF
26
29
  end
27
30
 
28
31
  describe "running the command" do
29
- let(:new_space) { fake(:space, :name => new_name) }
30
- let(:new_name) { "some-new-name" }
31
-
32
- let(:spaces) { [new_space] }
33
- let(:organization) { fake(:organization, :spaces => spaces) }
34
-
35
- let(:client) { fake_client(:current_organization => organization, :spaces => spaces) }
32
+ let(:new_space) { build(:space) }
33
+ let(:organization) { build(:organization, :spaces => [new_space]) }
36
34
 
37
35
  before do
38
36
  client.stub(:space).and_return(new_space)
@@ -40,8 +38,6 @@ module CF
40
38
  new_space.stub(:add_manager)
41
39
  new_space.stub(:add_developer)
42
40
  new_space.stub(:add_auditor)
43
- described_class.any_instance.stub(:client).and_return(client)
44
- described_class.any_instance.stub(:precondition).and_return(nil)
45
41
  CF::Populators::Organization.any_instance.stub(:populate_and_save!).and_return(organization)
46
42
  CF::Populators::Organization.any_instance.stub(:choices).and_return([organization])
47
43
  end
@@ -3,6 +3,9 @@ require "spec_helper"
3
3
  module CF
4
4
  module Space
5
5
  describe Delete do
6
+ let(:client) { build(:client) }
7
+ before { stub_client_and_precondition }
8
+
6
9
  describe "metadata" do
7
10
  let(:command) { Mothership.commands[:delete_space] }
8
11
 
@@ -16,26 +19,24 @@ module CF
16
19
  end
17
20
 
18
21
  describe "running the command" do
19
- let(:space) { fake :space, :name => "some_space_name" }
20
- let(:organization) { fake(:organization, :spaces => [space], :name => "MyOrg") }
21
- let(:client) { fake_client(:current_organization => organization, :spaces => [space]) }
22
+ let(:space) { build :space, :name => "some_space_name" }
23
+ let(:organization) { build(:organization, :spaces => [space], :name => "MyOrg") }
22
24
 
23
25
  subject { capture_output { cf %W[delete-space some_space_name --quiet --force] } }
24
26
 
25
27
  before do
26
- described_class.any_instance.stub(:client) { client }
27
- described_class.any_instance.stub(:precondition)
28
28
  CF::Populators::Organization.any_instance.stub(:populate_and_save!).and_return(organization)
29
+ organization.stub(:spaces_by_name).with("some_space_name").and_return([space])
29
30
  space.stub(:delete!)
30
31
  end
31
32
 
32
-
33
33
  context "without the force parameter when prompting" do
34
34
  subject { cf %W[delete-space some_space_name --quiet] }
35
+
35
36
  context "when the user responds 'y'" do
36
37
  it "deletes the space, exits cleanly" do
37
38
  space.should_receive(:delete!)
38
- mock_ask("Really delete #{space.name}?", {:default => false}) { true }
39
+ should_ask("Really delete #{space.name}?", {:default => false}) { true }
39
40
 
40
41
  subject
41
42
  @status.should == 0
@@ -45,7 +46,7 @@ module CF
45
46
  context "when the user responds 'n'" do
46
47
  it "exits cleanly without deleting the space" do
47
48
  space.should_not_receive(:delete!)
48
- mock_ask("Really delete #{space.name}?", {:default => false}) { false }
49
+ should_ask("Really delete #{space.name}?", {:default => false}) { false }
49
50
 
50
51
  subject
51
52
  @status.should == 0
@@ -3,14 +3,13 @@ require "spec_helper"
3
3
  module CF
4
4
  module Space
5
5
  describe Rename do
6
- let(:spaces) { fake_list(:space, 3) }
7
- let(:organization) { fake(:organization, :spaces => spaces) }
8
- let(:client) { fake_client(:current_organization => organization, :spaces => spaces) }
6
+ let(:client) { build(:client) }
7
+ let(:spaces) { Array.new(3){ build(:space) } }
8
+ let(:organization) { build(:organization, :spaces => spaces) }
9
9
  let(:new_name) { "some-new-name" }
10
10
 
11
11
  before do
12
- described_class.any_instance.stub(:client) { client }
13
- described_class.any_instance.stub(:precondition)
12
+ stub_client_and_precondition
14
13
  CF::Populators::Organization.any_instance.stub(:populate_and_save!).and_return(organization)
15
14
  end
16
15
 
@@ -39,6 +38,10 @@ module CF
39
38
  context "when there are no spaces" do
40
39
  let(:spaces) { [] }
41
40
 
41
+ before do
42
+ client.stub(:spaces_by_name).with("some-invalid-space").and_return(spaces)
43
+ end
44
+
42
45
  context "and a space is given" do
43
46
  subject { cf %W[rename-space --space some-invalid-space --no-force --no-quiet] }
44
47
  it "prints out an error message" do
@@ -60,10 +63,14 @@ module CF
60
63
  let(:renamed_space) { spaces.first }
61
64
  subject { cf %W[rename-space --no-force --no-quiet] }
62
65
 
66
+ before do
67
+ client.stub(:spaces_by_name).with(renamed_space.name).and_return(spaces)
68
+ end
69
+
63
70
  context "when the defaults are used" do
64
71
  it "asks for the space and new name and renames" do
65
- mock_ask("Rename which space?", anything) { renamed_space }
66
- mock_ask("New name") { new_name }
72
+ should_ask("Rename which space?", anything) { renamed_space }
73
+ should_ask("New name") { new_name }
67
74
  renamed_space.should_receive(:name=).with(new_name)
68
75
  renamed_space.should_receive(:update!)
69
76
  subject
@@ -75,7 +82,7 @@ module CF
75
82
 
76
83
  it "asks for the new name and renames" do
77
84
  dont_allow_ask("Rename which space?", anything)
78
- mock_ask("New name") { new_name }
85
+ should_ask("New name") { new_name }
79
86
  renamed_space.should_receive(:name=).with(new_name)
80
87
  renamed_space.should_receive(:update!)
81
88
  subject
@@ -25,19 +25,19 @@ module CF
25
25
  end
26
26
 
27
27
  describe "running the command" do
28
- let(:apps) { fake_list(:app, 2) }
29
- let(:domains) { fake_list(:domain, 2) }
30
- let(:services) { fake_list(:service_instance, 2) }
31
- let!(:space_1) { fake(:space, :name => "some_space_name", :apps => apps, :service_instances => services, :domains => domains) }
32
- let(:spaces) { [space_1] }
33
- let(:organization) { fake(:organization, :name => "Spacey Org", :spaces => spaces) }
34
- let(:client) { fake_client(:spaces => spaces, :current_organization => organization) }
28
+ let(:client) { build(:client) }
29
+
30
+ let(:apps) { Array.new(2) { build(:app) } }
31
+ let(:domains) { Array.new(2) { build(:domain) } }
32
+ let(:services) { Array.new(2) { build(:service_instance) } }
33
+ let(:space) { build(:space, :name => "some_space_name", :apps => apps, :service_instances => services, :domains => domains, :organization => organization ) }
34
+ let(:spaces) { [space] }
35
+ let(:organization) { build(:organization, :name => "Spacey Org") }
35
36
 
36
37
  before do
37
- CF::Space::Base.any_instance.stub(:client) { client }
38
- CF::Space::Base.any_instance.stub(:precondition)
38
+ stub_client_and_precondition
39
39
  CF::Populators::Organization.any_instance.stub(:populate_and_save!).and_return(organization)
40
- CF::Populators::Space.any_instance.stub(:populate_and_save!).and_return(space_1)
40
+ CF::Populators::Space.any_instance.stub(:populate_and_save!).and_return(space)
41
41
  end
42
42
 
43
43
  context "with --quiet" do
@@ -4,16 +4,22 @@ module CF
4
4
  module Space
5
5
  describe Spaces do
6
6
  let(:full) { false }
7
- let!(:space_1) { fake(:space, :name => "bb_second", :apps => fake_list(:app, 2), :service_instances => [fake(:service_instance)]) }
8
- let!(:space_2) { fake(:space, :name => "aa_first", :apps => [fake(:app)], :service_instances => fake_list(:service_instance, 3), :domains => [fake(:domain)]) }
9
- let!(:space_3) { fake(:space, :name => "cc_last", :apps => fake_list(:app, 2), :service_instances => fake_list(:service_instance, 2), :domains => fake_list(:domain, 2)) }
7
+ let(:app) { build(:app) }
8
+ let!(:space_1) { build(:space, :name => "bb_second", :apps => [app], :service_instances => [build(:service_instance)]) }
9
+ let!(:space_2) { build(:space, :name => "aa_first", :apps => [app], :service_instances => [build(:service_instance)], :domains => [build(:domain)]) }
10
+ let!(:space_3) { build(:space, :name => "cc_last", :apps => [app], :service_instances => [build(:service_instance)], :domains => [build(:domain)]) }
10
11
  let(:spaces) { [space_1, space_2, space_3] }
11
- let(:organization) { fake(:organization, :spaces => spaces, :name => "foo") }
12
- let(:client) { fake_client(:spaces => spaces, :current_organization => organization) }
12
+ let(:organization) { build(:organization, :spaces => spaces, :name => "foo") }
13
+ let(:client) do
14
+ build(:client).tap do |client|
15
+ client.stub(:spaces => spaces, :current_organization => organization)
16
+ end
17
+ end
13
18
 
14
19
  before do
15
20
  stub_client_and_precondition
16
21
  CF::Populators::Organization.any_instance.stub(:populate_and_save!).and_return(organization)
22
+ organization.stub(:spaces).and_return(spaces)
17
23
  end
18
24
 
19
25
  describe "metadata" do
@@ -4,13 +4,12 @@ module CF
4
4
  module Space
5
5
  describe Switch do
6
6
  let(:space_to_switch_to) { spaces.last }
7
- let(:spaces) { fake_list(:space, 3) }
8
- let(:organization) { fake(:organization, :spaces => spaces) }
9
- let(:client) { fake_client(:current_organization => organization, :spaces => spaces) }
7
+ let(:spaces) { Array.new(3) { build(:space) } }
8
+ let(:organization) { build(:organization, :spaces => spaces) }
9
+ let(:client) { build(:client) }
10
10
 
11
11
  before do
12
- CF::Space::Base.any_instance.stub(:client) { client }
13
- CF::Space::Base.any_instance.stub(:precondition)
12
+ stub_client_and_precondition
14
13
  CF::Populators::Organization.any_instance.stub(:populate_and_save!).and_return(organization)
15
14
  end
16
15
 
@@ -38,6 +37,7 @@ module CF
38
37
  context "when the space exists" do
39
38
  before do
40
39
  Mothership.any_instance.should_receive(:invoke).with(:target, {:space => space_to_switch_to})
40
+ client.stub(:spaces_by_name).with(space_to_switch_to.name).and_return([space_to_switch_to])
41
41
  end
42
42
 
43
43
  it "switches to that space" do
@@ -46,11 +46,11 @@ module CF
46
46
  end
47
47
 
48
48
  context "when the space does not exist" do
49
- let(:space_to_switch_to) { fake(:space, :name => "unique-name") }
49
+ before { client.stub(:spaces_by_name).with(space_to_switch_to.name).and_return([]) }
50
50
 
51
51
  it_behaves_like "an error that gets passed through",
52
52
  :with_exception => CF::UserError,
53
- :with_message => "The space unique-name does not exist, please create the space first."
53
+ :with_message => /The space .* does not exist, please create the space first/
54
54
  end
55
55
  end
56
56
  end