spec/vmc/cli_spec.rb in vmc-0.5.0.rc4 vs spec/vmc/cli_spec.rb in vmc-0.5.0

- old
+ new

@@ -2,10 +2,13 @@ describe VMC::CLI do let(:context) { VMC::CLI.new } let(:command) { nil } + let(:fake_home_dir) { nil } + stub_home_dir_with { fake_home_dir } + describe "#wrap_errors" do let(:inputs) { {} } subject do capture_output do @@ -248,27 +251,27 @@ describe "#client_target" do subject { context.client_target } context "when a ~/.vmc/target exists" do - use_fake_home_dir { "#{SPEC_ROOT}/fixtures/fake_home_dirs/new" } + let(:fake_home_dir) { "#{SPEC_ROOT}/fixtures/fake_home_dirs/new" } it "returns the target in that file" do expect(subject).to eq "https://api.some-domain.com" end end context "when a ~/.vmc_target exists" do - use_fake_home_dir { "#{SPEC_ROOT}/fixtures/fake_home_dirs/old" } + let(:fake_home_dir) { "#{SPEC_ROOT}/fixtures/fake_home_dirs/old" } it "returns the target in that file" do expect(subject).to eq "https://api.some-domain.com" end end context "when no target file exists" do - use_fake_home_dir { "#{SPEC_ROOT}/fixtures/fake_home_dirs/no_config" } + let(:fake_home_dir) { "#{SPEC_ROOT}/fixtures/fake_home_dirs/no_config" } it "returns nil" do expect(subject).to eq nil end end @@ -276,11 +279,11 @@ describe "#targets_info" do subject { context.targets_info } context "when a ~/.vmc/tokens.yml exists" do - use_fake_home_dir { "#{SPEC_ROOT}/fixtures/fake_home_dirs/new" } + let(:fake_home_dir) { "#{SPEC_ROOT}/fixtures/fake_home_dirs/new" } it "returns the file's contents as a hash" do expect(subject).to eq({ "https://api.some-domain.com" => { :token => "bearer some-token", @@ -289,11 +292,11 @@ }) end end context "when a ~/.vmc_token file exists" do - use_fake_home_dir { "#{SPEC_ROOT}/fixtures/fake_home_dirs/old" } + let(:fake_home_dir) { "#{SPEC_ROOT}/fixtures/fake_home_dirs/old" } it "returns the target in that file" do expect(subject).to eq({ "https://api.some-domain.com" => { :token => "bearer some-token" @@ -301,11 +304,11 @@ }) end end context "when no token file exists" do - use_fake_home_dir { "#{SPEC_ROOT}/fixtures/fake_home_dirs/no_config" } + let(:fake_home_dir) { "#{SPEC_ROOT}/fixtures/fake_home_dirs/no_config" } it "returns an empty hash" do expect(subject).to eq({}) end end @@ -313,54 +316,49 @@ describe "#target_info" do subject { VMC::CLI.new.target_info("https://api.some-domain.com") } context "when a ~/.vmc/tokens.yml exists" do - use_fake_home_dir { "#{SPEC_ROOT}/fixtures/fake_home_dirs/new" } + let(:fake_home_dir) { "#{SPEC_ROOT}/fixtures/fake_home_dirs/new" } it "returns the info for the given url" do expect(subject).to eq({ :token => "bearer some-token", :version => 2 }) end end context "when a ~/.vmc_token file exists" do - use_fake_home_dir { "#{SPEC_ROOT}/fixtures/fake_home_dirs/old" } + let(:fake_home_dir) { "#{SPEC_ROOT}/fixtures/fake_home_dirs/old" } it "returns the info for the given url" do expect(subject).to eq({ :token => "bearer some-token" }) end end context "when no token file exists" do - use_fake_home_dir { "#{SPEC_ROOT}/fixtures/fake_home_dirs/no_config" } + let(:fake_home_dir) { "#{SPEC_ROOT}/fixtures/fake_home_dirs/no_config" } it "returns an empty hash" do expect(subject).to eq({}) end end end describe "methods that update the token info" do - let!(:tmpdir) { Dir.mktmpdir } - use_fake_home_dir { tmpdir } - before do stub(context).targets_info do { "https://api.some-domain.com" => { :token => "bearer token1" }, "https://api.some-other-domain.com" => { :token => "bearer token2" } } end end - after { FileUtils.rm_rf tmpdir } - describe "#save_target_info" do it "adds the given target info, and writes the result to ~/.vmc/tokens.yml" do context.save_target_info({ :token => "bearer token3" }, "https://api.some-domain.com") YAML.load_file(File.expand_path("~/.vmc/tokens.yml")).should == { "https://api.some-domain.com" => { :token => "bearer token3" }, @@ -378,11 +376,12 @@ end end end describe "#client" do - use_fake_home_dir { "#{SPEC_ROOT}/fixtures/fake_home_dirs/new" } + let(:fake_home_dir) { "#{SPEC_ROOT}/fixtures/fake_home_dirs/new" } + before { stub(context).input { {} } } describe "the client's token" do it "constructs an AuthToken object with the data from the tokens.yml file" do expect(context.client.token).to be_a(CFoundry::AuthToken) @@ -395,16 +394,15 @@ end end describe "the client's version" do it "uses the version stored in the yml file" do - expect(context.client.version).to eq(2) end end context "when there is no target" do - use_fake_home_dir { "#{SPEC_ROOT}/fixtures/fake_home_dirs/no_config" } + let(:fake_home_dir) { "#{SPEC_ROOT}/fixtures/fake_home_dirs/no_config" } it "returns nil" do expect(context.client).to eq(nil) end end