Skip to content

Commit

Permalink
Switch from Rubocop to Chefstyle and resolve all warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Smith <[email protected]>
  • Loading branch information
tas50 authored and chris-rock committed Aug 23, 2016
1 parent 7dd7f44 commit 988e612
Show file tree
Hide file tree
Showing 16 changed files with 268 additions and 333 deletions.
65 changes: 0 additions & 65 deletions .rubocop.yml

This file was deleted.

13 changes: 6 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@ language: ruby
cache: bundler
dist: trusty
services:
- docker
- docker
bundler_args: "--without integration guard tools"
before_install:
- gem install bundler
- gem --version
- gem install bundler
- gem --version
matrix:
include:
- rvm: 1.9.3
- rvm: 2.0
- rvm: 2.1
- rvm: 2.1.9
- rvm: ruby-head
- rvm: 2.2
- rvm: 2.2.5
bundler_args: "--without guard tools"
script: bundle exec rake test:integration OS='default profile contains_inspec'
- rvm: 2.2
- rvm: 2.2.5
bundler_args: "--without guard tools"
script: bundle exec rake test:integration OS='supermarket'
allow_failures:
Expand Down
10 changes: 5 additions & 5 deletions Berksfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# encoding: utf-8

source 'https://supermarket.chef.io'
source "https://supermarket.chef.io"

cookbook 'apt'
cookbook 'yum'
cookbook 'os_prepare', path: './test/cookbooks/os_prepare'
cookbook 'ssh-hardening', git: 'https://github.com/dev-sec/chef-ssh-hardening.git'
cookbook "apt"
cookbook "yum"
cookbook "os_prepare", path: "./test/cookbooks/os_prepare"
cookbook "ssh-hardening", git: "https://github.com/dev-sec/chef-ssh-hardening.git"
30 changes: 15 additions & 15 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
# -*- encoding: utf-8 -*-
source 'https://rubygems.org'
source "https://rubygems.org"
gemspec

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

group :test do
gem 'bundler', '~> 1.5'
gem 'minitest', '~> 5.5'
gem 'rake', '~> 10'
gem 'rubocop', '~> 0.32'
gem 'concurrent-ruby', '~> 0.9'
gem 'codeclimate-test-reporter', :require => nil
gem "bundler", "~> 1.5"
gem "minitest", "~> 5.5"
gem "rake", "~> 10"
gem "chefstyle", "~> 0.4.0"
gem "concurrent-ruby", "~> 0.9"
gem "codeclimate-test-reporter", :require => nil
end

# pin dependency for Ruby 1.9.3 since bundler is not
# detecting that net-ssh 3 does not work with 1.9.3
if Gem::Version.new(RUBY_VERSION) <= Gem::Version.new('1.9.3')
gem 'net-ssh', '~> 2.9'
if Gem::Version.new(RUBY_VERSION) <= Gem::Version.new("1.9.3")
gem "net-ssh", "~> 2.9"
end

group :integration do
gem 'berkshelf', '>= 4.2.3'
gem 'kitchen-dokken'
gem "berkshelf", ">= 4.2.3"
gem "kitchen-dokken"
end

group :tools do
gem 'pry', '~> 0.10'
gem 'github_changelog_generator', '1.11.3'
gem "pry", "~> 0.10"
gem "github_changelog_generator", "1.11.3"
end
6 changes: 3 additions & 3 deletions Guardfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
ignore %r{^\.gem/}

def rspec_opts
{ cmd: 'bundle exec rspec' }
{ cmd: "bundle exec rspec" }
end

def rubocop_opts
{ all_on_start: false, keep_failed: false, cli: '-r finstyle' }
{ all_on_start: false, keep_failed: false, cli: "-r chefstyle" }
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' }
watch(%r{^spec/spec_helper\.rb}) { "spec" }
end

guard :rubocop, rubocop_opts do
Expand Down
45 changes: 23 additions & 22 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

require "bundler/gem_tasks"
require "rspec/core/rake_task"
require 'rubocop/rake_task'
require "chefstyle"
require "rubocop/rake_task"

# Specs
RSpec::Core::RakeTask.new(:spec)
Expand All @@ -11,13 +12,13 @@ desc "Run all test suites"
task :test => [:spec]

# Rubocop
desc 'Run Rubocop lint checks'
desc "Run Rubocop lint checks"
task :rubocop do
RuboCop::RakeTask.new
end

# lint the project
desc 'Run robocop linter'
desc "Run robocop linter"
task lint: [:rubocop]

desc "Display LOC stats"
Expand All @@ -36,20 +37,20 @@ task :default => [:test, :quality]
# Automatically generate a changelog for this project. Only loaded if
# the necessary gem is installed.
begin
require 'github_changelog_generator/task'
require "github_changelog_generator/task"
GitHubChangelogGenerator::RakeTask.new :changelog
rescue LoadError
puts '>>>>> GitHub Changelog Generator not loaded, omitting tasks'
puts ">>>>> GitHub Changelog Generator not loaded, omitting tasks"
end

# Print the current version of this gem or update it.
#
# @param [Type] target the new version you want to set, or nil if you only want to show
def kitchen_inspec_version(target = nil)
path = 'lib/kitchen/verifier/inspec_version.rb'
require_relative path.sub(/.rb$/, '')
path = "lib/kitchen/verifier/inspec_version.rb"
require_relative path.sub(/.rb$/, "")

