require "vagrant-skytap/config" describe VagrantPlugins::Skytap::Config do let(:instance) { described_class.new } # Ensure tests are not affected by Skytap credential environment variables before :each do ENV.stub(:[] => nil) end describe "defaults" do subject do instance.tap do |o| o.finalize! end end its("username") { should be_nil } its("api_token") { should be_nil } its("base_url") { should == "https://cloud.skytap.com/" } its("vm_url") { should be_nil } its("vpn_url") { should be_nil } its("instance_ready_timeout") { should == 120 } its("cpus") { should be_nil } its("cpuspersocket") { should be_nil } its("ram") { should be_nil } its("guestos") { should be_nil } end describe "overriding defaults" do # I typically don't meta-program in tests, but this is a very # simple boilerplate test, so I cut corners here. It just sets # each of these attributes to "foo" in isolation, and reads the value # and asserts the proper result comes back out. [:username, :api_token, :base_url, :vm_url, :vpn_url, :instance_ready_timeout, :cpus, :cpuspersocket, :ram, :guestos].each do |attribute| it "should not default #{attribute} if overridden" do instance.send("#{attribute}=".to_sym, "foo") instance.finalize! instance.send(attribute).should == "foo" end end end describe "getting credentials from environment" do context "without Skytap credential environment variables" do subject do instance.tap do |o| o.finalize! end end its("username") { should be_nil } its("api_token") { should be_nil } end context "with Skytap credential environment variables" do before :each do ENV.stub(:[]).with("VAGRANT_SKYTAP_USERNAME").and_return("username") ENV.stub(:[]).with("VAGRANT_SKYTAP_API_TOKEN").and_return("api_token") end subject do instance.tap do |o| o.finalize! end end its("username") { should == "username" } its("api_token") { should == "api_token" } end end end