Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
begin conversion to new vmc invocation format in specs
Browse files Browse the repository at this point in the history
We changed this to reflect what the user types in the commandline rather than some implementation detail of mothership

Change-Id: Iba2d5289d623e3854ce9c0be8f8ec8d1ecfd92eb
  • Loading branch information
Max Brunsfeld and Tim Labeeuw committed Jan 18, 2013
1 parent 3120502 commit 26658e4
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 67 deletions.
7 changes: 1 addition & 6 deletions lib/vmc/cli.rb
Expand Up @@ -224,12 +224,7 @@ def user_colors
end

def err(msg, status = 1)
if quiet?
$stderr.puts(msg)
else
puts c(msg, :error)
end

$stderr.puts c(msg, :error)
exit_status status
end

Expand Down
29 changes: 17 additions & 12 deletions spec/vmc/cli/space/rename_spec.rb
Expand Up @@ -2,23 +2,18 @@
require "vmc/cli/space/rename"

describe VMC::Space::Rename do
let(:global) { { :color => false, :quiet => true } }
let(:inputs) { {} }
let(:given) { {} }
let(:spaces) { fake_list(:space, 3) }
let(:organization) { fake(:organization, :spaces => spaces) }
let(:client) { fake_client(:current_organization => organization, :spaces => spaces) }
let(:new_name) { "some-new-name" }

before do
any_instance_of(VMC::CLI) do |cli|
any_instance_of described_class do |cli|
stub(cli).client { client }
stub(cli).precondition { nil }
end
end

subject { Mothership.new.invoke(:rename_space, inputs, given, global) }

describe 'metadata' do
let(:command) { Mothership.commands[:rename_space] }

Expand All @@ -45,19 +40,28 @@
let(:spaces) { [] }

context 'and a space is given' do
let(:given) { { :space => "some-invalid-space" } }
it { expect { subject }.to raise_error(VMC::UserError, "Unknown space 'some-invalid-space'.") }
subject { vmc %W[rename-space --space some-invalid-space --no-force --no-quiet] }
it 'prints out an error message' do
subject
expect(stderr.string).to include "Unknown space 'some-invalid-space'."
end
end

context 'and a space is not given' do
it { expect { subject }.to raise_error(VMC::UserError, "No spaces.") }
subject { vmc %W[rename-space --no-force] }
it 'prints out an error message' do
subject
expect(stderr.string).to include "No spaces."
end
end
end

context 'when there are spaces' do
let(:renamed_space) { spaces.first }

context 'when the defaults are used' do
subject { vmc %W[rename-space --no-force --no-quiet] }

it 'asks for the space and new name and renames' do
mock_ask("Rename which space?", anything) { renamed_space }
mock_ask("New name") { new_name }
Expand All @@ -68,7 +72,7 @@
end

