2011-12-15 06:43:45 +00:00
|
|
|
require File.expand_path("../base", __FILE__)
|
|
|
|
|
|
|
|
describe Vagrant do
|
2013-02-22 23:10:34 +00:00
|
|
|
include_context "unit"
|
|
|
|
|
2011-12-15 06:43:45 +00:00
|
|
|
it "has the path to the source root" do
|
2014-03-14 15:02:07 +00:00
|
|
|
expect(described_class.source_root).to eq(Pathname.new(File.expand_path("../../../", __FILE__)))
|
2011-12-15 06:43:45 +00:00
|
|
|
end
|
|
|
|
|
2012-04-15 20:34:44 +00:00
|
|
|
describe "plugin superclass" do
|
2012-06-26 22:47:26 +00:00
|
|
|
describe "v1" do
|
|
|
|
it "returns the proper class for version 1" do
|
2014-03-14 15:02:07 +00:00
|
|
|
expect(described_class.plugin("1")).to eq(Vagrant::Plugin::V1::Plugin)
|
2012-06-26 22:47:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the proper components for version 1" do
|
2014-03-14 15:02:07 +00:00
|
|
|
expect(described_class.plugin("1", :command)).to eq(Vagrant::Plugin::V1::Command)
|
|
|
|
expect(described_class.plugin("1", :communicator)).to eq(Vagrant::Plugin::V1::Communicator)
|
|
|
|
expect(described_class.plugin("1", :config)).to eq(Vagrant::Plugin::V1::Config)
|
|
|
|
expect(described_class.plugin("1", :guest)).to eq(Vagrant::Plugin::V1::Guest)
|
|
|
|
expect(described_class.plugin("1", :host)).to eq(Vagrant::Plugin::V1::Host)
|
|
|
|
expect(described_class.plugin("1", :provider)).to eq(Vagrant::Plugin::V1::Provider)
|
|
|
|
expect(described_class.plugin("1", :provisioner)).to eq(Vagrant::Plugin::V1::Provisioner)
|
2012-06-26 22:47:26 +00:00
|
|
|
end
|
2012-04-15 20:34:44 +00:00
|
|
|
end
|
|
|
|
|
2013-11-22 01:38:17 +00:00
|
|
|
describe "v2" do
|
|
|
|
it "returns the proper class for version 2" do
|
2014-03-14 15:02:07 +00:00
|
|
|
expect(described_class.plugin("2")).to eq(Vagrant::Plugin::V2::Plugin)
|
2013-11-22 01:38:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the proper components for version 2" do
|
2014-03-14 15:02:07 +00:00
|
|
|
expect(described_class.plugin("2", :command)).to eq(Vagrant::Plugin::V2::Command)
|
|
|
|
expect(described_class.plugin("2", :communicator)).to eq(Vagrant::Plugin::V2::Communicator)
|
|
|
|
expect(described_class.plugin("2", :config)).to eq(Vagrant::Plugin::V2::Config)
|
|
|
|
expect(described_class.plugin("2", :guest)).to eq(Vagrant::Plugin::V2::Guest)
|
|
|
|
expect(described_class.plugin("2", :host)).to eq(Vagrant::Plugin::V2::Host)
|
|
|
|
expect(described_class.plugin("2", :provider)).to eq(Vagrant::Plugin::V2::Provider)
|
|
|
|
expect(described_class.plugin("2", :provisioner)).to eq(Vagrant::Plugin::V2::Provisioner)
|
|
|
|
expect(described_class.plugin("2", :synced_folder)).to eq(Vagrant::Plugin::V2::SyncedFolder)
|
2013-11-22 01:38:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-04-15 20:34:44 +00:00
|
|
|
it "raises an exception if an unsupported version is given" do
|
|
|
|
expect { described_class.plugin("88") }.
|
|
|
|
to raise_error(ArgumentError)
|
|
|
|
end
|
|
|
|
end
|
2012-05-06 21:01:10 +00:00
|
|
|
|
2013-09-11 19:58:21 +00:00
|
|
|
describe "has_plugin?" do
|
|
|
|
after(:each) do
|
2013-12-18 02:20:10 +00:00
|
|
|
manager.reset!
|
2013-09-11 19:58:21 +00:00
|
|
|
end
|
|
|
|
|
2014-01-08 18:50:28 +00:00
|
|
|
let(:manager) { described_class.plugin("2").manager }
|
2013-09-11 19:58:21 +00:00
|
|
|
|
2013-12-18 02:20:10 +00:00
|
|
|
it "should find the installed plugin by the registered name" do
|
2014-01-08 18:50:28 +00:00
|
|
|
Class.new(described_class.plugin(Vagrant::Config::CURRENT_VERSION)) do
|
|
|
|
name "i_am_installed"
|
|
|
|
end
|
|
|
|
|
2013-12-18 02:20:10 +00:00
|
|
|
expect(described_class.has_plugin?("i_am_installed")).to be_true
|
2013-09-11 19:58:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return false if the plugin is not installed" do
|
2013-12-18 02:20:10 +00:00
|
|
|
expect(described_class.has_plugin?("i_dont_exist")).to be_false
|
2013-09-11 19:58:21 +00:00
|
|
|
end
|
2014-01-08 18:50:28 +00:00
|
|
|
|
|
|
|
it "finds plugins by gem name" do
|
|
|
|
specs = [Gem::Specification.new]
|
|
|
|
specs[0].name = "foo"
|
2014-05-22 16:35:12 +00:00
|
|
|
Vagrant::Plugin::Manager.instance.stub(installed_specs: specs)
|
2014-01-08 18:50:28 +00:00
|
|
|
|
|
|
|
expect(described_class.has_plugin?("foo")).to be_true
|
|
|
|
expect(described_class.has_plugin?("bar")).to be_false
|
|
|
|
end
|
2014-10-23 17:52:02 +00:00
|
|
|
|
|
|
|
it "finds plugins by gem version" do
|
|
|
|
specs = [Gem::Specification.new]
|
|
|
|
specs[0].name = "foo"
|
|
|
|
specs[0].version = "1.2.3"
|
|
|
|
Vagrant::Plugin::Manager.instance.stub(installed_specs: specs)
|
|
|
|
|
|
|
|
expect(described_class.has_plugin?("foo", "~> 1.2.0")).to be_true
|
|
|
|
expect(described_class.has_plugin?("foo", "~> 1.0.0")).to be_false
|
|
|
|
end
|
2013-09-11 19:58:21 +00:00
|
|
|
end
|
2013-11-23 20:23:34 +00:00
|
|
|
|
|
|
|
describe "require_version" do
|
|
|
|
it "should succeed if valid range" do
|
|
|
|
expect { described_class.require_version(Vagrant::VERSION) }.
|
|
|
|
to_not raise_error
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not succeed if bad range" do
|
|
|
|
expect { described_class.require_version("> #{Vagrant::VERSION}") }.
|
|
|
|
to raise_error(Vagrant::Errors::VagrantVersionBad)
|
|
|
|
end
|
|
|
|
end
|
2011-12-15 06:43:45 +00:00
|
|
|
end
|