Skip to content

Commit

Permalink
Merge pull request #148 from test-kitchen/spec-coverage
Browse files Browse the repository at this point in the history
Add full spec coverge to codebase.
  • Loading branch information
fnichol committed Mar 10, 2015
2 parents 9f9b502 + 596cbd6 commit 46faf19
Show file tree
Hide file tree
Showing 9 changed files with 1,094 additions and 81 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ matrix:

notifications:
irc: "chat.freenode.net#kitchenci"

addons:
code_climate:
repo_token:
secure: "jVI7J+yiQcD5T1YNz9eGReGf6vyp8VIGjsyMEM0HBOxrbk4iCm7P5SN5n5cJPRZNzQd175ceqcpPisvJh91oPMetzpmN+PSDPhOzxVNB4rIqQ8ohJNX2jW/VVpaobzWHAQQurC349gfi2a6l7MvgZw3RGyExkacZXdqr+Bbsc38="
7 changes: 6 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@ source "https://rubygems.org"
gemspec

group :guard do
gem "guard-rubocop"
gem "guard-rspec", :require => nil
gem "guard-rubocop", :require => nil
end

group :test do
gem "codeclimate-test-reporter", :require => nil
end
10 changes: 10 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
# -*- encoding: utf-8 -*-
ignore %r{^\.gem/}

def rspec_opts
{ :cmd => "bundle exec rspec" }
end

def rubocop_opts
{ :all_on_start => false, :keep_failed => false, :cli => "-r finstyle" }
end

group :red_green_refactor, :halt_on_fail => true do
guard :rspec, rspec_opts do
watch(%r{^spec/(.*)_spec\.rb})
watch(%r{^lib/(.*)([^/]+)\.rb}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^spec/spec_helper\.rb}) { "spec" }
end

guard :rubocop, rubocop_opts do
watch(%r{.+\.rb$})
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
Expand Down
27 changes: 20 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
# -*- encoding: utf-8 -*-

require "bundler/gem_tasks"

require "rspec/core/rake_task"
desc "Run all specs in spec directory"
RSpec::Core::RakeTask.new(:spec) do |t|
t.pattern = "spec/**/*_spec.rb"
end

desc "Run all test suites"
task :test => [:spec]

require "cane/rake_task"
desc "Run cane to check quality metrics"
Cane::RakeTask.new do |cane|
cane.canefile = "./.cane"
end

desc "Display LOC stats"
task :stats do
puts "\n## Production Code Stats"
sh "countloc -r lib/kitchen"
end

require "finstyle"
require "rubocop/rake_task"
RuboCop::RakeTask.new(:style) do |task|
task.options << "--display-cop-names"
end

desc "Display LOC stats"
task :stats do
puts "\n## Production Code Stats"
sh "countloc -r lib/kitchen"
puts "\n## Test Code Stats"
sh "countloc -r spec"
end

desc "Run all quality tasks"
task :quality => [:cane, :style, :stats]

task :default => [:quality]
task :default => [:test, :quality]
4 changes: 3 additions & 1 deletion kitchen-vagrant.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ Gem::Specification.new do |gem|

gem.add_dependency "test-kitchen", "~> 1.0"

gem.add_development_dependency "countloc", "~> 0.4"
gem.add_development_dependency "rake"
gem.add_development_dependency "countloc", "~> 0.4"
gem.add_development_dependency "rspec", "~> 3.2"
gem.add_development_dependency "simplecov", "~> 0.9"

# style and complexity libraries are tightly version pinned as newer releases
# may introduce new and undesireable style choices which would be immediately
Expand Down
84 changes: 25 additions & 59 deletions lib/kitchen/driver/vagrant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ class Vagrant < Kitchen::Driver::SSHBase

default_config :provision, false

default_config :provider,
default_config :provider do |_|
ENV.fetch("VAGRANT_DEFAULT_PROVIDER", "virtualbox")
end

default_config :ssh, {}

Expand All @@ -66,15 +67,6 @@ class Vagrant < Kitchen::Driver::SSHBase

no_parallel_for :create, :destroy

# Converges a running instance.
#
# @param state [Hash] mutable instance and driver state
# @raise [ActionFailed] if the action could not be completed
def converge(state)
create_vagrantfile
super
end

# Creates a Vagrant VM instance.
#
# @param state [Hash] mutable instance and driver state
Expand All @@ -84,7 +76,7 @@ def create(state)
run_pre_create_command
cmd = "vagrant up"
cmd += " --no-provision" unless config[:provision]
cmd += " --provider=#{config[:provider]}" if config[:provider]
cmd += " --provider #{config[:provider]}" if config[:provider]
run cmd
update_ssh_state(state)
info("Vagrant instance #{instance.to_str} created.")
Expand Down Expand Up @@ -128,28 +120,14 @@ def destroy(state)
# @raise [ClientError] if instance parameter is nil
def finalize_config!(instance)
super
resolve_config!
config[:vagrantfiles] = config[:vagrantfiles].map do |path|
File.expand_path(path, config[:kitchen_root])
end
finalize_pre_create_command!
finalize_synced_folders!
self
end

# Sets up an instance.
#
# @param state [Hash] mutable instance and driver state
# @raise [ActionFailed] if the action could not be completed
def setup(state)
create_vagrantfile
super
end

# Verifies a converged instance.
#
# @param state [Hash] mutable instance and driver state
# @raise [ActionFailed] if the action could not be completed
def verify(state)
create_vagrantfile
super
end

# Performs whatever tests that may be required to ensure that this driver
# will be able to function in the current environment. This may involve
# checking for the presence of certain directories, software installed,
Expand All @@ -173,9 +151,6 @@ def verify_dependencies
def create_vagrantfile
return if @vagrantfile_created

finalize_synced_folder_config
expand_vagrantfile_paths

vagrantfile = File.join(vagrant_root, "Vagrantfile")
debug("Creating Vagrantfile for #{instance.to_str} (#{vagrantfile})")
FileUtils.mkdir_p(vagrant_root)
Expand All @@ -192,23 +167,25 @@ def debug_vagrantfile(vagrantfile)
end
end

def expand_vagrantfile_paths
config[:vagrantfiles].map! do |vagrantfile|
File.absolute_path(vagrantfile)
end
def finalize_pre_create_command!
return if config[:pre_create_command].nil?

config[:pre_create_command] = config[:pre_create_command].
gsub("{{vagrant_root}}", vagrant_root)
end

def finalize_synced_folder_config
config[:synced_folders].map! do |source, destination, options|
[
File.expand_path(
source.gsub("%{instance_name}", instance.name),
config[:kitchen_root]
),
destination.gsub("%{instance_name}", instance.name),
options || "nil"
]
end
def finalize_synced_folders!
config[:synced_folders] = config[:synced_folders].
map do |source, destination, options|
[
File.expand_path(
source.gsub("%{instance_name}", instance.name),
config[:kitchen_root]
),
destination.gsub("%{instance_name}", instance.name),
options || "nil"
]
end
end

def render_template
Expand All @@ -219,17 +196,6 @@ def render_template
end
end

def resolve_config!
unless config[:vagrantfile_erb].nil?
config[:vagrantfile_erb] =
File.expand_path(config[:vagrantfile_erb], config[:kitchen_root])
end
unless config[:pre_create_command].nil?
config[:pre_create_command] =
config[:pre_create_command].gsub("{{vagrant_root}}", vagrant_root)
end
end

def run(cmd, options = {})
cmd = "echo #{cmd}" if config[:dry_run]
run_command(cmd, { :cwd => vagrant_root }.merge(options))
Expand Down
Loading

0 comments on commit 46faf19

Please sign in to comment.