nu_version = target.nil? ? '' : " -> #{target}"
nu_version = target.nil? ? "" : " -> #{target}"
puts "Kitchen-inspec: #{Kitchen::Verifier::INSPEC_VERSION}#{nu_version}"

unless target.nil?
Expand All @@ -66,7 +67,7 @@ end
# @param [Type] msg the message to display if the command is missing
def require_command(x, msg = nil)
return if system("command -v #{x} || exit 1")
msg ||= 'Please install it first!'
msg ||= "Please install it first!"
puts "\033[31;1mCan't find command #{x.inspect}. #{msg}\033[0m"
exit 1
end
Expand All @@ -84,45 +85,45 @@ end

# Check the requirements for running an update of this repository.
def check_update_requirements
require_command 'git'
require_command 'github_changelog_generator', "\n"\
require_command "git"
require_command "github_changelog_generator", "\n"\
"For more information on how to install it see:\n"\
" https://github.com/skywinder/github-changelog-generator\n"
require_env 'CHANGELOG_GITHUB_TOKEN', "\n"\
require_env "CHANGELOG_GITHUB_TOKEN", "\n"\
"Please configure this token to make sure you can run all commands\n"\
"against GitHub.\n\n"\
"See github_changelog_generator homepage for more information:\n"\
" https://github.com/skywinder/github-changelog-generator\n"
end

# Show the current version of this gem.
desc 'Show the version of this gem'
desc "Show the version of this gem"
task :version do
kitchen_inspec_version
end

desc 'Generate the changelog'
desc "Generate the changelog"
task :changelog do
require_relative 'lib/kitchen/verifier/inspec_version'
require_relative "lib/kitchen/verifier/inspec_version"
system "github_changelog_generator -u chef -p kitchen-inspec --future-release #{Kitchen::Verifier::INSPEC_VERSION}"
end

# Update the version of this gem and create an updated
# changelog. It covers everything short of actually releasing
# the gem.
desc 'Bump the version of this gem'
desc "Bump the version of this gem"
task :bump_version, [:version] do |_, args|
v = args[:version] || ENV['to']
fail "You must specify a target version! rake release[1.2.3]" if v.empty?
v = args[:version] || ENV["to"]
raise "You must specify a target version! rake release[1.2.3]" if v.empty?
check_update_requirements
kitchen_inspec_version(v)
Rake::Task['changelog'].invoke
Rake::Task["changelog"].invoke
end

namespace :test do
task :integration do
concurrency = ENV['CONCURRENCY'] || 1
os = ENV['OS'] || ''
sh('sh', '-c', "bundle exec kitchen test -c #{concurrency} #{os}")
concurrency = ENV["CONCURRENCY"] || 1
os = ENV["OS"] || ""
sh("sh", "-c", "bundle exec kitchen test -c #{concurrency} #{os}")
end
end
6 changes: 3 additions & 3 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env ruby
# encoding: utf-8

require 'bundler/setup'
require 'kitchen/inspec'
require "bundler/setup"
require "kitchen/inspec"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand All @@ -11,5 +11,5 @@ require 'kitchen/inspec'
# require 'pry'
# Pry.start

require 'irb'
require "irb"
IRB.start
38 changes: 19 additions & 19 deletions kitchen-inspec.gemspec
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
# 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/verifier/inspec_version'
require 'English'
require "kitchen/verifier/inspec_version"
require "English"

Gem::Specification.new do |spec|
spec.name = 'kitchen-inspec'
spec.name = "kitchen-inspec"
spec.version = Kitchen::Verifier::INSPEC_VERSION
spec.license = 'Apache-2.0'
spec.authors = ['Fletcher Nichol']
spec.email = ['[email protected]']
spec.license = "Apache-2.0"
spec.authors = ["Fletcher Nichol"]
spec.email = ["[email protected]"]

spec.summary = 'A Test Kitchen Verifier for InSpec'
spec.summary = "A Test Kitchen Verifier for InSpec"
spec.description = spec.summary
spec.homepage = 'http://github.com/chef/kitchen-inspec'
spec.homepage = "http://github.com/chef/kitchen-inspec"

spec.files = `git ls-files -z`.split("\x0")
.reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = 'exe'
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']
spec.add_dependency 'inspec', '>=0.22.0', '<1.0.0'
spec.add_dependency 'test-kitchen', '~> 1.6'
spec.add_development_dependency 'countloc', '~> 0.4'
spec.add_development_dependency 'bundler', '~> 1.10'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'simplecov', '~> 0.10'
spec.require_paths = ["lib"]
spec.add_dependency "inspec", ">=0.22.0", "<1.0.0"
spec.add_dependency "test-kitchen", "~> 1.6"
spec.add_development_dependency "countloc", "~> 0.4"
spec.add_development_dependency "bundler", "~> 1.10"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec"
spec.add_development_dependency "simplecov", "~> 0.10"
# 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
spec.add_development_dependency 'finstyle', '1.5.0'
spec.add_development_dependency "chefstyle", "0.4.0"
end
Loading

0 comments on commit 988e612

Please sign in to comment.