context 'when no name is provided, but a space is' do
let(:given) { { :space => renamed_space.name } }
subject { vmc %W[rename-space --space #{renamed_space.name} --no-force] }

it 'asks for the new name and renames' do
dont_allow_ask("Rename which space?", anything)
Expand All @@ -80,7 +84,7 @@
end

context 'when a space is provided and a name' do
let(:inputs) { { :space => renamed_space, :name => new_name } }
subject { vmc %W[rename-space --space #{renamed_space.name} --name #{new_name} --no-force] }

it 'renames the space' do
mock(renamed_space).update!
Expand All @@ -97,7 +101,8 @@
context 'and the name already exists' do
it 'fails' do
mock(renamed_space).update! { raise CFoundry::SpaceNameTaken.new("Taken", 404) }
expect { subject }.to raise_error(CFoundry::SpaceNameTaken)
subject
expect(stderr.string).to include "404: Taken"
end
end
end
Expand Down
17 changes: 6 additions & 11 deletions spec/vmc/cli/space/spaces_spec.rb
Expand Up @@ -2,10 +2,7 @@
require 'stringio'

describe VMC::Space::Spaces do
let(:global) { { :color => false } }
let(:inputs) { {} }
let(:given) { {} }
let(:output) { StringIO.new }
let(:full) { false }
let!(:space_1) { fake(:space, :name => "bb_second", :apps => fake_list(:app, 2), :service_instances => [fake(:service_instance)]) }
let!(:space_2) { fake(:space, :name => "aa_first", :apps => [fake(:app)], :service_instances => fake_list(:service_instance, 3), :domains => [fake(:domain)]) }
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)) }
Expand All @@ -14,16 +11,12 @@
let(:client) { fake_client(:spaces => spaces, :current_organization => organization) }

before do
any_instance_of(VMC::CLI) do |cli|
any_instance_of described_class do |cli|
stub(cli).client { client }
stub(cli).precondition { nil }
end
end

subject do
capture_output { Mothership.new.invoke(:spaces, inputs, given, global) }
end

describe 'metadata' do
let(:command) { Mothership.commands[:spaces] }

Expand All @@ -43,6 +36,8 @@
end
end

subject { vmc %W[spaces --#{bool_flag(:full)} --no-quiet] }

it 'should have the correct first two lines' do
subject

Expand All @@ -55,7 +50,7 @@
let(:spaces) { [] }

context 'and the full flag is given' do
let(:inputs) { {:full => true} }
let(:full) { true }

it 'displays yaml-style output with all space details' do
any_instance_of VMC::Space::Spaces do |spaces|
Expand All @@ -78,7 +73,7 @@

context 'when there are spaces' do
context 'and the full flag is given' do
let(:inputs) { {:full => true} }
let(:full) { true }

it 'displays yaml-style output with all space details' do
any_instance_of VMC::Space::Spaces do |spaces|
Expand Down
34 changes: 17 additions & 17 deletions spec/vmc/cli/start/info_spec.rb
@@ -1,33 +1,30 @@
require 'spec_helper'

describe VMC::Start::Info do
let(:global) { { :color => false } }
let(:inputs) { {} }
let(:given) { {} }
let(:frameworks) { false }
let(:runtimes) { false }
let(:services) { false }
let(:all) { false }

let(:client) {
let(:client) do
fake_client :frameworks => fake_list(:framework, 3),
:runtimes => fake_list(:runtime, 3),
:services => fake_list(:service, 3)
}
end

let(:target_info) {
{ :description => "Some description",
let(:target_info) do
{:description => "Some description",
:version => 2,
:support => "http://example.com"
}
}
end

before do
any_instance_of(VMC::CLI) do |cli|
any_instance_of described_class do |cli|
stub(cli).client { client }
end
end

subject do
capture_output { Mothership.new.invoke(:info, inputs, given, global) }
end

describe 'metadata' do
let(:command) { Mothership.commands[:info] }

Expand All @@ -54,6 +51,9 @@
end
end


subject { vmc %W[info --#{bool_flag(:frameworks)} --#{bool_flag(:runtimes)} --#{bool_flag(:services)} --#{bool_flag(:all)} --no-force --no-quiet] }

context 'when given no flags' do
it "displays target information" do
mock(client).info { target_info }
Expand All @@ -70,7 +70,7 @@
end

context 'when given --frameworks' do
let(:inputs) { { :frameworks => true } }
let(:frameworks) { true }

it 'does not grab /info' do
dont_allow(client).info
Expand All @@ -92,7 +92,7 @@
end

context 'when given --runtimes' do
let(:inputs) { { :runtimes => true } }
let(:runtimes) { true }

it 'does not grab /info' do
dont_allow(client).info
Expand All @@ -114,7 +114,7 @@
end

context 'when given --services' do
let(:inputs) { { :services => true } }
let(:services) { true }

it 'does not grab /info' do
dont_allow(client).info
Expand All @@ -136,7 +136,7 @@
end

context 'when given --all' do
let(:inputs) { { :all => true } }
let(:all) { true }

it 'combines --frameworks --runtimes and --services' do
mock(client).info { target_info }
Expand Down
15 changes: 4 additions & 11 deletions spec/vmc/cli/user/create_spec.rb
Expand Up @@ -4,21 +4,14 @@
let(:client) { fake_client }

before do
any_instance_of(VMC::CLI) do |cli|
stub(cli).client { client }
end
stub(VMC::CLI).exit { |code| code }
any_instance_of(described_class) { |cli| stub(cli).client { client } }
stub(client).register
end

subject do
capture_output do
VMC::CLI.start %W(create-user --force #{force})
end
end
subject { vmc %W[create-user --#{bool_flag(:force)}] }

context "when the user is not logged in" do
let(:force) { "true" }
let(:force) { true }

before do
stub(client).logged_in? { false }
Expand All @@ -31,7 +24,7 @@
end

context "when the user is logged in" do
let(:force) { "false" }
let(:force) { false }

before do
stub(client).logged_in? { true }
Expand Down
12 changes: 3 additions & 9 deletions spec/vmc/cli/user/passwd_spec.rb
Expand Up @@ -26,29 +26,23 @@
let(:new_password) { "password" }
let(:verify_password) { new_password }
let(:score) { :strong }

let(:guid) { random_string("my-object-guid") }
let(:user_model) { fake_model { attribute :password, :object } }
let(:user_object) { user_model.new(guid, client) }
let(:user) { user_object.fake(:password => 'foo') }

before do
stub(client).logged_in? { true }
stub(VMC::CLI).exit { |code| code }
any_instance_of(VMC::CLI) do |cli|
any_instance_of described_class do |cli|
stub(cli).client { client }
stub(cli).precondition { nil }
end
stub(client).logged_in? { true }
stub(client).current_user { user }
stub(client).register
stub(client).base.stub!.uaa.stub!.password_score(new_password) { score }
end

subject do
capture_output do
VMC::CLI.start %W(passwd --password #{old_password} --new-password #{new_password} --verify #{verify_password} --no-force --debug)
end
end
subject { vmc %W[passwd --password #{old_password} --new-password #{new_password} --verify #{verify_password} --no-force --debug] }

context 'when the passwords dont match' do
let(:verify_password) { "other_password" }
Expand Down
2 changes: 1 addition & 1 deletion spec/vmc/cli/user/register_spec.rb
Expand Up @@ -32,7 +32,7 @@
let(:score) { :strong }

before do
any_instance_of(VMC::CLI) do |cli|
any_instance_of described_class do |cli|
stub(cli).client { client }
stub(cli).precondition { nil }
end
Expand Down

0 comments on commit 26658e4

Please sign in to comment.