spec/vmc/cli_spec.rb in vmc-0.5.0.rc1 vs spec/vmc/cli_spec.rb in vmc-0.5.0.rc2
- old
+ new
@@ -1,55 +1,21 @@
require 'spec_helper'
-class NoWrapErrorsDummy < VMC::CLI
- def wrap_errors
- yield
- end
-end
-
describe VMC::CLI do
- let(:context) { NoWrapErrorsDummy.new }
+ let(:context) { VMC::CLI.new }
let(:command) { nil }
describe "#wrap_errors" do
- let(:context) { VMC::CLI.new }
let(:inputs) { {} }
subject do
capture_output do
stub(context).input { inputs }
context.wrap_errors { action.call }
end
end
- shared_examples_for "an error that's obvious to the user" do |options|
- message = options[:with_message]
-
- it "prints the message" do
- subject
- expect(stderr.string).to include message
- end
-
- it "sets the exit code to 1" do
- mock(context).exit_status(1)
- subject
- end
-
- it "does not mention ~/.vmc/crash" do
- subject
- expect(stderr.string).to_not include VMC::CRASH_FILE
- end
- end
-
- shared_examples_for "an error that gets passed through" do |options|
- exception = options[:with_exception]
-
- it "reraises the error" do
- expect { subject }.to raise_error(exception)
- end
- end
-
context "with a CFoundry::Timeout" do
let(:action) { proc { raise CFoundry::Timeout.new(123, "fizzbuzz") } }
it_behaves_like "an error that's obvious to the user",
:with_message => "fizzbuzz"
@@ -175,11 +141,11 @@
let(:context) { TokenRefreshDummy.new }
let(:command) { Mothership.commands[:refresh_token] }
let(:auth_token) { CFoundry::AuthToken.new("old-header") }
let(:new_auth_token) { CFoundry::AuthToken.new("new-header") }
- class TokenRefreshDummy < NoWrapErrorsDummy
+ class TokenRefreshDummy < VMC::CLI
class << self
attr_accessor :new_token
end
def precondition; end
@@ -439,9 +405,45 @@
context "when there is no target" do
use_fake_home_dir { "#{SPEC_ROOT}/fixtures/fake_home_dirs/no_config" }
it "returns nil" do
expect(context.client).to eq(nil)
+ end
+ end
+
+ context "with a v1 cloud controller" do
+ before do
+ stub(context).target_info { { :version => 1} }
+ end
+
+ it "connects using the v1 api" do
+ expect(context.client).to be_a(CFoundry::V1::Client)
+ end
+
+ context "with a proxy user" do
+ before { stub(context).input { {:proxy => 'foo@example.com'} } }
+
+ it "uses the provided client proxy user" do
+ expect(context.client.proxy).to eq('foo@example.com')
+ end
+ end
+ end
+
+ context "with a v2 cloud controller" do
+ before do
+ stub(context).target_info { { :version => 2} }
+ end
+
+ it "connects using the v2 api" do
+ expect(context.client).to be_a(CFoundry::V2::Client)
+ end
+
+ context "with a proxy user" do
+ before { stub(context).input { {:proxy => 'foo@example.com'} } }
+
+ it "foo" do
+ expect {context.client}.to raise_error(VMC::UserError, "User switching not implemented for v2.")
+ end
end
end
end
end