spec/cf/cli/space/create_spec.rb in cf-5.0.0.rc3 vs spec/cf/cli/space/create_spec.rb in cf-5.0.0.rc4
- old
+ new
@@ -19,45 +19,124 @@
describe "arguments" do
subject { command.arguments }
it "has the correct argument order" do
should eq([
- {:type => :optional, :value => nil, :name => :name},
- {:type => :optional, :value => nil, :name => :organization}
+ {type: :optional, value: nil, name: :name},
+ {type: :optional, value: nil, name: :organization}
])
end
end
end
describe "running the command" do
let(:new_space) { build(:space) }
- let(:organization) { build(:organization, :spaces => [new_space]) }
before do
- client.stub(:space).and_return(new_space)
- new_space.stub(:create!)
- new_space.stub(:add_manager)
- new_space.stub(:add_developer)
- new_space.stub(:add_auditor)
- CF::Populators::Organization.any_instance.stub(:populate_and_save!).and_return(organization)
- CF::Populators::Organization.any_instance.stub(:choices).and_return([organization])
+ client.stub(space: new_space)
+ CF::Populators::Organization.any_instance.stub(populate_and_save!: organization)
+
+ @command_args = ["create-space", new_space.name]
end
- context "when --target is given" do
- subject { cf %W[create-space #{new_space.name} --target] }
+ context "when the space already exists" do
+ let(:existing_space) { build(:space, name: new_space.name) }
+ let(:organization) { build(:organization, spaces: [existing_space]) }
+ let(:current_user) { build(:user) }
- it "switches them to the new space" do
- mock_invoke :target, :organization => organization, :space => new_space
- subject
+ before do
+ client.stub(current_user: current_user)
+ new_space.stub(:create!).and_raise(CFoundry::SpaceNameTaken)
end
+
+ context "when --find-if-exists is given" do
+ before do
+ @command_args << "--find-if-exists"
+ client.stub(:space_by_name).with(new_space.name).and_return(existing_space)
+ existing_space.stub(:add_manager).with(current_user)
+ existing_space.stub(:add_developer).with(current_user)
+ end
+
+ context "when --target is given" do
+ before { @command_args << "--target" }
+
+ it "switches them to the existing space" do
+ mock_invoke :target, organization: organization, space: existing_space
+ cf @command_args
+ end
+ end
+
+ context "when --target is NOT given" do
+ it "tells the user how they can switch to the existing space" do
+ cf @command_args
+ expect(output).to say("Space already exists!\n\ncf switch-space #{existing_space.name} # targets existing space")
+ end
+ end
+ end
+
+ context "when --find-if-exists is NOT given" do
+ before { @command_args << "--target" }
+
+ context "when --target is given" do
+ it "raises an exception" do
+ expect { cf @command_args }.to raise_error(CFoundry::SpaceNameTaken)
+ end
+ end
+
+ context "when --target is NOT given" do
+ it "raises an exception" do
+ expect { cf @command_args }.to raise_error(CFoundry::SpaceNameTaken)
+ end
+ end
+ end
end
- context "when --target is NOT given" do
- subject { cf %W[create-space #{new_space.name}] }
+ context "when the space DOES NOT already exist" do
+ let(:organization) { build(:organization, spaces: []) }
- it "tells the user how they can switch to the new space" do
- subject
- expect(output).to say("Space created!\n\ncf switch-space #{new_space.name} # targets new space")
+ before do
+ new_space.stub(:create!)
+ new_space.stub(:add_manager)
+ new_space.stub(:add_developer)
+ new_space.stub(:add_auditor)
+ end
+
+ context "when --find-if-exists is given" do
+ before { @command_args << "--find-if-exists" }
+
+ context "when --target is given" do
+ before { @command_args << "--target" }
+
+ it "switches them to the new space" do
+ mock_invoke :target, organization: organization, space: new_space
+ cf @command_args
+ end
+ end
+
+ context "when --target is NOT given" do
+ it "tells the user how they can switch to the new space" do
+ cf @command_args
+ expect(output).to say("Space created!\n\ncf switch-space #{new_space.name} # targets new space")
+ end
+ end
+ end
+
+ context "when --find-if-exists is NOT given" do
+ context "when --target is given" do
+ before { @command_args << "--target" }
+
+ it "switches them to the new space" do
+ mock_invoke :target, organization: organization, space: new_space
+ cf @command_args
+ end
+ end
+
+ context "when --target is NOT given" do
+ it "tells the user how they can switch to the new space" do
+ cf @command_args
+ expect(output).to say("Space created!\n\ncf switch-space #{new_space.name} # targets new space")
+ end
+ end
end
end
end
end
end