features/vagrant-exec.feature in vagrant-exec-0.2.1 vs features/vagrant-exec.feature in vagrant-exec-0.3.0

- old
+ new

@@ -8,84 +8,167 @@ And prepend commands with "bundle exec" And set exported environmental variables Using Vagrantfile configuration Background: - Given I have default Vagrantfile + Given I write to "Vagrantfile" with: + """ + Vagrant.require_plugin 'vagrant-exec' - Scenario: uses /vagrant as default folder + Vagrant.configure('2') do |config| + config.vm.box = 'vagrant_exec' + end + """ + + Scenario Outline: shows help correctly Given I run `bundle exec vagrant up` + When I run `bundle exec vagrant exec <args>` + Then the output should contain "Usage: vagrant exec [options] <command>" + Examples: + | args | + | | + | -h | + | --help | + | -h pwd | + | --help pwd -h | + + Scenario Outline: passes command arguments correctly + Given I run `bundle exec vagrant up` + When I run `bundle exec vagrant exec <cmd>` + Then SHH subprocess should execute command "cd /vagrant && <cmd>" + Examples: + | cmd | + | cwd . | + | cwd ~ | + | cwd -h | + | cwd --blah | + | "cwd -h blah -v blah" | + + Scenario: uses /vagrant as default root + Given I run `bundle exec vagrant up` When I run `bundle exec vagrant exec pwd` Then the exit status should be 0 - And the output should contain "Executing single command on remote machine: source ~/.profile && cd /vagrant && pwd" + And SHH subprocess should execute command "cd /vagrant && pwd" - Scenario: can use custom folder - Given I set vagrant-exec folder to "/tmp" + Scenario: can use custom root + Given I overwrite "Vagrantfile" with: + """ + Vagrant.require_plugin 'vagrant-exec' + + Vagrant.configure('2') do |config| + config.vm.box = 'vagrant_exec' + config.exec.root = '/tmp' + end + """ And I run `bundle exec vagrant up` When I run `bundle exec vagrant exec pwd` Then the exit status should be 0 - And the output should contain "Executing single command on remote machine: source ~/.profile && cd /tmp && pwd" + And SHH subprocess should execute command "cd /tmp && pwd" - Scenario: raises error if folder is improperly set - Given I set vagrant-exec folder to true + Scenario: raises error if root is improperly set + Given I overwrite "Vagrantfile" with: + """ + Vagrant.require_plugin 'vagrant-exec' + + Vagrant.configure('2') do |config| + config.vm.box = 'vagrant_exec' + config.exec.root = true + end + """ And I run `bundle exec vagrant up` Then the exit status should not be 0 - And the output should contain "folder should be a string" + And the output should contain "root should be a string" - Scenario: does not use bundler by default - Given I run `bundle exec vagrant up` + Scenario: can prepend all commands + Given I overwrite "Vagrantfile" with: + """ + Vagrant.require_plugin 'vagrant-exec' + + Vagrant.configure('2') do |config| + config.vm.box = 'vagrant_exec' + config.exec.prepend_with 'echo vagrant-exec &&' + end + """ + And I run `bundle exec vagrant up` When I run `bundle exec vagrant exec pwd` - Then the output should not contain "bundle exec" + Then the exit status should be 0 + And SHH subprocess should execute command "cd /vagrant && echo vagrant-exec && pwd" - # we don't have bundler in box - Scenario: can use bundler - Given I set vagrant-exec bundler to true + Scenario: can prepend only specific commands + Given I overwrite "Vagrantfile" with: + """ + Vagrant.require_plugin 'vagrant-exec' + + Vagrant.configure('2') do |config| + config.vm.box = 'vagrant_exec' + config.exec.prepend_with 'echo vagrant-exec &&', :only => %w(pwd echo) + end + """ And I run `bundle exec vagrant up` When I run `bundle exec vagrant exec pwd` - Then the exit status should not be 0 - And the output should contain "Executing single command on remote machine: source ~/.profile && cd /vagrant && bundle exec pwd" + Then SHH subprocess should execute command "cd /vagrant && echo vagrant-exec && pwd" + When I run `bundle exec vagrant exec echo 1` + Then SHH subprocess should execute command "cd /vagrant && echo vagrant-exec && echo 1" + When I run `bundle exec vagrant exec env` + Then SHH subprocess should execute command "cd /vagrant && env" - Scenario: does not use bundler for bundle commands - Given I set vagrant-exec bundler to true + Scenario: can use prepend multiple times + Given I overwrite "Vagrantfile" with: + """ + Vagrant.require_plugin 'vagrant-exec' + + Vagrant.configure('2') do |config| + config.vm.box = 'vagrant_exec' + config.exec.prepend_with 'echo vagrant-exec1 &&', :only => %w(pwd) + config.exec.prepend_with 'echo vagrant-exec2 &&', :only => %w(echo) + end + """ And I run `bundle exec vagrant up` - When I run `bundle exec vagrant exec bundle install` - Then the output should contain "Executing single command on remote machine: source ~/.profile && cd /vagrant && bundle install" + When I run `bundle exec vagrant exec pwd` + Then SHH subprocess should execute command "cd /vagrant && echo vagrant-exec1 && pwd" + When I run `bundle exec vagrant exec echo 1` + Then SHH subprocess should execute command "cd /vagrant && echo vagrant-exec2 && echo 1" - Scenario: raises error if bundler is improperly set - Given I set vagrant-exec bundler to "true" - When I run `bundle exec vagrant up` + Scenario: raises error if prepend command is improperly set + Given I overwrite "Vagrantfile" with: + """ + Vagrant.require_plugin 'vagrant-exec' + + Vagrant.configure('2') do |config| + config.vm.box = 'vagrant_exec' + config.exec.prepend_with :test + end + """ + Given I set vagrant-exec prepend with :test for all commands + And I run `bundle exec vagrant up` Then the exit status should not be 0 - And the output should contain "bundler should be boolean" + And the output should contain "prepend_with command should be a string" + Scenario: raises error if prepend only is improperly set + Given I overwrite "Vagrantfile" with: + """ + Vagrant.require_plugin 'vagrant-exec' + + Vagrant.configure('2') do |config| + config.vm.box = 'vagrant_exec' + config.exec.prepend_with 'echo vagrant-exec1 &&', :only => 'test' + end + """ + And I run `bundle exec vagrant up` + Then the exit status should not be 0 + And the output should contain "prepend_with :only should be an array" + Scenario: can export environment variables - Given I set vagrant-exec env with the following values: - | key | value | - | TEST1 | true | - | TEST2 | false | + Given I overwrite "Vagrantfile" with: + """ + Vagrant.require_plugin 'vagrant-exec' + + Vagrant.configure('2') do |config| + config.vm.box = 'vagrant_exec' + config.exec.env['TEST1'] = true + config.exec.env['TEST2'] = false + end + """ And I run `bundle exec vagrant up` When I run `bundle exec vagrant exec pwd` Then the exit status should be 0 - And the output should contain "Executing single command on remote machine: source ~/.profile && cd /vagrant && export TEST1=true && export TEST2=false && pwd" - - Scenario Outline: shows help correctly - Given I run `bundle exec vagrant up` - When I run `bundle exec vagrant exec <args>` - Then the output should contain "Usage: vagrant exec [options] <command>" - Examples: - | args | - | | - | -h | - | --help | - | -h pwd | - | --help pwd -h | - - Scenario Outline: passes command arguments correctly - Given I run `bundle exec vagrant up` - When I run `bundle exec vagrant exec <cmd>` - Then the output should contain "Executing single command on remote machine: source ~/.profile && cd /vagrant && <cmd>" - Examples: - | cmd | - | cwd . | - | cwd ~ | - | cwd -h | - | cwd --blah | - | cwd -h blah -v blah | + And SHH subprocess should execute command "cd /vagrant && export TEST1=true && export TEST2=false && pwd"