mitchellh/vagrant — pull request #2569 by fgrehm (2013-12-03 00:45:52+00:00)
Title: Fix hook with methods

This is a follow-up of my heads up [over here](https://github.com/mitchellh/vagrant/commit/3701b955cb9d70917945da4d6d3a8475e8df50c0#commitcomment-4729680)

I tried using the new `provisioner_run` hook from GH-2405 using the following Vagrantfile and it turned out that the action class does not get executed:

```ruby
class Action
def initialize(app, env)
@app = app
end

def call(env)
puts "Before '#{env[:provisioner_name]}'"
@app.call env
puts "After '#{env[:provisioner_name]}'"
end
end

class Plugin < Vagrant.plugin('2')
name 'testing-hook'
action_hook 'hook-name', :provisioner_run do |hook|
hook.prepend Action
end
end

Vagrant.configure("2") do |config|
config.vm.box = "precise64"
config.vm.provision :shell, inline: 'echo hello'
config.vm.provision :shell, inline: 'echo hello 2'
end
```

The output of a `vagrant provision`:

```
$ be vagrant provision
You appear to be running Vagrant in a Bundler environment. Because
Vagrant should be run within installers (outside of Bundler), Vagrant
will assume that you're developing plugins and will change its behavior
in certain ways to better assist plugin development.

[default] Running provisioner: shell...
[default] Running: inline script
stdin: is not a tty
hello
[default] Running provisioner: shell...
[default] Running: inline script
stdin: is not a tty
hello 2
```

`vagrant provision` after this patch:

```
$ be vagrant provision
You appear to be running Vagrant in a Bundler environment. Because
Vagrant should be run within installers (outside of Bundler), Vagrant
will assume that you're developing plugins and will change its behavior
in certain ways to better assist plugin development.

[default] Running provisioner: shell...
Before 'shell'
[default] Running: inline script
stdin: is not a tty
hello
After 'shell'
[default] Running provisioner: shell...
Before 'shell'
[default] Running: inline script
stdin: is not a tty
hello 2
After 'shell'
```

While this PR also adds a spec for the new `Method` support, I wasn't able to figure out where I should add a spec for making sure the hook behaves as expected when a `Method` object gets provided.