spec/vmc/cli/start/info_spec.rb in vmc-0.5.0.beta.7 vs spec/vmc/cli/start/info_spec.rb in vmc-0.5.0.beta.10

- old
+ new

@@ -1,38 +1,33 @@ require 'spec_helper' describe VMC::Start::Info do - let(:global) { { :color => false } } - let(:inputs) { {} } - let(:given) { {} } - let(:output) { StringIO.new } + 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) - } + :services => fake_list(:service, 3), + :token => CFoundry::AuthToken.new("bearer some-access-token") + 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 - with_output_to output do - Mothership.new.invoke(:info, inputs, given, global) - end - end - describe 'metadata' do let(:command) { Mothership.commands[:info] } describe 'command' do subject { command } @@ -55,101 +50,104 @@ subject { command.arguments } it { should be_empty } 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 } subject - output.rewind - expect(output.readline).to eq "Some description\n" - expect(output.readline).to eq "\n" - expect(output.readline).to eq "target: #{client.target}\n" - expect(output.readline).to eq " version: 2\n" - expect(output.readline).to eq " support: http://example.com\n" + stdout.rewind + expect(stdout.readline).to eq "Some description\n" + expect(stdout.readline).to eq "\n" + expect(stdout.readline).to eq "target: #{client.target}\n" + expect(stdout.readline).to eq " version: 2\n" + expect(stdout.readline).to eq " support: http://example.com\n" end end context 'when given --frameworks' do - let(:inputs) { { :frameworks => true } } + let(:frameworks) { true } it 'does not grab /info' do dont_allow(client).info subject end it 'lists frameworks on the target' do subject - output.rewind - expect(output.readline).to match /Getting frameworks.*OK/ - expect(output.readline).to eq "\n" - expect(output.readline).to match /framework\s+description/ + stdout.rewind + expect(stdout.readline).to match /Getting frameworks.*OK/ + expect(stdout.readline).to eq "\n" + expect(stdout.readline).to match /framework\s+description/ client.frameworks.sort_by(&:name).each do |f| - expect(output.readline).to match /#{f.name}\s+#{f.description}/ + expect(stdout.readline).to match /#{f.name}\s+#{f.description}/ end end end context 'when given --runtimes' do - let(:inputs) { { :runtimes => true } } + let(:runtimes) { true } it 'does not grab /info' do dont_allow(client).info subject end it 'lists runtimes on the target' do subject - output.rewind - expect(output.readline).to match /Getting runtimes.*OK/ - expect(output.readline).to eq "\n" - expect(output.readline).to match /runtime\s+description/ + stdout.rewind + expect(stdout.readline).to match /Getting runtimes.*OK/ + expect(stdout.readline).to eq "\n" + expect(stdout.readline).to match /runtime\s+description/ client.runtimes.sort_by(&:name).each do |r| - expect(output.readline).to match /#{r.name}\s+#{r.description}/ + expect(stdout.readline).to match /#{r.name}\s+#{r.description}/ end end end context 'when given --services' do - let(:inputs) { { :services => true } } + let(:services) { true } it 'does not grab /info' do dont_allow(client).info subject end it 'lists services on the target' do subject - output.rewind - expect(output.readline).to match /Getting services.*OK/ - expect(output.readline).to eq "\n" - expect(output.readline).to match /service\s+version\s+provider\s+plans\s+description/ + stdout.rewind + expect(stdout.readline).to match /Getting services.*OK/ + expect(stdout.readline).to eq "\n" + expect(stdout.readline).to match /service\s+version\s+provider\s+plans\s+description/ client.services.sort_by(&:label).each do |s| - expect(output.readline).to match /#{s.label}\s+#{s.version}\s+#{s.provider}.+#{s.description}/ + expect(stdout.readline).to match /#{s.label}\s+#{s.version}\s+#{s.provider}.+#{s.description}/ end end 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 } subject - output.rewind - expect(output.readline).to match /Getting runtimes.*OK/ - expect(output.readline).to match /Getting frameworks.*OK/ - expect(output.readline).to match /Getting services.*OK/ + stdout.rewind + expect(stdout.readline).to match /Getting runtimes.*OK/ + expect(stdout.readline).to match /Getting frameworks.*OK/ + expect(stdout.readline).to match /Getting services.*OK/ end end end