Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project quality freshening #146

Merged
merged 12 commits into from
Mar 6, 2015
18 changes: 17 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
language: ruby

rvm:
- 1.9.3
- 2.2
- 2.1
- 2.0.0
- 1.9.3
- ruby-head

bundler_args: --without guard

sudo: false

matrix:
allow_failures:
- rvm: ruby-head

notifications:
irc: "chat.freenode.net#kitchenci"
8 changes: 3 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in kitchen-vagrant.gemspec
source "https://rubygems.org"
gemspec

group :test do
gem 'rake'
group :guard do
gem "guard-rubocop"
end
13 changes: 13 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# -*- encoding: utf-8 -*-
ignore %r{^\.gem/}

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

group :red_green_refactor, :halt_on_fail => true do
guard :rubocop, rubocop_opts do
watch(%r{.+\.rb$})
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
end
end
19 changes: 11 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
require "bundler/gem_tasks"
require 'cane/rake_task'
require 'tailor/rake_task'

require "cane/rake_task"
desc "Run cane to check quality metrics"
Cane::RakeTask.new

Tailor::RakeTask.new do |task|
task.file_set('lib/**/*.rb', 'code')
Cane::RakeTask.new do |cane|
cane.canefile = "./.cane"
end

desc "Display LOC stats"
Expand All @@ -15,7 +12,13 @@ task :stats do
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 "Run all quality tasks"
task :quality => [:cane, :tailor, :stats]
task :quality => [:cane, :style, :stats]

task :default => [ :quality ]
task :default => [:quality]
22 changes: 14 additions & 8 deletions kitchen-vagrant.gemspec
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
# -*- encoding: utf-8 -*-
lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'kitchen/driver/vagrant_version.rb'
require "kitchen/driver/vagrant_version.rb"
require "English"

Gem::Specification.new do |gem|
gem.name = "kitchen-vagrant"
gem.version = Kitchen::Driver::VAGRANT_VERSION
gem.license = 'Apache 2.0'
gem.license = "Apache 2.0"
gem.authors = ["Fletcher Nichol"]
gem.email = ["[email protected]"]
gem.description = "Kitchen::Driver::Vagrant - A Vagrant Driver for Test Kitchen."
gem.summary = gem.description
gem.homepage = "https://github.com/test-kitchen/kitchen-vagrant/"

gem.files = `git ls-files`.split($/)
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
gem.executables = []
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]

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

gem.add_development_dependency 'cane'
gem.add_development_dependency 'tailor'
gem.add_development_dependency 'countloc'
gem.add_development_dependency "rake"
gem.add_development_dependency "countloc", "~> 0.4"

# style and complexity libraries are tightly version pinned as newer releases
# may introduce new and undesireable style choices which would be immediately
# enforced in CI
gem.add_development_dependency "finstyle", "1.4.0"
gem.add_development_dependency "cane", "2.6.2"
end
32 changes: 15 additions & 17 deletions lib/kitchen/driver/vagrant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

require 'fileutils'
require 'rubygems/version'
require "fileutils"
require "rubygems/version"

require 'kitchen'
require "kitchen"

module Kitchen

Expand All @@ -45,7 +45,7 @@ class Vagrant < Kitchen::Driver::SSHBase
File.join(File.dirname(__FILE__), "../../../templates/Vagrantfile.erb")

default_config :provider,
ENV.fetch('VAGRANT_DEFAULT_PROVIDER', "virtualbox")
ENV.fetch("VAGRANT_DEFAULT_PROVIDER", "virtualbox")

default_config :vm_hostname do |driver|
driver.instance.name
Expand Down Expand Up @@ -73,7 +73,7 @@ def create(state)
cmd += " --no-provision" unless config[:provision]
cmd += " --provider=#{config[:provider]}" if config[:provider]
run cmd
set_ssh_state(state)
update_ssh_state(state)
info("Vagrant instance #{instance.to_str} created.")
end

Expand Down Expand Up @@ -113,14 +113,13 @@ def instance=(instance)
end

def default_box_url

# No default neede for 1.5 onwards - Vagrant Cloud only needs a box name
return if Gem::Version.new(vagrant_version) >= Gem::Version.new(1.5)

bucket = config[:provider]
bucket = 'vmware' if config[:provider] =~ /^vmware_(.+)$/
bucket = "vmware" if config[:provider] =~ /^vmware_(.+)$/

"https://opscode-vm-bento.s3.amazonaws.com/vagrant/#{bucket}/" +
"https://opscode-vm-bento.s3.amazonaws.com/vagrant/#{bucket}/" \
"opscode_#{instance.platform.name}_chef-provisionerless.box"
end

Expand All @@ -147,7 +146,7 @@ def run_pre_create_command

def vagrant_root
@vagrant_root ||= File.join(
config[:kitchen_root], %w{.kitchen kitchen-vagrant},
config[:kitchen_root], %w[.kitchen kitchen-vagrant],
"kitchen-#{File.basename(config[:kitchen_root])}-#{instance.name}"
)
end
Expand Down Expand Up @@ -186,8 +185,8 @@ def expand_vagrantfile_paths
end

def render_template
if File.exists?(template)
ERB.new(IO.read(template)).result(binding).gsub(%r{^\s*$\n}, '')
if File.exist?(template)
ERB.new(IO.read(template)).result(binding).gsub(%r{^\s*$\n}, "")
else
raise ActionFailed, "Could not find Vagrantfile template #{template}"
end
Expand All @@ -197,7 +196,7 @@ def template
File.expand_path(config[:vagrantfile_erb], config[:kitchen_root])
end

def set_ssh_state(state)
def update_ssh_state(state)
hash = vagrant_ssh_config

state[:hostname] = hash["HostName"]
Expand All @@ -211,7 +210,7 @@ def vagrant_ssh_config
output = run("vagrant ssh-config", :live_stream => nil)
lines = output.split("\n").map do |line|
tokens = line.strip.partition(" ")
[tokens.first, tokens.last.gsub(/"/, '')]
[tokens.first, tokens.last.gsub(/"/, "")]
end
Hash[lines]
end
Expand All @@ -236,17 +235,16 @@ def resolve_config!
end

def vagrant_version
version_string = silently_run("vagrant --version")
version_string = version_string.chomp.split(" ").last
silently_run("vagrant --version").chomp.split(" ").last
rescue Errno::ENOENT
raise UserError, "Vagrant #{MIN_VER} or higher is not installed." +
raise UserError, "Vagrant #{MIN_VER} or higher is not installed." \
" Please download a package from #{WEBSITE}."
end

def check_vagrant_version
version = vagrant_version
if Gem::Version.new(version) < Gem::Version.new(MIN_VER)
raise UserError, "Detected an old version of Vagrant (#{version})." +
raise UserError, "Detected an old version of Vagrant (#{version})." \
" Please upgrade to version #{MIN_VER} or higher from #{WEBSITE}."
end
end
Expand Down