1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
require File.expand_path("../../../../../base", __FILE__)
describe VagrantPlugins::CommandPlugin::Action::ExpungePlugins do
let(:app) { lambda { |env| } }
let(:home_path){ '/fake/file/path/.vagrant.d' }
let(:gems_path){ "#{home_path}/gems" }
let(:force){ true }
let(:env_local){ false }
let(:env_local_only){ nil }
let(:global_only){ nil }
let(:env) {{
ui: Vagrant::UI::Silent.new,
home_path: home_path,
gems_path: gems_path,
force: force,
env_local: env_local,
env_local_only: env_local_only,
global_only: global_only
}}
let(:user_file) { double("user_file", path: user_file_pathname) }
let(:user_file_pathname) { double("user_file_pathname", exist?: true, delete: true) }
let(:local_file) { nil }
let(:bundler) { double("bundler", plugin_gem_path: plugin_gem_path,
env_plugin_gem_path: env_plugin_gem_path) }
let(:plugin_gem_path) { double("plugin_gem_path", exist?: true, rmtree: true) }
let(:env_plugin_gem_path) { nil }
let(:manager) { double("manager", user_file: user_file, local_file: local_file) }
let(:expect_to_receive) do
lambda do
allow(File).to receive(:exist?).with(File.join(home_path, 'plugins.json')).and_return(true)
allow(File).to receive(:directory?).with(gems_path).and_return(true)
expect(app).to receive(:call).with(env).once
end
end
subject { described_class.new(app, env) }
before do
allow(Vagrant::Plugin::Manager).to receive(:instance).and_return(manager)
allow(Vagrant::Bundler).to receive(:instance).and_return(bundler)
end
describe "#call" do
before do
instance_exec(&expect_to_receive)
end
it "should delete all plugins" do
expect(user_file_pathname).to receive(:delete)
expect(plugin_gem_path).to receive(:rmtree)
subject.call(env)
end
describe "when force is false" do
let(:force){ false }
it "should prompt user before deleting all plugins" do
expect(env[:ui]).to receive(:ask).and_return("Y\n")
subject.call(env)
end
describe "when user declines prompt" do
let(:expect_to_receive) do
lambda do
expect(app).not_to receive(:call)
end
end
it "should not delete all plugins" do
expect(env[:ui]).to receive(:ask).and_return("N\n")
subject.call(env)
end
end
end
context "when local option is set" do
let(:env_local) { true }
it "should delete plugins" do
expect(user_file_pathname).to receive(:delete)
expect(plugin_gem_path).to receive(:rmtree)
subject.call(env)
end
end
context "when local plugins exist" do
let(:local_file) { double("local_file", path: local_file_pathname) }
let(:local_file_pathname) { double("local_file_pathname", exist?: true, delete: true) }
let(:env_plugin_gem_path) { double("env_plugin_gem_path", exist?: true, rmtree: true) }
it "should delete user and local plugins" do
expect(user_file_pathname).to receive(:delete)
expect(local_file_pathname).to receive(:delete)
expect(plugin_gem_path).to receive(:rmtree)
expect(env_plugin_gem_path).to receive(:rmtree)
subject.call(env)
end
context "when local option is set" do
let(:env_local) { true }
it "should delete local plugins" do
expect(local_file_pathname).to receive(:delete)
expect(env_plugin_gem_path).to receive(:rmtree)
subject.call(env)
end
it "should delete user plugins" do
expect(user_file_pathname).to receive(:delete)
expect(plugin_gem_path).to receive(:rmtree)
subject.call(env)
end
context "when local only option is set" do
let(:env_local_only) { true }
it "should delete local plugins" do
expect(local_file_pathname).to receive(:delete)
expect(env_plugin_gem_path).to receive(:rmtree)
subject.call(env)
end
it "should not delete user plugins" do
expect(user_file_pathname).not_to receive(:delete)
expect(plugin_gem_path).not_to receive(:rmtree)
subject.call(env)
end
end
context "when global only option is set" do
let(:global_only) { true }
it "should not delete local plugins" do
expect(local_file_pathname).not_to receive(:delete)
expect(env_plugin_gem_path).not_to receive(:rmtree)
subject.call(env)
end
it "should delete user plugins" do
expect(user_file_pathname).to receive(:delete)
expect(plugin_gem_path).to receive(:rmtree)
subject.call(env)
end
end
context "when global and local only options are set" do
let(:env_local_only) { true }
let(:global_only) { true }
it "should delete local plugins" do
expect(local_file_pathname).to receive(:delete)
expect(env_plugin_gem_path).to receive(:rmtree)
subject.call(env)
end
it "should delete user plugins" do
expect(user_file_pathname).to receive(:delete)
expect(plugin_gem_path).to receive(:rmtree)
subject.call(env)
end
end
end
end
end
end
|