vagrant-rspec-ci 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/README.md +97 -0
- data/lib/vagrant-rspec-ci.rb +33 -0
- data/lib/vagrant-rspec-ci/command.rb +93 -0
- data/lib/vagrant-rspec-ci/config.rb +58 -0
- data/lib/vagrant_init.rb +1 -0
- metadata +83 -0
data/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# vagrant-rspec-ci
|
|
2
|
+
|
|
3
|
+
**vagrant-rspec-ci** is a Vagrant plugin for running integration tests against
|
|
4
|
+
your VMs, and produces jUnit formatted reports for consumption by your CI server
|
|
5
|
+
(travis and Jenkins and both can consume this).
|
|
6
|
+
|
|
7
|
+
It is based on a fork of Michael Paul Thomas Conigliaro's vagrant-test plugin, with
|
|
8
|
+
some (very) breaking changes to make it rpsec-specific and integrate better with ci_reporter
|
|
9
|
+
(the jUnit report formatter). I also removed the internal side of testing, as we didn't
|
|
10
|
+
want to alter the test subject (by installing rspec internally in the VM, for example)
|
|
11
|
+
|
|
12
|
+
## Installation (Vagrant v1.0.x)
|
|
13
|
+
|
|
14
|
+
vagrant gem install vagrant-rspec-ci
|
|
15
|
+
|
|
16
|
+
## Configuration
|
|
17
|
+
|
|
18
|
+
The following options can be used within the `Vagrant::Config.run` block of
|
|
19
|
+
your Vagrantfile:
|
|
20
|
+
|
|
21
|
+
<table>
|
|
22
|
+
<tr>
|
|
23
|
+
<th>Option</th>
|
|
24
|
+
<th>Description</th>
|
|
25
|
+
<th>Default value</th>
|
|
26
|
+
</tr>
|
|
27
|
+
<tr>
|
|
28
|
+
<td>config.rspec.enable_ci_reporter</td>
|
|
29
|
+
<td>Boolean - whether to use ci_reporter to format rspec results as jUnit reports.</td>
|
|
30
|
+
<td>true</td>
|
|
31
|
+
</tr>
|
|
32
|
+
<tr>
|
|
33
|
+
<td>config.rspec.suppress_ci_stdout</td>
|
|
34
|
+
<td>ci_reporter improperly registers as a formatter, writes to files, but leaves the doc formatter in place. This makes for very noisy output. Set to true (default) to send all STDOUT formatter output from rspec to /dev/null ; set to false when diagnosing a problem, or if you like noise.</td>
|
|
35
|
+
<td>true</td>
|
|
36
|
+
</tr>
|
|
37
|
+
|
|
38
|
+
<tr>
|
|
39
|
+
<td>config.rspec.dirs</td>
|
|
40
|
+
<td>Array of directories (relative to vagrant project root) to be used as a search path for external tests.</td>
|
|
41
|
+
<td>['combined/spec_ext", "spec"]</td>
|
|
42
|
+
</tr>
|
|
43
|
+
<tr>
|
|
44
|
+
<td>config.rspec.tests</td>
|
|
45
|
+
<td>List of tests (filenames or globs, expanded in the dirs paths) to be run outside the VM</td>
|
|
46
|
+
<td>[ '*ext_spec.rb' ]</td>
|
|
47
|
+
</tr>
|
|
48
|
+
<tr>
|
|
49
|
+
<td>config.rspec.rspec_bin_path</td>
|
|
50
|
+
<td>Path to rspec command, on VM host</td>
|
|
51
|
+
<td>"rspec"</td>
|
|
52
|
+
</tr>
|
|
53
|
+
<tr>
|
|
54
|
+
<td>config.rspec.reports_dir</td>
|
|
55
|
+
<td>If ci_reporter is enabled, path to write the jUnit XML reports. Relative to vagrant project dir.</td>
|
|
56
|
+
<td>"rspec_reports"</td>
|
|
57
|
+
</tr>
|
|
58
|
+
|
|
59
|
+
## Usage
|
|
60
|
+
|
|
61
|
+
vagrant rspec [vm-name]
|
|
62
|
+
|
|
63
|
+
## Change Log
|
|
64
|
+
|
|
65
|
+
### 0.0.1 (2013-04-09)
|
|
66
|
+
|
|
67
|
+
* Forked from v0.1.2 of vagrant-test
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
Copyright (C) 2013 Clinton Wolfe
|
|
72
|
+
|
|
73
|
+
Copyright (C) 2012 Michael Paul Thomas Conigliaro
|
|
74
|
+
|
|
75
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
76
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
77
|
+
the Software without restriction, including without limitation the rights to
|
|
78
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
79
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
80
|
+
so, subject to the following conditions:
|
|
81
|
+
|
|
82
|
+
The above copyright notice and this permission notice shall be included in all
|
|
83
|
+
copies or substantial portions of the Software.
|
|
84
|
+
|
|
85
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
86
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
87
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
88
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
89
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
90
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
91
|
+
SOFTWARE.
|
|
92
|
+
|
|
93
|
+
## Credits
|
|
94
|
+
|
|
95
|
+
* [Clinton Wolfe](http://ccwolfe.com): Derivative author of vagrant-rspec-ci
|
|
96
|
+
|
|
97
|
+
* [Michael Paul Thomas Conigliaro](http://conigliaro.org): Original author of vagrant-test
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require "rubygems"
|
|
2
|
+
|
|
3
|
+
require "vagrant"
|
|
4
|
+
require "vagrant/util/subprocess"
|
|
5
|
+
require "vagrant-rspec-ci/config"
|
|
6
|
+
require "vagrant-rspec-ci/command"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
require "pry-debugger"
|
|
11
|
+
|
|
12
|
+
module VagrantRspecCI
|
|
13
|
+
|
|
14
|
+
NAME = "vagrant-rspec-ci"
|
|
15
|
+
VERSION = "0.0.1"
|
|
16
|
+
AUTHOR = "Clinton Wolfe"
|
|
17
|
+
AUTHOR_EMAIL = "clintoncwolfe [at] gmail [dot] com"
|
|
18
|
+
DESCRIPTION = "vagrant-rspec-ci is a Vagrant plugin for running tests against your VMs, derived from vagrant-test"
|
|
19
|
+
URL = "http://github.com/clintoncwolfe/vagrant-rspec-ci"
|
|
20
|
+
|
|
21
|
+
V_ROOT = "/vagrant"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
DEFAULT_RSPEC_BIN_PATH = "rspec"
|
|
25
|
+
DEFAULT_REPORTS_DIR = "rspec_reports"
|
|
26
|
+
DEFAULT_DIRS = [ "combined/spec_ext", "spec" ]
|
|
27
|
+
DEFAULT_TESTS = [ "*spec.rb" ]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
Vagrant.config_keys.register(:rspec) { VagrantRspecCI::Config }
|
|
33
|
+
Vagrant.commands.register(:rspec) { VagrantRspecCI::Command }
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
module VagrantRspecCI
|
|
2
|
+
|
|
3
|
+
class Command < Vagrant::Command::Base
|
|
4
|
+
|
|
5
|
+
def execute
|
|
6
|
+
opts = OptionParser.new do |opts|
|
|
7
|
+
opts.banner = "Usage: vagrant rpsec [vm-name]"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
argv = parse_options(opts)
|
|
11
|
+
return if !argv
|
|
12
|
+
|
|
13
|
+
with_target_vms(argv[0]) do |vm|
|
|
14
|
+
vm.env.action_runner.run(Vagrant::Action::General::Validate, {:vm=>vm, :ui=>vm.ui})
|
|
15
|
+
|
|
16
|
+
if !vm.created? || vm.state != :running
|
|
17
|
+
vm.ui.error("VM not running. Not running tests.")
|
|
18
|
+
else
|
|
19
|
+
|
|
20
|
+
tests = expand_test_list(vm.config.rspec)
|
|
21
|
+
cmd = rspec_command(vm)
|
|
22
|
+
tests.each do |testfile|
|
|
23
|
+
vm.ui.info("Running rspec test: #{testfile}")
|
|
24
|
+
cmd = "#{cmd} #{testfile}"
|
|
25
|
+
@logger.debug("Command: #{cmd}")
|
|
26
|
+
system({ "CI_REPORTS" => vm.config.rspec.reports_dir } , cmd)
|
|
27
|
+
result = $?
|
|
28
|
+
# rspec exits 0 if all passed, 1 if some failed - and system gives nil if there was a problem starting the process
|
|
29
|
+
if result.nil? then
|
|
30
|
+
vm.ui.error "Unable to execute rspec command: #{$!} \n #{cmd}"
|
|
31
|
+
elsif result.exitstatus == 1 then
|
|
32
|
+
vm.ui.warn "Rspec test #{testfile} has at least one failure - see report output for details"
|
|
33
|
+
elsif result.exitstatus == 0 then
|
|
34
|
+
vm.ui.success "Rspec test #{testfile} passed"
|
|
35
|
+
else
|
|
36
|
+
vm.ui.error "Unrecognized exit code from rspec: #{result.exitstatus}\nfor:#{cmd}"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
if tests.empty?
|
|
41
|
+
vm.ui.info("No rspec tests found.")
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
def expand_test_list (rspec_config)
|
|
50
|
+
tests = rspec_config.tests.map { |filespec|
|
|
51
|
+
rspec_config.dirs.find_all { |dir| File.directory?(dir) }.map { |dir|
|
|
52
|
+
Dir.glob(File.join(dir, filespec))
|
|
53
|
+
}
|
|
54
|
+
}.flatten.uniq
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def rspec_command (vm)
|
|
58
|
+
# Use gemset provided by Vagrant
|
|
59
|
+
# Cribbed from https://github.com/mitchellh/vagrant/blob/1-0-stable/lib/vagrant/command/gem.rb
|
|
60
|
+
ENV['GEM_HOME'] = vm.env.gems_path.to_s
|
|
61
|
+
::Gem.clear_paths
|
|
62
|
+
|
|
63
|
+
use_cir = vm.config.rspec.enable_ci_reporter
|
|
64
|
+
|
|
65
|
+
# Find ci_reporter rspec hook
|
|
66
|
+
if use_cir then
|
|
67
|
+
ci_hook_candidates = ::Gem.find_files('ci/reporter/rake/rspec_loader')
|
|
68
|
+
|
|
69
|
+
# TODO - bad assumption here, but if we find more than one, let's assume we can sort them and use the latest version.
|
|
70
|
+
ci_hook_path = (ci_hook_candidates.sort)[-1]
|
|
71
|
+
|
|
72
|
+
unless ci_hook_path then
|
|
73
|
+
raise "Could not find ci_reporter rspec hook - I expect ci_reporter to be installed as a gem under vagrant!"
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Find rspec
|
|
78
|
+
# TODO - even when you install it as a vagrant gem, it is not present in ::Gem.bindir :(
|
|
79
|
+
# Cross fingers?
|
|
80
|
+
rspec_path = vm.config.rspec.rspec_bin_path
|
|
81
|
+
|
|
82
|
+
cmd = ""
|
|
83
|
+
cmd << rspec_path
|
|
84
|
+
cmd << (use_cir ? " --require " + ci_hook_path + " --format CI::Reporter::RSpec" : "")
|
|
85
|
+
cmd << (use_cir && vm.config.rspec.suppress_ci_stdout ? " -o /dev/null " : "")
|
|
86
|
+
cmd << vm.config.rspec.dirs.map{ |d| " -I #{d}" }.join('')
|
|
87
|
+
|
|
88
|
+
cmd
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
module VagrantRspecCI
|
|
2
|
+
|
|
3
|
+
class Config < Vagrant::Config::Base
|
|
4
|
+
|
|
5
|
+
attr_writer :enable_ci_reporter,
|
|
6
|
+
:suppress_ci_stdout,
|
|
7
|
+
:rspec_bin_path,
|
|
8
|
+
:reports_dir,
|
|
9
|
+
:dirs,
|
|
10
|
+
:tests
|
|
11
|
+
|
|
12
|
+
def enable_ci_reporter
|
|
13
|
+
@enable_ci_reporter.nil? ? true : @enable_ci_reporter
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def suppress_ci_stdout
|
|
17
|
+
@suppress_ci_stdout.nil? ? true : @suppress_ci_stdout
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def rspec_bin_path
|
|
21
|
+
@rpsec_bin_path || DEFAULT_RSPEC_BIN_PATH
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def reports_dir
|
|
25
|
+
@reports_dir || DEFAULT_REPORTS_DIR
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def dirs
|
|
29
|
+
@dirs || DEFAULT_DIRS
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def tests
|
|
33
|
+
@tests || DEFAULT_TESTS
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def validate(env, errors)
|
|
37
|
+
|
|
38
|
+
[
|
|
39
|
+
:dirs,
|
|
40
|
+
:tests,
|
|
41
|
+
].each do |thing_sym|
|
|
42
|
+
# Each of these should be an array or enumerable.
|
|
43
|
+
value = self.send(thing_sym)
|
|
44
|
+
unless value.respond_to?(:each) then
|
|
45
|
+
errors.add("config.rspec.#{thing_sym} should be an array")
|
|
46
|
+
return
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Must find at least one of the directory defaults
|
|
51
|
+
edir = self.dirs.find {|d| File.directory?(d) }
|
|
52
|
+
errors.add("No test directory found - candidates: #{self.dirs.join(',')}") unless edir
|
|
53
|
+
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
end
|
data/lib/vagrant_init.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "vagrant-rspec-ci"
|
metadata
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: vagrant-rspec-ci
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Clinton Wolfe
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2013-04-10 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: vagrant
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: 0.9.0
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ! '>='
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: 0.9.0
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: rspec
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
none: false
|
|
34
|
+
requirements:
|
|
35
|
+
- - ! '>='
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
type: :runtime
|
|
39
|
+
prerelease: false
|
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ! '>='
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '0'
|
|
46
|
+
description: vagrant-rspec-ci is a Vagrant plugin for running tests against your VMs,
|
|
47
|
+
derived from vagrant-test
|
|
48
|
+
email: clintoncwolfe [at] gmail [dot] com
|
|
49
|
+
executables: []
|
|
50
|
+
extensions: []
|
|
51
|
+
extra_rdoc_files: []
|
|
52
|
+
files:
|
|
53
|
+
- README.md
|
|
54
|
+
- lib/vagrant_init.rb
|
|
55
|
+
- lib/vagrant-rspec-ci/command.rb
|
|
56
|
+
- lib/vagrant-rspec-ci/config.rb
|
|
57
|
+
- lib/vagrant-rspec-ci.rb
|
|
58
|
+
homepage: http://github.com/clintoncwolfe/vagrant-rspec-ci
|
|
59
|
+
licenses: []
|
|
60
|
+
post_install_message:
|
|
61
|
+
rdoc_options: []
|
|
62
|
+
require_paths:
|
|
63
|
+
- lib
|
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
65
|
+
none: false
|
|
66
|
+
requirements:
|
|
67
|
+
- - ! '>='
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '0'
|
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
|
+
none: false
|
|
72
|
+
requirements:
|
|
73
|
+
- - ! '>='
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
requirements: []
|
|
77
|
+
rubyforge_project: vagrant-rspec-ci
|
|
78
|
+
rubygems_version: 1.8.24
|
|
79
|
+
signing_key:
|
|
80
|
+
specification_version: 3
|
|
81
|
+
summary: vagrant-rspec-ci is a Vagrant plugin for running tests against your VMs,
|
|
82
|
+
derived from vagrant-test
|
|
83
|
+
test_files: []
|