diff options
author | Asutosh Palai <asupalai@gmail.com> | 2016-06-21 17:48:54 +0530 |
---|---|---|
committer | Asutosh Palai <asupalai@gmail.com> | 2016-07-03 09:40:59 +0530 |
commit | 4f00384937263175c3563cd23bbabae5c2d912fd (patch) | |
tree | 3f4b02825775a590375ade25804ba046e699d0f3 /spec/bundler/plugin_spec.rb | |
parent | 9c23dcc1896f2b657ea4407998e3c0ee38d83a49 (diff) | |
download | bundler-4f00384937263175c3563cd23bbabae5c2d912fd.tar.gz |
Added unit spec for plugin class
Diffstat (limited to 'spec/bundler/plugin_spec.rb')
-rw-r--r-- | spec/bundler/plugin_spec.rb | 94 |
1 files changed, 83 insertions, 11 deletions
diff --git a/spec/bundler/plugin_spec.rb b/spec/bundler/plugin_spec.rb index d1420f530e..8e85be6718 100644 --- a/spec/bundler/plugin_spec.rb +++ b/spec/bundler/plugin_spec.rb @@ -75,7 +75,7 @@ describe Bundler::Plugin do before do allow(Plugin::DSL).to receive(:new) { builder } - allow(builder).to receive(:eval_gemfile) + allow(builder).to receive(:eval_gemfile).with(gemfile) allow(builder).to receive(:to_definition) { definition } allow(builder).to receive(:auto_plugins) { [] } end @@ -87,18 +87,37 @@ describe Bundler::Plugin do subject.gemfile_install(gemfile) end - it "should validate and register the plugins" do - allow(definition).to receive(:dependencies) { [1, 2] } - plugin_paths = { - "new-plugin" => lib_path("new-plugin"), - "another-plugin" => lib_path("another-plugin"), - } - allow(installer).to receive(:install_definition) { plugin_paths } + context "with dependencies" do + let(:plugin_paths) do + { + "new-plugin" => lib_path("new-plugin"), + "another-plugin" => lib_path("another-plugin"), + } + end + + before do + allow(definition).to receive(:dependencies) { [1, 2] } + allow(installer).to receive(:install_definition) { plugin_paths } + end - expect(subject).to receive(:validate_plugin!).twice - expect(subject).to receive(:register_plugin).twice + it "should validate and register the plugins" do + expect(subject).to receive(:validate_plugin!).twice + expect(subject).to receive(:register_plugin).twice - subject.gemfile_install(gemfile) + subject.gemfile_install(gemfile) + end + + it "should pass the optional plugins to #register_plugin" do + allow(builder).to receive(:auto_plugins) { ["another-plugin"] } + + expect(subject).to receive(:register_plugin). + with("new-plugin", plugin_paths["new-plugin"], false).once + + expect(subject).to receive(:register_plugin). + with("another-plugin", plugin_paths["another-plugin"], true).once + + subject.gemfile_install(gemfile) + end end end @@ -124,4 +143,57 @@ describe Bundler::Plugin do to raise_error(Plugin::UndefinedCommandError) end end + + describe "#source?" do + it "returns true value for sources in index" do + allow(index). + to receive(:command_plugin).with("foo-source") { "my-plugin" } + result = subject.command? "foo-source" + expect(result).to be_truthy + end + + it "returns false value for source not in index" do + allow(index).to receive(:command_plugin).with("foo-source") { nil } + result = subject.command? "foo-source" + expect(result).to be_falsy + end + end + + describe "#source" do + it "raises UnknownSourceError when source is not found" do + allow(index).to receive(:source_plugin).with("bar") { nil } + expect { subject.source("bar") }. + to raise_error(Plugin::UnknownSourceError) + end + + it "loads the plugin, if not loaded" do + allow(index).to receive(:source_plugin).with("foo-bar") {"plugin_name"} + + expect(subject).to receive(:load_plugin).with("plugin_name") + subject.source("foo-bar") + end + + it "returns the class registered with #add_source" do + allow(index).to receive(:source_plugin).with("foo") { "plugin_name" } + stub_const "NewClass", Class.new + + subject.add_source("foo", NewClass) + expect(subject.source("foo")).to be(NewClass) + end + end + + describe "#source_from_lock" do + it "returns instance of registered class initialized with locked opts" do + opts = {"type" => "l_source", "remote" => "xyz", "other" => "random"} + allow(index).to receive(:source_plugin).with("l_source") { "plugin_name" } + + stub_const "SClass", Class.new + s_instance = double(:s_instance) + subject.add_source("l_source", SClass) + + expect(SClass).to receive(:new).with(hash_including( + "type" => "l_source", "uri" => "xyz", "other" => "random")) { s_instance } + expect(subject.source_from_lock(opts)).to be(s_instance) + end + end end |