vagrant-triggers 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +10 -1
- data/CHANGELOG.md +18 -0
- data/README.md +9 -1
- data/lib/vagrant-triggers/action/trigger.rb +45 -28
- data/lib/vagrant-triggers/config.rb +12 -4
- data/lib/vagrant-triggers/dsl.rb +19 -4
- data/lib/vagrant-triggers/errors.rb +5 -1
- data/lib/vagrant-triggers/plugin.rb +10 -0
- data/lib/vagrant-triggers/version.rb +1 -1
- data/locales/en.yml +3 -11
- data/spec/vagrant-triggers/action/trigger_spec.rb +48 -6
- data/spec/vagrant-triggers/config_spec.rb +5 -7
- data/spec/vagrant-triggers/dsl_spec.rb +35 -8
- data/vagrant-triggers.gemspec +2 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24bfa273b967f208d110651eda1e6c9dc807ecf0
|
4
|
+
data.tar.gz: 643443292d3045678520d9b864bf00811648e8fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26fafa806afa5d6863033843dfe1329297ade73a8df715945ca1e877100925f12db659d63073b0a91bbc11f59b1d0734b1df3874ca4f073fde8a9eee4e45c9cd
|
7
|
+
data.tar.gz: d285bca1d4d3c2cba1dea08748cd7434aa8f3d5e8b3dac8a147269c4308cc57ade7e4458c29433d01fb7cf943c81917cb0ea7cde6d92c03dea95efb720aa4355
|
data/.travis.yml
CHANGED
@@ -1,15 +1,24 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
3
|
- 2.0.0
|
4
|
+
before_install:
|
5
|
+
- gem update --system
|
6
|
+
- rvm @global do gem uninstall -ax bundler
|
7
|
+
- gem install bundler -v 1.5.3
|
4
8
|
env:
|
5
|
-
- VAGRANT_VERSION=v1.
|
9
|
+
- VAGRANT_VERSION=v1.6.2
|
6
10
|
matrix:
|
7
11
|
include:
|
8
12
|
- env: VAGRANT_VERSION=master
|
13
|
+
rvm: 2.0.0
|
14
|
+
- env: VAGRANT_VERSION=v1.5.4
|
15
|
+
rvm: 2.0.0
|
9
16
|
- env: VAGRANT_VERSION=v1.4.3
|
17
|
+
rvm: 2.0.0
|
10
18
|
- env: VAGRANT_VERSION=v1.3.5
|
11
19
|
rvm: 1.9.3
|
12
20
|
- env: VAGRANT_VERSION=v1.2.7
|
13
21
|
rvm: 1.9.3
|
14
22
|
allow_failures:
|
15
23
|
- env: VAGRANT_VERSION=master
|
24
|
+
rvm: 2.0.0
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
## 0.4.0 (May 20, 2014)
|
2
|
+
|
3
|
+
NEW FEATURES:
|
4
|
+
|
5
|
+
- New trigger type: ```instead_of```.
|
6
|
+
- Add ```:vm``` option for choosing the target vm(s) in case of multi-machine Vagrantfile.
|
7
|
+
|
8
|
+
IMPROVEMENTS:
|
9
|
+
|
10
|
+
- DSL: add ```run_remote``` as alias to ```run("vagrant ssh -c ...")```.
|
11
|
+
- DSL: the ```error``` statement now stops the action and makes Vagrant fail with an error.
|
12
|
+
- Ensure the ```run``` statement always returns the command output.
|
13
|
+
|
14
|
+
BUG FIXES:
|
15
|
+
|
16
|
+
- Use additive merge logic [(#12)](https://github.com/emyl/vagrant-triggers/issues/12)
|
17
|
+
- Remove bundler settings from RUBYOPT [(reopened #5)](https://github.com/emyl/vagrant-triggers/issues/5)
|
18
|
+
|
1
19
|
## 0.3.0 (April 4, 2014)
|
2
20
|
|
3
21
|
CHANGES:
|
data/README.md
CHANGED
@@ -31,9 +31,16 @@ Vagrant.configure("2") do |config|
|
|
31
31
|
run "script"
|
32
32
|
...
|
33
33
|
end
|
34
|
+
|
35
|
+
config.trigger.instead_of :command, :option => "value" do
|
36
|
+
run "script"
|
37
|
+
...
|
38
|
+
end
|
34
39
|
end
|
35
40
|
```
|
36
41
|
|
42
|
+
The ```instead_of``` trigger could also be aliased as ```reject```.
|
43
|
+
|
37
44
|
The first argument is the command in which the trigger will be tied. It could be an array (e.g. ```[:up, :resume]```) in case of multiple commands.
|
38
45
|
|
39
46
|
### Options
|
@@ -41,10 +48,11 @@ The first argument is the command in which the trigger will be tied. It could be
|
|
41
48
|
* ```:append_to_path => ["dir", "dir"]```: additional places where looking for scripts. See [this wiki page](https://github.com/emyl/vagrant-triggers/wiki/The-:append_to_path-option) for details.
|
42
49
|
* ```:force => true```: continue even one of the scripts fails (exits with non-zero code)
|
43
50
|
* ```:stdout => true```: display script output
|
51
|
+
* ```:vm => ["vm1", /vm[2-3]/]```: fire only for matching virtual machines. Value can be a string, a regexp or an array of strings and/or regexps.
|
44
52
|
|
45
53
|
### Trigger block DSL
|
46
54
|
|
47
|
-
The given block will be evaluated by an instance of the [VagrantPlugins::Triggers::DSL](https://github.com/emyl/vagrant-triggers/blob/master/lib/vagrant-triggers/dsl.rb) class. This class defines a very simple DSL for running scripts on the host machine.
|
55
|
+
The given block will be evaluated by an instance of the [VagrantPlugins::Triggers::DSL](https://github.com/emyl/vagrant-triggers/blob/master/lib/vagrant-triggers/dsl.rb) class. This class defines a very simple DSL for running scripts on the host machine. Only a few methods are directly defined, all the other calls will be forwarded to Vagrant's [ui](https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/ui.rb) instance. This allows the definition of custom messages along with scripts.
|
48
56
|
|
49
57
|
For additional details you can take a look to the [VagrantPlugins::Triggers::DSL](https://github.com/emyl/vagrant-triggers/blob/master/lib/vagrant-triggers/dsl.rb) definition.
|
50
58
|
|
@@ -8,50 +8,67 @@ module VagrantPlugins
|
|
8
8
|
@app = app
|
9
9
|
@condition = condition
|
10
10
|
@env = env
|
11
|
+
@exit = false
|
11
12
|
@logger = Log4r::Logger.new("vagrant::plugins::triggers::trigger")
|
12
13
|
end
|
13
14
|
|
14
15
|
def call(env)
|
15
16
|
fire_triggers
|
16
17
|
|
17
|
-
|
18
|
-
@app.call(env)
|
18
|
+
@app.call(env) unless @exit
|
19
19
|
end
|
20
20
|
|
21
21
|
private
|
22
22
|
|
23
23
|
def fire_triggers
|
24
24
|
# Triggers don't fire on environment load and unload.
|
25
|
-
return if [:environment_load, :environment_unload].include?(@env[:action_name])
|
26
|
-
|
25
|
+
return if [:environment_load, :environment_plugins_loaded, :environment_unload].include?(@env[:action_name])
|
26
|
+
|
27
27
|
# Also don't fire if machine action is not defined.
|
28
|
-
return unless
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
dsl = DSL.new(@env[:ui], @options)
|
46
|
-
dsl.execute @options[:execute]
|
47
|
-
when @options[:info]
|
48
|
-
dsl = DSL.new(@env[:ui], @options)
|
49
|
-
dsl.info @options[:info]
|
50
|
-
else
|
51
|
-
@logger.debug("Trigger command not found.")
|
28
|
+
return unless @env[:machine_action]
|
29
|
+
|
30
|
+
@logger.debug("Looking for triggers with:")
|
31
|
+
trigger_env.each { |k, v| @logger.debug("-- #{k}: #{v}")}
|
32
|
+
|
33
|
+
# Loop through all defined triggers checking for matches.
|
34
|
+
triggers_to_fire = [].tap do |triggers|
|
35
|
+
@env[:machine].config.trigger.triggers.each do |trigger|
|
36
|
+
next if trigger[:action] != trigger_env[:action]
|
37
|
+
next if trigger[:condition] != trigger_env[:condition]
|
38
|
+
|
39
|
+
if trigger[:options][:vm]
|
40
|
+
match = false
|
41
|
+
Array(trigger[:options][:vm]).each do |pattern|
|
42
|
+
match = true if trigger_env[:vm].match(pattern)
|
43
|
+
end
|
44
|
+
next unless match
|
52
45
|
end
|
46
|
+
|
47
|
+
triggers << trigger
|
53
48
|
end
|
54
49
|
end
|
50
|
+
|
51
|
+
unless triggers_to_fire.empty?
|
52
|
+
@env[:ui].info I18n.t("vagrant_triggers.action.trigger.running_triggers", trigger_env).gsub('_', ' ')
|
53
|
+
@exit = true if trigger_env[:condition] == :instead_of
|
54
|
+
end
|
55
|
+
|
56
|
+
triggers_to_fire.each do |trigger|
|
57
|
+
if trigger[:proc]
|
58
|
+
dsl = DSL.new(@env[:ui], @env[:machine], trigger[:options])
|
59
|
+
dsl.instance_eval &trigger[:proc]
|
60
|
+
else
|
61
|
+
@logger.debug("Trigger command not found.")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def trigger_env
|
67
|
+
{
|
68
|
+
:action => @env[:machine_action],
|
69
|
+
:condition => @condition,
|
70
|
+
:vm => @env[:machine].name
|
71
|
+
}
|
55
72
|
end
|
56
73
|
end
|
57
74
|
end
|
@@ -1,12 +1,10 @@
|
|
1
1
|
module VagrantPlugins
|
2
2
|
module Triggers
|
3
3
|
class Config < Vagrant.plugin("2", :config)
|
4
|
-
attr_reader :deprecation_warning
|
5
4
|
attr_reader :triggers
|
6
5
|
|
7
6
|
def initialize
|
8
|
-
@
|
9
|
-
@triggers = []
|
7
|
+
@triggers = []
|
10
8
|
end
|
11
9
|
|
12
10
|
def after(actions, options = {}, &block)
|
@@ -17,6 +15,17 @@ module VagrantPlugins
|
|
17
15
|
add_trigger(actions, :before, options, block)
|
18
16
|
end
|
19
17
|
|
18
|
+
def instead_of(actions, options = {}, &block)
|
19
|
+
add_trigger(actions, :instead_of, options, block)
|
20
|
+
end
|
21
|
+
alias_method :reject, :instead_of
|
22
|
+
|
23
|
+
def merge(other)
|
24
|
+
super.tap do |result|
|
25
|
+
result.instance_variable_set(:@triggers, @triggers + other.triggers)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
20
29
|
def validate(machine)
|
21
30
|
errors = []
|
22
31
|
|
@@ -32,7 +41,6 @@ module VagrantPlugins
|
|
32
41
|
def add_trigger(actions, condition, options, proc)
|
33
42
|
Array(actions).each do |action|
|
34
43
|
@triggers << { :action => action, :condition => condition, :options => options, :proc => proc }
|
35
|
-
@deprecation_warning = true if options[:execute] || options[:info]
|
36
44
|
end
|
37
45
|
end
|
38
46
|
end
|
data/lib/vagrant-triggers/dsl.rb
CHANGED
@@ -5,14 +5,19 @@ require "vagrant/util/subprocess"
|
|
5
5
|
module VagrantPlugins
|
6
6
|
module Triggers
|
7
7
|
class DSL
|
8
|
-
def initialize(ui, options = {})
|
8
|
+
def initialize(ui, machine, options = {})
|
9
9
|
@logger = Log4r::Logger.new("vagrant::plugins::triggers::dsl")
|
10
|
+
@machine = machine
|
10
11
|
@options = options
|
11
12
|
@ui = ui
|
12
13
|
end
|
13
14
|
|
15
|
+
def error(message, *opts)
|
16
|
+
raise Errors::DSLError, @ui.error(message, *opts)
|
17
|
+
end
|
18
|
+
|
14
19
|
def run(raw_command, options = {})
|
15
|
-
|
20
|
+
info I18n.t("vagrant_triggers.action.trigger.executing_command", :command => raw_command)
|
16
21
|
command = Shellwords.shellsplit(raw_command)
|
17
22
|
env_backup = ENV.to_hash
|
18
23
|
begin
|
@@ -27,11 +32,17 @@ module VagrantPlugins
|
|
27
32
|
raise Errors::CommandFailed, :command => raw_command, :stderr => result.stderr
|
28
33
|
end
|
29
34
|
if @options[:stdout]
|
30
|
-
|
35
|
+
info I18n.t("vagrant_triggers.action.trigger.command_output", :output => result.stdout)
|
31
36
|
end
|
37
|
+
result.stdout
|
32
38
|
end
|
33
39
|
alias_method :execute, :run
|
34
40
|
|
41
|
+
def run_remote(raw_command, options = {})
|
42
|
+
run("vagrant ssh -c '#{raw_command}' #{@machine.name}", options)
|
43
|
+
end
|
44
|
+
alias_method :execute_remote, :run_remote
|
45
|
+
|
35
46
|
def method_missing(method, *args, &block)
|
36
47
|
# If the @ui object responds to the given method, call it
|
37
48
|
if @ui.respond_to?(method)
|
@@ -55,7 +66,11 @@ module VagrantPlugins
|
|
55
66
|
new_path = ENV["VAGRANT_INSTALLER_ENV"] ? ENV["PATH"].gsub(/#{ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"]}.*?#{File::PATH_SEPARATOR}/, "") : ENV["PATH"]
|
56
67
|
new_path += Array(@options[:append_to_path]).map { |dir| "#{File::PATH_SEPARATOR}#{dir}" }.join
|
57
68
|
ENV["PATH"] = new_path
|
58
|
-
@logger.debug("PATH
|
69
|
+
@logger.debug("PATH modified: #{ENV["PATH"]}")
|
70
|
+
|
71
|
+
# Remove bundler settings from RUBYOPT
|
72
|
+
ENV["RUBYOPT"] = (ENV["RUBYOPT"] || "").gsub(/-rbundler\/setup\s*/, "")
|
73
|
+
@logger.debug("RUBYOPT modified: #{ENV["RUBYOPT"]}")
|
59
74
|
|
60
75
|
# Add the VAGRANT_NO_TRIGGERS variable to avoid loops
|
61
76
|
ENV["VAGRANT_NO_TRIGGERS"] = "1"
|
@@ -4,6 +4,15 @@ if Vagrant::VERSION < "1.2.0"
|
|
4
4
|
raise "The Vagrant Triggers plugin is only compatible with Vagrant 1.2+"
|
5
5
|
end
|
6
6
|
|
7
|
+
if ["1.6.0", "1.6.1"].include?(Vagrant::VERSION)
|
8
|
+
warn <<-WARNING.gsub /^\s{2}/, ""
|
9
|
+
The Vagrant version you're using contains a bug that prevents some
|
10
|
+
triggers to work as expected. Update to version 1.6.2+ if you
|
11
|
+
want to avoid issues.
|
12
|
+
|
13
|
+
WARNING
|
14
|
+
end
|
15
|
+
|
7
16
|
module VagrantPlugins
|
8
17
|
module Triggers
|
9
18
|
class Plugin < Vagrant.plugin("2")
|
@@ -19,6 +28,7 @@ module VagrantPlugins
|
|
19
28
|
require_relative "action"
|
20
29
|
unless ENV["VAGRANT_NO_TRIGGERS"]
|
21
30
|
hook.prepend(Action.action_trigger(:before))
|
31
|
+
hook.prepend(Action.action_trigger(:instead_of))
|
22
32
|
hook.append(Action.action_trigger(:after))
|
23
33
|
end
|
24
34
|
end
|
data/locales/en.yml
CHANGED
@@ -7,20 +7,10 @@ en:
|
|
7
7
|
---------------
|
8
8
|
%{output}
|
9
9
|
---------------
|
10
|
-
deprecated_syntax: |-
|
11
|
-
--------------------
|
12
|
-
DEPRECATION WARNING:
|
13
|
-
--------------------
|
14
|
-
The `:execute` and `:info` trigger options are deprecated
|
15
|
-
and will be removed in vagrant-triggers 0.4. Please upgrade
|
16
|
-
your Vagrantfile according to the new trigger DSL.
|
17
|
-
|
18
|
-
More information on the project home page:
|
19
|
-
https://github.com/emyl/vagrant-triggers
|
20
10
|
executing_command: |-
|
21
11
|
Executing command "%{command}"...
|
22
12
|
running_triggers: |-
|
23
|
-
Running triggers %{condition} action...
|
13
|
+
Running triggers %{condition} %{action}...
|
24
14
|
errors:
|
25
15
|
command_failed: |-
|
26
16
|
The command "%{command}" returned a failed exit code. The
|
@@ -31,3 +21,5 @@ en:
|
|
31
21
|
The executable "%{command}" Vagrant is trying to trigger
|
32
22
|
was not found. If you know it is not in the PATH, please
|
33
23
|
specify its absolute path using the :append_to_path option.
|
24
|
+
dsl_error: |-
|
25
|
+
Trigger failed with an error.
|
@@ -14,7 +14,7 @@ describe VagrantPlugins::Triggers::Action::Trigger do
|
|
14
14
|
before do
|
15
15
|
trigger_block = Proc.new { nil }
|
16
16
|
@triggers = [ { :action => machine_action, :condition => condition, :options => { }, :proc => trigger_block } ]
|
17
|
-
machine.
|
17
|
+
machine.stub(:name)
|
18
18
|
machine.stub_chain(:config, :trigger, :triggers).and_return(@triggers)
|
19
19
|
end
|
20
20
|
|
@@ -35,7 +35,7 @@ describe VagrantPlugins::Triggers::Action::Trigger do
|
|
35
35
|
|
36
36
|
it "should fire trigger when all conditions are satisfied" do
|
37
37
|
dsl = double("dsl")
|
38
|
-
VagrantPlugins::Triggers::DSL.stub(:new).with(ui, @triggers.first[:options]).and_return(dsl)
|
38
|
+
VagrantPlugins::Triggers::DSL.stub(:new).with(ui, machine, @triggers.first[:options]).and_return(dsl)
|
39
39
|
dsl.should_receive(:instance_eval).and_yield
|
40
40
|
described_class.new(app, env, condition).call(env)
|
41
41
|
end
|
@@ -64,9 +64,51 @@ describe VagrantPlugins::Triggers::Action::Trigger do
|
|
64
64
|
described_class.new(app, env, condition).call(env)
|
65
65
|
end
|
66
66
|
|
67
|
-
it "
|
68
|
-
|
69
|
-
|
70
|
-
described_class.new(app, env,
|
67
|
+
it "shouldn't carry on in the middleware chain on instead_of condition" do
|
68
|
+
@triggers[0][:condition] = :instead_of
|
69
|
+
app.should_not_receive(:call).with(env)
|
70
|
+
described_class.new(app, env, :instead_of).call(env)
|
71
|
+
end
|
72
|
+
|
73
|
+
context ":vm option" do
|
74
|
+
before do
|
75
|
+
machine.stub(:name).and_return("vm1")
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should fire trigger when :vm option match" do
|
79
|
+
@triggers[0][:options][:vm] = "vm1"
|
80
|
+
VagrantPlugins::Triggers::DSL.should_receive(:new)
|
81
|
+
described_class.new(app, env, condition).call(env)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "shouldn't fire trigger when :vm option doesn't match" do
|
85
|
+
@triggers[0][:options][:vm] = "vm2"
|
86
|
+
VagrantPlugins::Triggers::DSL.should_not_receive(:new)
|
87
|
+
described_class.new(app, env, condition).call(env)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should fire trigger when :vm option is an array and one of the elements match" do
|
91
|
+
@triggers[0][:options][:vm] = ["vm1", "vm2"]
|
92
|
+
VagrantPlugins::Triggers::DSL.should_receive(:new)
|
93
|
+
described_class.new(app, env, condition).call(env)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "shouldn't fire trigger when :vm option is an array and no element match" do
|
97
|
+
@triggers[0][:options][:vm] = ["vm2", "vm3"]
|
98
|
+
VagrantPlugins::Triggers::DSL.should_not_receive(:new)
|
99
|
+
described_class.new(app, env, condition).call(env)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should fire trigger when :vm option is a regex and the pattern match" do
|
103
|
+
@triggers[0][:options][:vm] = /^vm/
|
104
|
+
VagrantPlugins::Triggers::DSL.should_receive(:new)
|
105
|
+
described_class.new(app, env, condition).call(env)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "shouldn't fire trigger when :vm option is a regex and the pattern doesn't match" do
|
109
|
+
@triggers[0][:options][:vm] = /staging/
|
110
|
+
VagrantPlugins::Triggers::DSL.should_not_receive(:new)
|
111
|
+
described_class.new(app, env, condition).call(env)
|
112
|
+
end
|
71
113
|
end
|
72
114
|
end
|
@@ -20,16 +20,14 @@ describe VagrantPlugins::Triggers::Config do
|
|
20
20
|
expect(config.triggers).to have(1).item
|
21
21
|
end
|
22
22
|
|
23
|
-
it "should add
|
24
|
-
config.
|
23
|
+
it "should add instead_of triggers" do
|
24
|
+
config.instead_of(:up) { run "ls" }
|
25
25
|
expect(config.triggers).to have(1).item
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
expect(config.deprecation_warning).to be_true
|
32
|
-
end
|
28
|
+
it "should add after triggers" do
|
29
|
+
config.after(:up) { run "ls" }
|
30
|
+
expect(config.triggers).to have(1).item
|
33
31
|
end
|
34
32
|
end
|
35
33
|
|
@@ -5,12 +5,22 @@ describe VagrantPlugins::Triggers::DSL do
|
|
5
5
|
let(:result) { double("result", :exit_code => 0, :stderr => stderr) }
|
6
6
|
let(:stderr) { double("stderr") }
|
7
7
|
|
8
|
-
let(:
|
9
|
-
let(:
|
8
|
+
let(:machine) { double("machine") }
|
9
|
+
let(:ui) { double("ui", :info => info) }
|
10
|
+
let(:info) { double("info") }
|
10
11
|
|
11
12
|
before do
|
12
13
|
@command = "foo"
|
13
|
-
@dsl = described_class.new(ui, {})
|
14
|
+
@dsl = described_class.new(ui, machine, {})
|
15
|
+
|
16
|
+
result.stub(:stdout => "Some output")
|
17
|
+
end
|
18
|
+
|
19
|
+
context "error" do
|
20
|
+
it "should raise a DSL error on UI error" do
|
21
|
+
ui.should_receive(:error).with("Error message")
|
22
|
+
expect { @dsl.error("Error message") }.to raise_error(VagrantPlugins::Triggers::Errors::DSLError)
|
23
|
+
end
|
14
24
|
end
|
15
25
|
|
16
26
|
context "method missing" do
|
@@ -31,14 +41,13 @@ describe VagrantPlugins::Triggers::DSL do
|
|
31
41
|
end
|
32
42
|
|
33
43
|
it "shouldn't raise an error if executed command exits with non-zero code but :force option was specified" do
|
34
|
-
dsl = described_class.new(ui, :force => true)
|
44
|
+
dsl = described_class.new(ui, machine, :force => true)
|
35
45
|
result.stub(:exit_code => 1)
|
36
46
|
expect { dsl.run(@command) }.not_to raise_error()
|
37
47
|
end
|
38
48
|
|
39
49
|
it "should display output if :stdout option was specified" do
|
40
|
-
dsl = described_class.new(ui, :stdout => true)
|
41
|
-
result.stub(:stdout => "Some output")
|
50
|
+
dsl = described_class.new(ui, machine, :stdout => true)
|
42
51
|
ui.should_receive(:info).with(/Some output/)
|
43
52
|
dsl.run(@command)
|
44
53
|
end
|
@@ -74,14 +83,14 @@ describe VagrantPlugins::Triggers::DSL do
|
|
74
83
|
end
|
75
84
|
|
76
85
|
it "should honor the :append_to_path option and restore original path after execution" do
|
77
|
-
dsl = described_class.new(ui, :append_to_path => @tmp_dir)
|
86
|
+
dsl = described_class.new(ui, machine, :append_to_path => @tmp_dir)
|
78
87
|
original_path = ENV["PATH"]
|
79
88
|
dsl.run(@command)
|
80
89
|
expect(ENV["PATH"]).to eq(original_path)
|
81
90
|
end
|
82
91
|
|
83
92
|
it "should accept an array for the :append_to_path option" do
|
84
|
-
dsl = described_class.new(ui, :append_to_path => [@tmp_dir, @tmp_dir])
|
93
|
+
dsl = described_class.new(ui, machine, :append_to_path => [@tmp_dir, @tmp_dir])
|
85
94
|
expect { dsl.run(@command) }.not_to raise_error()
|
86
95
|
end
|
87
96
|
end
|
@@ -95,6 +104,7 @@ describe VagrantPlugins::Triggers::DSL do
|
|
95
104
|
ENV["GEM_PATH"] = ENV["GEM_HOME"]
|
96
105
|
ENV["GEMRC"] = "#{ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"]}/etc/gemrc"
|
97
106
|
ENV["PATH"] = "#{ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"]}/bin:#{ENV["PATH"]}"
|
107
|
+
ENV["RUBYOPT"] = "-rbundler/setup"
|
98
108
|
end
|
99
109
|
|
100
110
|
context "with a command which is present into the Vagrant embedded dir" do
|
@@ -122,12 +132,29 @@ describe VagrantPlugins::Triggers::DSL do
|
|
122
132
|
end
|
123
133
|
end
|
124
134
|
|
135
|
+
it "should remove bundler settings from RUBYOPT" do
|
136
|
+
Vagrant::Util::Subprocess.should_receive(:execute) do |command|
|
137
|
+
expect(ENV["RUBYOPT"]).to eq("")
|
138
|
+
result
|
139
|
+
end
|
140
|
+
@dsl.run(@command)
|
141
|
+
end
|
142
|
+
|
125
143
|
after do
|
126
144
|
ENV["EMBEDDED_DIR"] = nil
|
127
145
|
ENV["GEM_HOME"] = nil
|
128
146
|
ENV["GEM_PATH"] = nil
|
129
147
|
ENV["GEMRC"] = nil
|
130
148
|
ENV["PATH"] = @original_path
|
149
|
+
ENV["RUBYOPT"] = nil
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context "run_remote" do
|
154
|
+
it "should generate a 'vagrant ssh -c' command" do
|
155
|
+
machine.stub(:name => "vm1")
|
156
|
+
@dsl.should_receive(:run).with("vagrant ssh -c '#{@command}' vm1", {})
|
157
|
+
@dsl.run_remote(@command, {})
|
131
158
|
end
|
132
159
|
end
|
133
160
|
end
|
data/vagrant-triggers.gemspec
CHANGED
@@ -6,8 +6,10 @@ Gem::Specification.new do |spec|
|
|
6
6
|
spec.version = VagrantPlugins::Triggers::VERSION
|
7
7
|
spec.authors = "Emiliano Ticci"
|
8
8
|
spec.email = "emiticci@gmail.com"
|
9
|
+
spec.homepage = "https://github.com/emyl/vagrant-triggers"
|
9
10
|
spec.summary = "Triggers for Vagrant commands."
|
10
11
|
spec.description = "This plugin allow the definition of arbitrary scripts that will run on the host before and/or after Vagrant commands."
|
12
|
+
spec.license = "MIT"
|
11
13
|
|
12
14
|
# The following block of code determines the files that should be included
|
13
15
|
# in the gem. It does this by reading all the files in the directory where
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-triggers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emiliano Ticci
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -81,8 +81,9 @@ files:
|
|
81
81
|
- vagrant-triggers.gemspec
|
82
82
|
- .gitignore
|
83
83
|
- .travis.yml
|
84
|
-
homepage:
|
85
|
-
licenses:
|
84
|
+
homepage: https://github.com/emyl/vagrant-triggers
|
85
|
+
licenses:
|
86
|
+
- MIT
|
86
87
|
metadata: {}
|
87
88
|
post_install_message:
|
88
89
|
rdoc_options: []
|