From c61b4430869d1fa5701a0d6c6a4ea2e9615be042 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Thu, 5 Mar 2015 20:16:38 -0700 Subject: [PATCH 01/12] Update .travis.yml configuration. --- .travis.yml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 46029aff..46b1dc89 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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" From 1cce23c0d058191b884fb95ae230fa17144e2de7 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Thu, 5 Mar 2015 20:22:51 -0700 Subject: [PATCH 02/12] Drop tailor & add finstyle for style checking, update Rakefile. --- Gemfile | 6 ++---- Rakefile | 19 +++++++++++-------- kitchen-vagrant.gemspec | 11 ++++++++--- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Gemfile b/Gemfile index 72edf673..885ec764 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,6 @@ source 'https://rubygems.org' - -# Specify your gem's dependencies in kitchen-vagrant.gemspec gemspec -group :test do - gem 'rake' +group :guard do + gem "guard-rubocop" end diff --git a/Rakefile b/Rakefile index 0cb701cf..80363527 100644 --- a/Rakefile +++ b/Rakefile @@ -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" @@ -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, :stats] -task :default => [ :quality ] +task :default => [:quality] diff --git a/kitchen-vagrant.gemspec b/kitchen-vagrant.gemspec index aba61b9e..05244e2e 100644 --- a/kitchen-vagrant.gemspec +++ b/kitchen-vagrant.gemspec @@ -20,7 +20,12 @@ Gem::Specification.new do |gem| 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 From fea4675468acf83195f77f365018c56993fb48af Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Thu, 5 Mar 2015 20:27:20 -0700 Subject: [PATCH 03/12] Prefer english-style globals in gemspec (style). --- kitchen-vagrant.gemspec | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kitchen-vagrant.gemspec b/kitchen-vagrant.gemspec index 05244e2e..5d765b20 100644 --- a/kitchen-vagrant.gemspec +++ b/kitchen-vagrant.gemspec @@ -2,6 +2,7 @@ lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'kitchen/driver/vagrant_version.rb' +require "English" Gem::Specification.new do |gem| gem.name = "kitchen-vagrant" @@ -13,7 +14,7 @@ Gem::Specification.new do |gem| 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"] From 3b7ec172d431c420973c284f789c67bd0842df5b Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Thu, 5 Mar 2015 20:29:56 -0700 Subject: [PATCH 04/12] Prefer `%w[]` Arrays (style). --- lib/kitchen/driver/vagrant.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/kitchen/driver/vagrant.rb b/lib/kitchen/driver/vagrant.rb index 834de668..57a7e4e5 100644 --- a/lib/kitchen/driver/vagrant.rb +++ b/lib/kitchen/driver/vagrant.rb @@ -147,7 +147,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 From c846b83899b631519afb8bfd2db69b52ae43140a Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Thu, 5 Mar 2015 20:30:45 -0700 Subject: [PATCH 05/12] Remove extra vertical whitespace (style). --- lib/kitchen/driver/vagrant.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/kitchen/driver/vagrant.rb b/lib/kitchen/driver/vagrant.rb index 57a7e4e5..fb2fabc5 100644 --- a/lib/kitchen/driver/vagrant.rb +++ b/lib/kitchen/driver/vagrant.rb @@ -113,7 +113,6 @@ 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) From 61939cf3b9f1c2a93d2536e4e0f707c74e68ed35 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Thu, 5 Mar 2015 20:32:31 -0700 Subject: [PATCH 06/12] Rename #set_ssh_state to #update_ssh_state (style). --- lib/kitchen/driver/vagrant.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/kitchen/driver/vagrant.rb b/lib/kitchen/driver/vagrant.rb index fb2fabc5..e8cc79a0 100644 --- a/lib/kitchen/driver/vagrant.rb +++ b/lib/kitchen/driver/vagrant.rb @@ -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 @@ -196,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"] From 1809a9405726ddb9fc1eb86de6885f92b0909d2a Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Thu, 5 Mar 2015 20:34:40 -0700 Subject: [PATCH 07/12] Remove unused assignment in #vagrant_version (style). --- lib/kitchen/driver/vagrant.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/kitchen/driver/vagrant.rb b/lib/kitchen/driver/vagrant.rb index e8cc79a0..f6bdbdea 100644 --- a/lib/kitchen/driver/vagrant.rb +++ b/lib/kitchen/driver/vagrant.rb @@ -235,8 +235,7 @@ 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." + " Please download a package from #{WEBSITE}." From 4e780a54aefe44e4c5e526b55486e8c0d14aeb1f Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Thu, 5 Mar 2015 20:35:22 -0700 Subject: [PATCH 08/12] Prefer `File.exist?` to `File.exists?` which will be deprecated (style). --- lib/kitchen/driver/vagrant.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/kitchen/driver/vagrant.rb b/lib/kitchen/driver/vagrant.rb index f6bdbdea..17c379f0 100644 --- a/lib/kitchen/driver/vagrant.rb +++ b/lib/kitchen/driver/vagrant.rb @@ -185,7 +185,7 @@ def expand_vagrantfile_paths end def render_template - if File.exists?(template) + if File.exist?(template) ERB.new(IO.read(template)).result(binding).gsub(%r{^\s*$\n}, '') else raise ActionFailed, "Could not find Vagrantfile template #{template}" From 2be41adf7a8874c9b35bdcc3ca79bc37178ef2b6 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Thu, 5 Mar 2015 20:37:15 -0700 Subject: [PATCH 09/12] Prefer `\` style String concatenation across lines (style). --- lib/kitchen/driver/vagrant.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/kitchen/driver/vagrant.rb b/lib/kitchen/driver/vagrant.rb index 17c379f0..0dc66b68 100644 --- a/lib/kitchen/driver/vagrant.rb +++ b/lib/kitchen/driver/vagrant.rb @@ -119,7 +119,7 @@ def default_box_url bucket = config[:provider] 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 @@ -237,14 +237,14 @@ def resolve_config! def vagrant_version 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 From 3ac24c2ffee30afb7145bce7e3a5fdf397c53d61 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Thu, 5 Mar 2015 20:41:31 -0700 Subject: [PATCH 10/12] One of those tiny String tweak deals (style). --- Gemfile | 2 +- kitchen-vagrant.gemspec | 12 ++++++------ lib/kitchen/driver/vagrant.rb | 14 +++++++------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Gemfile b/Gemfile index 885ec764..5460d7a5 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source 'https://rubygems.org' +source "https://rubygems.org" gemspec group :guard do diff --git a/kitchen-vagrant.gemspec b/kitchen-vagrant.gemspec index 5d765b20..e537f290 100644 --- a/kitchen-vagrant.gemspec +++ b/kitchen-vagrant.gemspec @@ -1,13 +1,13 @@ # -*- 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 = ["fnichol@nichol.ca"] gem.description = "Kitchen::Driver::Vagrant - A Vagrant Driver for Test Kitchen." @@ -19,10 +19,10 @@ Gem::Specification.new do |gem| 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 'rake' - gem.add_development_dependency 'countloc', '~> 0.4' + 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 diff --git a/lib/kitchen/driver/vagrant.rb b/lib/kitchen/driver/vagrant.rb index 0dc66b68..868be125 100644 --- a/lib/kitchen/driver/vagrant.rb +++ b/lib/kitchen/driver/vagrant.rb @@ -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 @@ -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 @@ -117,7 +117,7 @@ def default_box_url 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}/" \ "opscode_#{instance.platform.name}_chef-provisionerless.box" @@ -186,7 +186,7 @@ def expand_vagrantfile_paths def render_template if File.exist?(template) - ERB.new(IO.read(template)).result(binding).gsub(%r{^\s*$\n}, '') + ERB.new(IO.read(template)).result(binding).gsub(%r{^\s*$\n}, "") else raise ActionFailed, "Could not find Vagrantfile template #{template}" end @@ -210,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 From b3cd143891b76a165f5e205aab1b75b83a8fca8d Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Thu, 5 Mar 2015 20:42:00 -0700 Subject: [PATCH 11/12] Add Guardfile. --- Guardfile | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Guardfile diff --git a/Guardfile b/Guardfile new file mode 100644 index 00000000..5aba00af --- /dev/null +++ b/Guardfile @@ -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 From 224a4bca8331728dbf2701b1763ce9f784766bad Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Thu, 5 Mar 2015 20:42:53 -0700 Subject: [PATCH 12/12] Add style checks into default Rake task. --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 80363527..b6d3af6a 100644 --- a/Rakefile +++ b/Rakefile @@ -19,6 +19,6 @@ RuboCop::RakeTask.new(:style) do |task| end desc "Run all quality tasks" -task :quality => [:cane, :stats] +task :quality => [:cane, :style, :stats] task :default => [:quality]