vagrant-cucumber 0.0.1
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.
- data/CHANGELOG.md +3 -0
- data/README.md +116 -0
- data/example/Vagrantfile +19 -0
- data/example/features/basic.feature +32 -0
- data/example/features/multivm.feature +18 -0
- data/example/features/process.feature +9 -0
- data/example/features/step_definitions/process.rb +77 -0
- data/example/features/support/env.rb +3 -0
- data/lib/vagrant-cucumber/commands/cucumber.rb +20 -0
- data/lib/vagrant-cucumber/cucumber/formatter/html.rb +24 -0
- data/lib/vagrant-cucumber/cucumber/formatter/pretty.rb +33 -0
- data/lib/vagrant-cucumber/glue.rb +99 -0
- data/lib/vagrant-cucumber/plugin.rb +24 -0
- data/lib/vagrant-cucumber/step_definitions.rb +106 -0
- data/lib/vagrant-cucumber/version.rb +5 -0
- data/lib/vagrant-cucumber.rb +9 -0
- data/vagrant-cucumber.gemspec +33 -0
- metadata +84 -0
data/CHANGELOG.md
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
Vagrant Cucumber
|
|
2
|
+
================
|
|
3
|
+
|
|
4
|
+
Description
|
|
5
|
+
-----------
|
|
6
|
+
|
|
7
|
+
This plugin allows Vagrant to run cucumber features, and provides some glue
|
|
8
|
+
for working with vagrant boxes within your cucumber steps.
|
|
9
|
+
|
|
10
|
+
It was originally developed to help us test configuration management scripts,
|
|
11
|
+
and with the following workflow in mind:
|
|
12
|
+
|
|
13
|
+
* Start one or more Vagrant boxes
|
|
14
|
+
* Configure these boxes with some default state
|
|
15
|
+
* Snapshot each box in this default state.
|
|
16
|
+
* In each cucumber scenario
|
|
17
|
+
- Run config management tools inside the box to make configuration changes
|
|
18
|
+
- Test that these changes produce the desired result
|
|
19
|
+
- Roll the VM state back, ready for the next scenario
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
Requirements
|
|
23
|
+
------------
|
|
24
|
+
|
|
25
|
+
The plugin requires cucumber and vagrant-zz-multiprovider-snap gems, but will
|
|
26
|
+
install these itself if required.
|
|
27
|
+
|
|
28
|
+
Vagrant Cucumber currently works only with the current Vagrant providers:
|
|
29
|
+
|
|
30
|
+
* VirtualBox
|
|
31
|
+
* VMWare Fusion (using the commercial VMWare plugin for Vagrant)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
Installation
|
|
36
|
+
------------
|
|
37
|
+
|
|
38
|
+
Assuming you're running the packaged version of Vagrant, the easiest way to
|
|
39
|
+
install this plugin is via the published gem:
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
vagrant plugin install vagrant-cucumber
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
As well as the vagrant-cucumber plugin, this will also install the
|
|
46
|
+
vagrant-zz-multiprovider-snap plugin if you don't already have it.
|
|
47
|
+
|
|
48
|
+
vagrant-cucumber will also install a version of cucumber >= 1.3.2 under the
|
|
49
|
+
Ruby environment provided by Vagrant.
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
Usage
|
|
53
|
+
-----
|
|
54
|
+
|
|
55
|
+
This plugin adds a subcommand, ```vagrant cucumber``` - this simply wraps
|
|
56
|
+
the usual ```cucumber``` commandline handler - refer to the documentation for
|
|
57
|
+
cucumber for details, or use ```vagrant cucumber -h``` for a full list of
|
|
58
|
+
options.
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
Example
|
|
62
|
+
-------
|
|
63
|
+
|
|
64
|
+
The git source of the plugin includes a folder called "example", which contains
|
|
65
|
+
a Vagrantfile and features directory which demonstrates the plugin in action.
|
|
66
|
+
|
|
67
|
+
The Vagrantfile defines two basic VMs which will be used to run our tests.
|
|
68
|
+
It will work with either the Virtualbox or the VMWare Fusion provider.
|
|
69
|
+
|
|
70
|
+
Use ```vagrant up``` in that folder in order to start the default VM. (In the
|
|
71
|
+
current version of the plugin, VMs must be running before they can be used
|
|
72
|
+
in tests). If you don't already have the standard precise64 vagrant box, it
|
|
73
|
+
will be fetched from the Vagrant website. If you prefer to use the VMWare
|
|
74
|
+
provider, add ```--provider=vmware_fusion``` to the commandline.
|
|
75
|
+
|
|
76
|
+
To run all the tests, run
|
|
77
|
+
|
|
78
|
+
```vagrant cucumber```.
|
|
79
|
+
|
|
80
|
+
The tests are split between multiple feature files. You can run one feature
|
|
81
|
+
file at a time by specifying it on the commandline:
|
|
82
|
+
|
|
83
|
+
```vagrant cucumber features/basic.feature```
|
|
84
|
+
|
|
85
|
+
```basic.feature``` demonstrates running basic shell commands inside the VM
|
|
86
|
+
both as the standard vagrant user, and as root. It also contains a test to show
|
|
87
|
+
that snapshot rollback is working correctly.
|
|
88
|
+
|
|
89
|
+
```multivm.feature``` shows how steps can reference different VMs. For details
|
|
90
|
+
on how to write your own step definitions which can work on multiple VMs,
|
|
91
|
+
see the next section.
|
|
92
|
+
|
|
93
|
+
The test in ```multivm.feature``` also demonstrates use of cucumber tags.
|
|
94
|
+
The test scenario is preceded with the tag ```@vagrant-cucumber-debug```. This
|
|
95
|
+
causes debug output to be emitted.
|
|
96
|
+
|
|
97
|
+
We also provide a ```@norollback``` tag, which prevents the VMs from being
|
|
98
|
+
rolled back at the end of the scenario. This is useful for debugging.
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
Implementation Detail
|
|
103
|
+
---------------------
|
|
104
|
+
|
|
105
|
+
The best place to gain an understanding of the implementation of Cucumber steps
|
|
106
|
+
is in ```example/features/step_definitions/process.rb```. I've heavily
|
|
107
|
+
commented this in order to be a good working example.
|
|
108
|
+
|
|
109
|
+
```example/features/process.feature``` uses these step definitions.
|
|
110
|
+
|
|
111
|
+
Other step definitions and hooks are defined in ```lib/vagrant-cucumber/step_definitions.rb```.
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
data/example/Vagrantfile
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Vagrant.configure("2") do |config|
|
|
2
|
+
|
|
3
|
+
config.vm.box = "precise64"
|
|
4
|
+
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
|
|
5
|
+
|
|
6
|
+
config.vm.provider :vmware_fusion do |fusion,override|
|
|
7
|
+
override.vm.box = "precise64_vmware_fusion"
|
|
8
|
+
override.vm.box_url = "http://files.vagrantup.com/precise64_vmware_fusion.box"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
config.vm.define :vm1 do |vm1|
|
|
12
|
+
vm1.vm.hostname = 'vm1'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
config.vm.define :vm2 do |vm2|
|
|
16
|
+
vm2.vm.hostname = 'vm2'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Feature: VM Running
|
|
2
|
+
|
|
3
|
+
Scenario: Check we can run simple commands
|
|
4
|
+
|
|
5
|
+
Given there is a running VM called "vm1"
|
|
6
|
+
Then running the shell command `id` should succeed
|
|
7
|
+
And the stdout of that shell command should match /vagrant/
|
|
8
|
+
And the stdout of that shell command should not match /root/
|
|
9
|
+
And the stderr of that shell command should match /^$/
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
Scenario: Check we can run commands as root
|
|
13
|
+
|
|
14
|
+
Given there is a running VM called "vm1"
|
|
15
|
+
Then running the shell command `id` as root should succeed
|
|
16
|
+
And the stdout of that shell command should match /root/
|
|
17
|
+
And the stdout of that shell command should not match /vagrant/
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
Scenario: Write a file so that we can check we're rolling back properly
|
|
21
|
+
|
|
22
|
+
Given there is a running VM called "vm1"
|
|
23
|
+
|
|
24
|
+
Then running the shell command `grep test /tmp/cucumber-written-file` should fail
|
|
25
|
+
|
|
26
|
+
When I run the shell command `echo test > /tmp/cucumber-written-file`, it should succeed
|
|
27
|
+
And running the shell command `grep test /tmp/cucumber-written-file` should succeed
|
|
28
|
+
|
|
29
|
+
When I roll back the VM called "vm1"
|
|
30
|
+
Then running the shell command `grep test /tmp/cucumber-written-file` should fail
|
|
31
|
+
|
|
32
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Feature: Testing on multiple VMs
|
|
2
|
+
|
|
3
|
+
@vagrant-cucumber-debug
|
|
4
|
+
Scenario: Check we can run simple commands on multiple VMs
|
|
5
|
+
|
|
6
|
+
Given there is a running VM called "vm1"
|
|
7
|
+
And there is a running VM called "vm2"
|
|
8
|
+
|
|
9
|
+
# The following four steps are equivalent
|
|
10
|
+
Then running the shell command `hostname` on the VM called "vm1" should succeed
|
|
11
|
+
Then running the shell command `hostname` on the VM "vm1" should succeed
|
|
12
|
+
And running the shell command `hostname` on the last VM should succeed
|
|
13
|
+
And running the shell command `hostname` should succeed
|
|
14
|
+
|
|
15
|
+
And running the shell command `hostname` on the VM "vm2" should succeed
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Feature: Check to see if processes are running in the VM
|
|
2
|
+
|
|
3
|
+
Scenario: Check that init is running
|
|
4
|
+
Given there is a running VM called "vm1"
|
|
5
|
+
Then there should be a process called "init" running
|
|
6
|
+
|
|
7
|
+
Scenario: Check that non-existant process check also works
|
|
8
|
+
Given there is a running VM called "vm1"
|
|
9
|
+
Then there should not be a process called "i-dont-exist" running
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# Cucumber step definitions are defined like function definitions, and start
|
|
2
|
+
# with a preposition or adverb (Given, When, Then, And, But).
|
|
3
|
+
#
|
|
4
|
+
# The regular expression defined will be matched against steps in the feature
|
|
5
|
+
# files when cucumber runs. The matched groups in the regex will be passed
|
|
6
|
+
# in order as variables to the block. In this case, the three groups are
|
|
7
|
+
# assigned to "condition", "process_name" and "vmre"
|
|
8
|
+
#
|
|
9
|
+
# More information on step definitions can be found at
|
|
10
|
+
# https://github.com/cucumber/cucumber/wiki/Step-Definitions
|
|
11
|
+
|
|
12
|
+
Then /there should(| not) be a process called "([^"]*)" running(#{VMRE})$/ do |condition, process_name, vmre|
|
|
13
|
+
|
|
14
|
+
# First, we work out what virtual machine we're going to be dealing with
|
|
15
|
+
# in this step. The VMRE variable in the regex above is defined by
|
|
16
|
+
# vagrant-cucumber to match various English-language ways in which we
|
|
17
|
+
# might refer to a vagrant box:
|
|
18
|
+
#
|
|
19
|
+
# String matched VM identified
|
|
20
|
+
# -------------------------------------------------------------------
|
|
21
|
+
# '' Last referenced
|
|
22
|
+
# 'on the last VM' Last referenced
|
|
23
|
+
# 'on the VM "<vmname>"' Named <vmname>
|
|
24
|
+
# 'on the VM called "<vmname>"' Named <vmname>
|
|
25
|
+
#
|
|
26
|
+
# The call to vagrant_glue.identified_vm returns a Vagrant::Machine
|
|
27
|
+
# object to the relevant VM.
|
|
28
|
+
|
|
29
|
+
machine = vagrant_glue.identified_vm(vmre)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# Now we use the machine's communication interface (probably ssh, though
|
|
33
|
+
# this is provider-dependent) to execute a shell command inside the VM.
|
|
34
|
+
|
|
35
|
+
machine.communicate.tap do |comm|
|
|
36
|
+
|
|
37
|
+
rv = comm.execute(
|
|
38
|
+
"pidof #{process_name}", {
|
|
39
|
+
:error_check => false, # stop vagrant throwing an exception
|
|
40
|
+
} # if the command returns non-zero
|
|
41
|
+
|
|
42
|
+
) do |type,data|
|
|
43
|
+
|
|
44
|
+
# Execute takes a block, which is yielded to whenever there's
|
|
45
|
+
# output on stdout or stderr. We handle any output in this block.
|
|
46
|
+
#
|
|
47
|
+
# In this case, we'll put all output onto stdout, but only if
|
|
48
|
+
# @vagrant_cucumber_debug has been set. This class variable will
|
|
49
|
+
# be set to true in the Before hook defined in
|
|
50
|
+
# lib/vagrant-cucumber/step_definitions.rb
|
|
51
|
+
|
|
52
|
+
if @vagrant_cucumber_debug
|
|
53
|
+
puts "[:#{type}] #{data.chomp}"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Output the status from the command if we're in debugging mode
|
|
59
|
+
if @vagrant_cucumber_debug
|
|
60
|
+
puts "Exit status of pidof command: #{rv}"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Cucumber steps are expected to exit cleanly if they worked ok, and
|
|
64
|
+
# raise exceptions if they fail. The following logic implements
|
|
65
|
+
# the conditions in which we want to fail the step.
|
|
66
|
+
|
|
67
|
+
if rv != 0 and condition == ''
|
|
68
|
+
raise "There was no proces called #{process_name} running on #{machine.name}"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
if rv == 0 and condition == ' not'
|
|
72
|
+
raise "There was a process called #{process_name} running on #{machine.name}"
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module VagrantPlugins
|
|
2
|
+
module Cucumber
|
|
3
|
+
class CucumberCommand < Vagrant.plugin(2, :command)
|
|
4
|
+
|
|
5
|
+
def execute
|
|
6
|
+
|
|
7
|
+
require 'cucumber/rspec/disable_option_parser'
|
|
8
|
+
require 'cucumber/cli/main'
|
|
9
|
+
|
|
10
|
+
require 'vagrant-cucumber/cucumber/formatter/pretty'
|
|
11
|
+
require 'vagrant-cucumber/cucumber/formatter/html'
|
|
12
|
+
|
|
13
|
+
failure = ::Cucumber::Cli::Main.execute(@argv)
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'cucumber/formatter/html'
|
|
2
|
+
|
|
3
|
+
module VagrantPlugins
|
|
4
|
+
|
|
5
|
+
module Cucumber
|
|
6
|
+
|
|
7
|
+
module Formatter
|
|
8
|
+
|
|
9
|
+
class Html < ::Cucumber::Formatter::Html
|
|
10
|
+
|
|
11
|
+
def puts(message)
|
|
12
|
+
# TODO Strip ansi escape codes
|
|
13
|
+
@delayed_messages << message
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'cucumber/formatter/pretty'
|
|
2
|
+
|
|
3
|
+
module VagrantPlugins
|
|
4
|
+
|
|
5
|
+
module Cucumber
|
|
6
|
+
|
|
7
|
+
module Formatter
|
|
8
|
+
|
|
9
|
+
class Pretty < ::Cucumber::Formatter::Pretty
|
|
10
|
+
|
|
11
|
+
# Use the Pretty formatter, but disable use of
|
|
12
|
+
# delayed messages (ie. output each line at once)
|
|
13
|
+
|
|
14
|
+
def initialize(*args)
|
|
15
|
+
super
|
|
16
|
+
@delayed_messages = nil
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# print_messages is only used to output the delayed_messages
|
|
20
|
+
# and fails because of the above hack, so make it a noop
|
|
21
|
+
|
|
22
|
+
def print_messages
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
unless defined?(VMRE)
|
|
2
|
+
VMRE = /(?: on the last VM| on the VM(?: called|) "(?:[^"]+)"|)/
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
module VagrantPlugins
|
|
6
|
+
|
|
7
|
+
module Cucumber
|
|
8
|
+
|
|
9
|
+
module Glue
|
|
10
|
+
|
|
11
|
+
# This glue module will be used in the cucumber World for
|
|
12
|
+
# tests run with vagrant-cucumber. It's used to hide interaction
|
|
13
|
+
# with the messier parts of the vagrant environment so the
|
|
14
|
+
# step definitions don't need to care about them.
|
|
15
|
+
|
|
16
|
+
def vagrant_glue
|
|
17
|
+
VagrantGlue.instance
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class VagrantGlue
|
|
21
|
+
|
|
22
|
+
def initialize
|
|
23
|
+
|
|
24
|
+
@vagrant_env = Vagrant::Environment.new(
|
|
25
|
+
:ui_class => Vagrant::UI::Basic
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
@last_machine_mentioned = nil
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.instance
|
|
33
|
+
return @@instance ||= VagrantGlue.new
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def vagrant_env
|
|
37
|
+
@vagrant_env
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def get_last_vm
|
|
41
|
+
get_vm( @last_machine_mentioned )
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def get_vm( vmname )
|
|
45
|
+
|
|
46
|
+
machine_provider = nil
|
|
47
|
+
machine_name = nil
|
|
48
|
+
|
|
49
|
+
# If this machine name is not configured, blow up
|
|
50
|
+
if ! @vagrant_env.machine_names.index(vmname.to_sym)
|
|
51
|
+
raise Vagrant::Errors::VMNotFoundError, :name => vmname
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
@vagrant_env.active_machines.each do |a_name, a_provider|
|
|
55
|
+
|
|
56
|
+
if a_name == vmname.to_sym
|
|
57
|
+
machine_provider = a_provider
|
|
58
|
+
machine_name = a_name
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
if !machine_name
|
|
64
|
+
|
|
65
|
+
raise "The VM '#{vmname}' is configured in the Vagrantfile "+
|
|
66
|
+
"but has not been started. Run 'vagrant up #{vmname}' and "+
|
|
67
|
+
"specify a provider if necessary."
|
|
68
|
+
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
machine_provider ||= vagrant_env.default_provider
|
|
72
|
+
machine = @vagrant_env.machine(
|
|
73
|
+
machine_name, machine_provider
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
@last_machine_mentioned = vmname
|
|
77
|
+
|
|
78
|
+
machine
|
|
79
|
+
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def identified_vm( str )
|
|
83
|
+
case str
|
|
84
|
+
when /^( on the last VM|)$/
|
|
85
|
+
get_last_vm
|
|
86
|
+
when /^ on the VM(?: called|) "([^"]+)"$/
|
|
87
|
+
get_vm( $1 )
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
end
|
|
99
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require "vagrant"
|
|
3
|
+
rescue LoadError
|
|
4
|
+
raise "The Vagrant Cucumber plugin must be run within Vagrant."
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
module VagrantPlugins
|
|
8
|
+
module Cucumber
|
|
9
|
+
class Plugin < Vagrant.plugin("2")
|
|
10
|
+
|
|
11
|
+
name "Cucumber"
|
|
12
|
+
|
|
13
|
+
description <<-DESC
|
|
14
|
+
This plugin makes it possible for Cucumber to interact with Vagrant
|
|
15
|
+
DESC
|
|
16
|
+
|
|
17
|
+
command "cucumber" do
|
|
18
|
+
require_relative "commands/cucumber"
|
|
19
|
+
CucumberCommand
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
require 'to_regexp'
|
|
2
|
+
|
|
3
|
+
Given /^there is a running VM called "([^"]*)"$/ do |vmname|
|
|
4
|
+
|
|
5
|
+
machine = vagrant_glue.get_vm( vmname )
|
|
6
|
+
|
|
7
|
+
machine.action(:up)
|
|
8
|
+
|
|
9
|
+
unless machine.provider.driver.has_snapshot?
|
|
10
|
+
machine.action(:snapshot_take)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
When /^I roll back the VM called "([^"]*)"$/ do |vmname|
|
|
16
|
+
|
|
17
|
+
machine = vagrant_glue.get_vm( vmname )
|
|
18
|
+
vagrant_glue.vagrant_env.cli('snap', 'rollback', vmname )
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
Then /^(?:running|I run) the shell command `(.*)`(| as root)(#{VMRE})(?:|, it) should (succeed|fail)$/ do |command,as_root,vmre,condition|
|
|
23
|
+
|
|
24
|
+
@last_shell_command_output = {
|
|
25
|
+
:stdout => '',
|
|
26
|
+
:stderr => '',
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@last_shell_command_status = nil
|
|
30
|
+
|
|
31
|
+
machine = vagrant_glue.identified_vm(vmre)
|
|
32
|
+
machine.communicate.tap do |comm|
|
|
33
|
+
|
|
34
|
+
@last_shell_command_status = comm.execute(
|
|
35
|
+
command, {
|
|
36
|
+
:error_check => false,
|
|
37
|
+
:sudo => as_root == ' as root',
|
|
38
|
+
}
|
|
39
|
+
) do |type,data|
|
|
40
|
+
|
|
41
|
+
if @vagrant_cucumber_debug
|
|
42
|
+
puts "[:#{type}] #{data.chomp}"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
@last_shell_command_output[type] += data
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
if @last_shell_command_status == 0 and condition == 'fail'
|
|
52
|
+
raise "Expected command to fail, but got 0 exit status"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
if @last_shell_command_status != 0 and condition == 'succeed'
|
|
56
|
+
raise "Expected command to succeed but got #{@last_shell_command_status} exit status"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
Then /^the (.+) of that shell command should(| not) match (\/.+\/)$/ do |stream,condition,re|
|
|
62
|
+
|
|
63
|
+
stream.downcase!
|
|
64
|
+
|
|
65
|
+
unless @last_shell_command_output.has_key?( stream.to_sym )
|
|
66
|
+
raise "@last_shell_command_output structure has no #{stream}"
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
re_result = ( @last_shell_command_output[stream.to_sym] =~ re.to_regexp )
|
|
70
|
+
re_matched = !re_result.nil?
|
|
71
|
+
|
|
72
|
+
should_match = condition != ' not'
|
|
73
|
+
|
|
74
|
+
if re_matched and !should_match
|
|
75
|
+
raise "Regular expression matched, but shouldn't have"
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
if !re_matched and should_match
|
|
79
|
+
raise "Regular expression didn't match, but should have"
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
Before('@norollback') do |scenario|
|
|
85
|
+
puts "Saw @norollback tag:"
|
|
86
|
+
puts " * Won't roll back snapshot at end of scenario"
|
|
87
|
+
puts " * Will roll back explicit snapshots in the scenario"
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
After('~@norollback') do |scenario|
|
|
93
|
+
|
|
94
|
+
puts "Rolling back VM states"
|
|
95
|
+
vagrant_glue.vagrant_env.cli('snap', 'rollback' )
|
|
96
|
+
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
After('@norollback') do |scenario|
|
|
100
|
+
puts "Saw @norollback tag - not rolling back"
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
Before('@vagrant-cucumber-debug') do |scenario|
|
|
104
|
+
puts "Enabling debugging for vagrant-cucumber scenarios"
|
|
105
|
+
@vagrant_cucumber_debug = true
|
|
106
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
3
|
+
require "vagrant-cucumber/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.name = "vagrant-cucumber"
|
|
7
|
+
s.version = VagrantPlugins::Cucumber::VERSION
|
|
8
|
+
s.authors = ["Jon Topper"]
|
|
9
|
+
s.email = ["jon@scalefactory.com"]
|
|
10
|
+
s.homepage = "https://github.com/scalefactory/vagrant-cucumber"
|
|
11
|
+
s.summary = %q{Cucumber support for Vagrant}
|
|
12
|
+
s.description = %q{This plugin makes it possible for Cucumber to interact with Vagrant}
|
|
13
|
+
|
|
14
|
+
s.rubyforge_project = "vagrant-cucumber"
|
|
15
|
+
|
|
16
|
+
files = `git ls-files`.split("\n")
|
|
17
|
+
ignore = %w{Gemfile Rakefile .gitignore}
|
|
18
|
+
|
|
19
|
+
files.delete_if do |f|
|
|
20
|
+
ignore.any? do |i|
|
|
21
|
+
File.fnmatch(i, f, File::FNM_PATHNAME) ||
|
|
22
|
+
File.fnmatch(i, File.basename(f), File::FNM_PATHNAME)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
s.add_runtime_dependency "cucumber", ">=1.3.2"
|
|
27
|
+
s.add_runtime_dependency "vagrant-zz-multiprovider-snap", ">=0.0.3"
|
|
28
|
+
|
|
29
|
+
s.files = files
|
|
30
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
31
|
+
s.require_paths = ["lib"]
|
|
32
|
+
|
|
33
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: vagrant-cucumber
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Jon Topper
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2013-07-02 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: cucumber
|
|
16
|
+
requirement: &70146505916660 !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: 1.3.2
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: *70146505916660
|
|
25
|
+
- !ruby/object:Gem::Dependency
|
|
26
|
+
name: vagrant-zz-multiprovider-snap
|
|
27
|
+
requirement: &70146505916160 !ruby/object:Gem::Requirement
|
|
28
|
+
none: false
|
|
29
|
+
requirements:
|
|
30
|
+
- - ! '>='
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 0.0.3
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: *70146505916160
|
|
36
|
+
description: This plugin makes it possible for Cucumber to interact with Vagrant
|
|
37
|
+
email:
|
|
38
|
+
- jon@scalefactory.com
|
|
39
|
+
executables: []
|
|
40
|
+
extensions: []
|
|
41
|
+
extra_rdoc_files: []
|
|
42
|
+
files:
|
|
43
|
+
- CHANGELOG.md
|
|
44
|
+
- README.md
|
|
45
|
+
- example/Vagrantfile
|
|
46
|
+
- example/features/basic.feature
|
|
47
|
+
- example/features/multivm.feature
|
|
48
|
+
- example/features/process.feature
|
|
49
|
+
- example/features/step_definitions/process.rb
|
|
50
|
+
- example/features/support/env.rb
|
|
51
|
+
- lib/vagrant-cucumber.rb
|
|
52
|
+
- lib/vagrant-cucumber/commands/cucumber.rb
|
|
53
|
+
- lib/vagrant-cucumber/cucumber/formatter/html.rb
|
|
54
|
+
- lib/vagrant-cucumber/cucumber/formatter/pretty.rb
|
|
55
|
+
- lib/vagrant-cucumber/glue.rb
|
|
56
|
+
- lib/vagrant-cucumber/plugin.rb
|
|
57
|
+
- lib/vagrant-cucumber/step_definitions.rb
|
|
58
|
+
- lib/vagrant-cucumber/version.rb
|
|
59
|
+
- vagrant-cucumber.gemspec
|
|
60
|
+
homepage: https://github.com/scalefactory/vagrant-cucumber
|
|
61
|
+
licenses: []
|
|
62
|
+
post_install_message:
|
|
63
|
+
rdoc_options: []
|
|
64
|
+
require_paths:
|
|
65
|
+
- lib
|
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
67
|
+
none: false
|
|
68
|
+
requirements:
|
|
69
|
+
- - ! '>='
|
|
70
|
+
- !ruby/object:Gem::Version
|
|
71
|
+
version: '0'
|
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
|
+
none: false
|
|
74
|
+
requirements:
|
|
75
|
+
- - ! '>='
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: '0'
|
|
78
|
+
requirements: []
|
|
79
|
+
rubyforge_project: vagrant-cucumber
|
|
80
|
+
rubygems_version: 1.8.11
|
|
81
|
+
signing_key:
|
|
82
|
+
specification_version: 3
|
|
83
|
+
summary: Cucumber support for Vagrant
|
|
84
|
+
test_files: []
|