From f9610924360de928af4b4be0d8ad8885c24ecf32 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Tue, 5 Aug 2014 14:19:02 -0600 Subject: [PATCH 01/25] Remove Tailor as development dependency. --- .tailor | 106 ------------------------------------------------- Rakefile | 5 +-- emeril.gemspec | 1 - 3 files changed, 1 insertion(+), 111 deletions(-) delete mode 100644 .tailor diff --git a/.tailor b/.tailor deleted file mode 100644 index dfbf33e..0000000 --- a/.tailor +++ /dev/null @@ -1,106 +0,0 @@ -#------------------------------------------------------------------------------ -# Horizontal Whitespace -#------------------------------------------------------------------------------ -# allow_hard_tabs True to let hard tabs be considered a single space. -# Default: false -# -# allow_trailing_line_spaces -# True to skip detecting extra spaces at the ends of -# lines. -# Default: false -# -# indentation_spaces The number of spaces to consider a proper indent. -# Default: 2 -# -# max_line_length The maximum number of characters in a line before -# tailor complains. -# Default: 80 -# spaces_after_comma Number of spaces to expect after a comma. -# Default: 1 -# -# spaces_before_comma Number of spaces to expect before a comma. -# Default: 0 -# -# spaces_after_lbrace The number of spaces to expect after an lbrace ('{'). -# Default: 1 -# -# spaces_before_lbrace The number of spaces to expect before an lbrace ('{'). -# Default: 1 -# -# spaces_before_rbrace The number of spaces to expect before an rbrace ('}'). -# Default: 1 -# -# spaces_in_empty_braces The number of spaces to expect between braces when -# there's nothing in the braces (i.e. {}). -# Default: 0 -# -# spaces_after_lbracket The number of spaces to expect after an -# lbracket ('['). -# Default: 0 -# -# spaces_before_rbracket The number of spaces to expect before an -# rbracket (']'). -# Default: 0 -# -# spaces_after_lparen The number of spaces to expect after an -# lparen ('('). -# Default: 0 -# -# spaces_before_rparen The number of spaces to expect before an -# rbracket (')'). -# Default: 0 -# -#------------------------------------------------------------------------------ -# Naming -#------------------------------------------------------------------------------ -# allow_camel_case_methods -# Setting to true skips detection of camel-case method -# names (i.e. def myMethod). -# Default: false -# -# allow_screaming_snake_case_classes -# Setting to true skips detection of screaming -# snake-case class names (i.e. My_Class). -# Default: false -# -#------------------------------------------------------------------------------ -# Vertical Whitespace -#------------------------------------------------------------------------------ -# max_code_lines_in_class The number of lines of code in a class to allow before -# tailor will warn you. -# Default: 300 -# -# max_code_lines_in_method -# The number of lines of code in a method to allow -# before tailor will warn you. -# Default: 30 -# -# trailing_newlines The number of newlines that should be at the end of -# the file. -# Default: 1 -# -Tailor.config do |config| - config.formatters "text" - config.file_set 'lib/**/*.rb' do |style| - style.allow_camel_case_methods false, level: :error - style.allow_hard_tabs false, level: :error - style.allow_screaming_snake_case_classes false, level: :error - style.allow_trailing_line_spaces false, level: :error - style.allow_invalid_ruby false, level: :warn - style.indentation_spaces 2, level: :error - style.max_code_lines_in_class 300, level: :error - style.max_code_lines_in_method 30, level: :error - style.max_line_length 80, level: :error - style.spaces_after_comma 1, level: :error - style.spaces_after_lbrace 1, level: :error - style.spaces_after_lbracket 0, level: :error - style.spaces_after_lparen 0, level: :error - style.spaces_before_comma 0, level: :error - style.spaces_before_lbrace 1, level: :error - style.spaces_before_rbrace 1, level: :error - style.spaces_before_rbracket 0, level: :error - style.spaces_before_rparen 0, level: :error - style.spaces_in_empty_braces 0, level: :error - style.trailing_newlines 1, level: :error - end -end diff --git a/Rakefile b/Rakefile index 66577ca..ea5e707 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,6 @@ require 'bundler/gem_tasks' require 'rake/testtask' require 'cane/rake_task' -require 'tailor/rake_task' Rake::TestTask.new(:unit) do |t| t.libs.push "lib" @@ -23,8 +22,6 @@ Cane::RakeTask.new do |cane| cane.canefile = './.cane' end -Tailor::RakeTask.new - desc "Display LOC stats" task :stats do puts "\n## Production Code Stats" @@ -34,6 +31,6 @@ task :stats do end desc "Run all quality tasks" -task :quality => [:cane, :tailor, :stats] +task :quality => [:cane, :stats] task :default => [:test, :quality] diff --git a/emeril.gemspec b/emeril.gemspec index 2bf031d..1ce91d4 100644 --- a/emeril.gemspec +++ b/emeril.gemspec @@ -33,7 +33,6 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'cane' spec.add_development_dependency 'guard-cane' - spec.add_development_dependency 'tailor' spec.add_development_dependency 'simplecov' spec.add_development_dependency 'countloc' end From c1fa7a080d49ab041269ea685bc1a9b2947bb1a4 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Tue, 5 Aug 2014 14:29:33 -0600 Subject: [PATCH 02/25] Update testing/health project dependencies. * Extract guard-related dependencies to Gemfile * Pin version of cane gem * Add finstyle gem * Update Guardfile with new guard strategy (red/green) * Add CodeClimate test coverage support * Expand TravisCI test matrix --- .travis.yml | 38 ++++++++++++++++++--------- Gemfile | 9 +++++++ Guardfile | 27 ++++++++++++++----- Rakefile | 8 +++++- emeril.gemspec | 9 ++++--- spec/integration/new_release_spec.rb | 1 + spec/integration/skip_publish_spec.rb | 4 +++ spec/spec_helper.rb | 5 +++- spec/unit/emeril/category_spec.rb | 1 + 9 files changed, 77 insertions(+), 25 deletions(-) diff --git a/.travis.yml b/.travis.yml index cc897a8..7822632 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,22 +1,34 @@ language: ruby rvm: -- 2.0.0 -- 1.9.3 -- 1.9.2 -- ruby-head + - 2.1 + - 2.0.0 + - 1.9.3 + - 1.9.2 + - ruby-head env: -- "CHEF_VERSION=" -- "CHEF_VERSION='~> 11.6.0'" -- "CHEF_VERSION='~> 11.4.4'" -- "CHEF_VERSION='~> 10.26'" + - "CHEF_VERSION=" + - "CHEF_VERSION='~> 11.14.2'" + - "CHEF_VERSION='~> 11.4.4'" + - "CHEF_VERSION='~> 10.26'" + +bundler_args: --without guard matrix: allow_failures: - - rvm: ruby-head + - rvm: ruby-head exclude: - - rvm: 2.0.0 - env: "CHEF_VERSION='~> 11.4.4'" - - rvm: 2.0.0 - env: "CHEF_VERSION='~> 10.26'" + - rvm: 2.1 + env: "CHEF_VERSION='~> 11.4.4'" + - rvm: 2.1 + env: "CHEF_VERSION='~> 10.26'" + - rvm: 2.0.0 + env: "CHEF_VERSION='~> 11.4.4'" + - rvm: 2.0.0 + env: "CHEF_VERSION='~> 10.26'" + +addons: + code_climate: + repo_token: + secure: "Apwuy7PdnWsOjQqkVYIfZQIcECns0D+eNecRmG0dQguBbgnQfG9xMMGIwuLshubhs9rPqAac/Bg9ZyIjWBa57V/ehaQg7BTzaN8K76R98lgrQ4Ub3bYoCU91zc554g4sgKMf5K8P5f1NLYGEyDb5+QP4oeafF1UDxwVHL17hHq0=" diff --git a/Gemfile b/Gemfile index cc20b10..fbd0464 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,16 @@ source 'https://rubygems.org' gemspec +group :guard do + gem 'guard-minitest' + gem 'guard-rubocop' + gem 'guard-cane' + gem 'guard-yard' +end + group :test do # allow CI to override the version of Chef for matrix testing gem 'chef', (ENV['CHEF_VERSION'] || '>= 0.10.10') + + gem 'codeclimate-test-reporter', require: nil end diff --git a/Guardfile b/Guardfile index 3f8d161..9aff534 100644 --- a/Guardfile +++ b/Guardfile @@ -1,10 +1,23 @@ -guard 'minitest' do - watch(%r|^spec/(.*)_spec\.rb|) - watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "spec/unit/#{m[1]}#{m[2]}_spec.rb" } - watch(%r|^spec/spec_helper\.rb|) { "spec" } +ignore %r{^\.gem/} + +group :red_green_refactor, halt_on_fail: true do + guard :minitest do + watch(%r|^spec/(.*)_spec\.rb|) + watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "spec/unit/#{m[1]}#{m[2]}_spec.rb" } + watch(%r|^spec/spec_helper\.rb|) { "spec" } + end + + guard :cane do + watch(%r|.*\.rb|) + watch('.cane') + end + + guard :rubocop, all_on_start: false, keep_failed: false, cli: "-r finstyle" do + watch(%r{.+\.rb$}) + watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) } + end end -guard 'cane' do - watch(%r|.*\.rb|) - watch('.cane') +guard :yard, port: "8808" do + watch(%r{lib/.+\.rb}) end diff --git a/Rakefile b/Rakefile index ea5e707..f9b92ba 100644 --- a/Rakefile +++ b/Rakefile @@ -17,6 +17,12 @@ end desc "Run all test suites" task :test => [:unit, :integration] +require "finstyle" +require "rubocop/rake_task" +RuboCop::RakeTask.new(:style) do |task| + task.options << "--display-cop-names" +end + desc "Run cane to check quality metrics" Cane::RakeTask.new do |cane| cane.canefile = './.cane' @@ -31,6 +37,6 @@ task :stats do end desc "Run all quality tasks" -task :quality => [:cane, :stats] +task :quality => [:cane, :style, :stats] task :default => [:test, :quality] diff --git a/emeril.gemspec b/emeril.gemspec index 1ce91d4..ef54afa 100644 --- a/emeril.gemspec +++ b/emeril.gemspec @@ -25,14 +25,17 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'bundler', '~> 1.3' spec.add_development_dependency 'rake' spec.add_development_dependency 'minitest' - spec.add_development_dependency 'guard-minitest' spec.add_development_dependency 'mocha' spec.add_development_dependency 'fakefs' spec.add_development_dependency 'vcr' spec.add_development_dependency 'webmock' - spec.add_development_dependency 'cane' - spec.add_development_dependency 'guard-cane' spec.add_development_dependency 'simplecov' spec.add_development_dependency 'countloc' + + # 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.1.0" + spec.add_development_dependency "cane", "2.6.2" end diff --git a/spec/integration/new_release_spec.rb b/spec/integration/new_release_spec.rb index 7619e9d..7ef703d 100644 --- a/spec/integration/new_release_spec.rb +++ b/spec/integration/new_release_spec.rb @@ -7,6 +7,7 @@ require 'emeril' VCR.configure do |config| + config.ignore_hosts "codeclimate.com" config.cassette_library_dir = "spec/fixtures/vcr_cassettes" config.hook_into :webmock diff --git a/spec/integration/skip_publish_spec.rb b/spec/integration/skip_publish_spec.rb index f7d86a1..78b37aa 100644 --- a/spec/integration/skip_publish_spec.rb +++ b/spec/integration/skip_publish_spec.rb @@ -6,6 +6,10 @@ require 'chef/knife' require 'emeril' +VCR.configure do |config| + config.ignore_hosts "codeclimate.com" +end + describe "Releasing and but not publishing a cookbook" do include Emeril::SpecCommon diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3b5808d..06f5118 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,7 +2,10 @@ gem 'minitest' -if ENV['SIMPLECOV'] +if ENV["CODECLIMATE_REPO_TOKEN"] + require "codeclimate-test-reporter" + CodeClimate::TestReporter.start +elsif ENV["COVERAGE"] require 'simplecov' SimpleCov.adapters.define 'gem' do command_name 'Specs' diff --git a/spec/unit/emeril/category_spec.rb b/spec/unit/emeril/category_spec.rb index 85c6791..793528d 100644 --- a/spec/unit/emeril/category_spec.rb +++ b/spec/unit/emeril/category_spec.rb @@ -6,6 +6,7 @@ require 'emeril/category' VCR.configure do |config| + config.ignore_hosts "codeclimate.com" config.cassette_library_dir = 'spec/fixtures/vcr_cassettes' config.hook_into :webmock end From b7a2cd78c6151cd09229948a6356ddf58b9b636b Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Tue, 5 Aug 2014 14:44:10 -0600 Subject: [PATCH 03/25] Use a next to skip iteration in each block (style). --- lib/emeril/metadata_chopper.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/emeril/metadata_chopper.rb b/lib/emeril/metadata_chopper.rb index 1b3ed6d..45efc48 100644 --- a/lib/emeril/metadata_chopper.rb +++ b/lib/emeril/metadata_chopper.rb @@ -24,10 +24,10 @@ class MetadataChopper < Hash def initialize(metadata_file) eval(IO.read(metadata_file), nil, metadata_file) %w{name version}.map(&:to_sym).each do |attr| - if self[attr].nil? - raise MetadataParseError, - "Missing attribute `#{attr}' must be set in #{metadata_file}" - end + next unless self[attr].nil? + + raise MetadataParseError, + "Missing attribute `#{attr}' must be set in #{metadata_file}" end end From 8ed31198acf29c5723e21ab19b24c0069fe2282b Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Tue, 5 Aug 2014 14:49:28 -0600 Subject: [PATCH 04/25] Replace or flow control with a conditional (style). --- lib/emeril/git_tagger.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/emeril/git_tagger.rb b/lib/emeril/git_tagger.rb index 1c6f177..3606fc7 100644 --- a/lib/emeril/git_tagger.rb +++ b/lib/emeril/git_tagger.rb @@ -78,8 +78,10 @@ def git_push end def guard_clean - clean? or raise GitNotCleanError, - "There are files that need to be committed first." + if !clean? + raise GitNotCleanError, + "There are files that need to be committed first." + end end def perform_git_push(options = '') From 74510e52aeaf51a19320962f4caa0a37449b5c62 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Tue, 5 Aug 2014 14:52:56 -0600 Subject: [PATCH 05/25] Refactor private method name in Releaser (style). --- lib/emeril/releaser.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/emeril/releaser.rb b/lib/emeril/releaser.rb index 5f4a54a..e29bd86 100644 --- a/lib/emeril/releaser.rb +++ b/lib/emeril/releaser.rb @@ -37,7 +37,7 @@ def initialize(options = {}) @category = options.fetch(:category) { default_category } @git_tagger = options.fetch(:git_tagger) { default_git_tagger } @publish_to_community = options.fetch(:publish_to_community) { true } - set_publisher(options.fetch(:publisher, nil)) if publish_to_community + setup_publisher(options.fetch(:publisher, nil)) if publish_to_community end # Tags and releases a cookbook. @@ -77,7 +77,7 @@ def default_publisher ) end - def set_publisher(publisher) + def setup_publisher(publisher) @publisher = publisher || default_publisher end From 6008a57d3c36382bbbeb9407e205c9a6b72ecf03 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Tue, 5 Aug 2014 14:53:56 -0600 Subject: [PATCH 06/25] Refactor rename method param to signal it is unused (style). --- lib/emeril/metadata_chopper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/emeril/metadata_chopper.rb b/lib/emeril/metadata_chopper.rb index 45efc48..9ba2ac2 100644 --- a/lib/emeril/metadata_chopper.rb +++ b/lib/emeril/metadata_chopper.rb @@ -31,7 +31,7 @@ def initialize(metadata_file) end end - def method_missing(meth, *args, &block) + def method_missing(meth, *args, &_block) self[meth] = args.first end end From 8a035976fccf516603a17d88c722acd350965885 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Tue, 5 Aug 2014 14:58:03 -0600 Subject: [PATCH 07/25] Prefer slightly less evil instance_eval over eval (style). --- lib/emeril/metadata_chopper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/emeril/metadata_chopper.rb b/lib/emeril/metadata_chopper.rb index 9ba2ac2..102b327 100644 --- a/lib/emeril/metadata_chopper.rb +++ b/lib/emeril/metadata_chopper.rb @@ -22,7 +22,7 @@ class MetadataChopper < Hash # @param metadata_file [String] path to a metadata.rb file # def initialize(metadata_file) - eval(IO.read(metadata_file), nil, metadata_file) + instance_eval(IO.read(metadata_file), metadata_file) %w{name version}.map(&:to_sym).each do |attr| next unless self[attr].nil? From 1a799774ca13f2eef593a5b8691c14ad1d1ca963 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Tue, 5 Aug 2014 15:03:22 -0600 Subject: [PATCH 08/25] Prefer english constants to perl symbols (style). --- emeril.gemspec | 3 ++- lib/emeril/git_tagger.rb | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/emeril.gemspec b/emeril.gemspec index ef54afa..2300059 100644 --- a/emeril.gemspec +++ b/emeril.gemspec @@ -2,6 +2,7 @@ lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'emeril/version' +require "English" Gem::Specification.new do |spec| spec.name = "emeril" @@ -13,7 +14,7 @@ Gem::Specification.new do |spec| spec.homepage = "http://fnichol.github.io/emeril/" spec.license = "MIT" - spec.files = `git ls-files`.split($/) + spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR) spec.executables = [] spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] diff --git a/lib/emeril/git_tagger.rb b/lib/emeril/git_tagger.rb index 3606fc7..8581774 100644 --- a/lib/emeril/git_tagger.rb +++ b/lib/emeril/git_tagger.rb @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- +require "English" + require 'emeril/logging' module Emeril @@ -100,11 +102,11 @@ def sh_with_code(cmd, &block) debug(cmd) Dir.chdir(source_path) { outbuf = `#{cmd}` - if $? == 0 + if $CHILD_STATUS == 0 block.call(outbuf) if block end } - [outbuf, $?] + [outbuf, $CHILD_STATUS] end def tag_version From ee0b8f6bd8258b2261f375ca75de75639f5311f3 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Tue, 5 Aug 2014 15:05:09 -0600 Subject: [PATCH 09/25] Use backslash string line continuation syntax vs. concatenation (style). --- lib/emeril/git_tagger.rb | 2 +- lib/emeril/rake_tasks.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/emeril/git_tagger.rb b/lib/emeril/git_tagger.rb index 8581774..ae2962f 100644 --- a/lib/emeril/git_tagger.rb +++ b/lib/emeril/git_tagger.rb @@ -91,7 +91,7 @@ def perform_git_push(options = '') out, code = sh_with_code(cmd) if code != 0 raise GitPushError, - "Couldn't git push. `#{cmd}' failed with the following output:" + + "Couldn't git push. `#{cmd}' failed with the following output:" \ "\n\n#{out}\n" end end diff --git a/lib/emeril/rake_tasks.rb b/lib/emeril/rake_tasks.rb index c3ec555..ce2d0b0 100644 --- a/lib/emeril/rake_tasks.rb +++ b/lib/emeril/rake_tasks.rb @@ -30,7 +30,7 @@ def initialize def define metadata = Emeril::MetadataChopper.new("metadata.rb") - desc "Create git tag for #{metadata[:name]}-#{metadata[:version]}" + + desc "Create git tag for #{metadata[:name]}-#{metadata[:version]}" \ " and push to the Community Site" task "release" do Chef::Knife.new.configure_chef From ba0d18abd0617f735bd269a98fa29bf13850ce67 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Tue, 5 Aug 2014 15:09:17 -0600 Subject: [PATCH 10/25] Indent case relative to end keyword (style). --- .rubocop.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..4cf0664 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,2 @@ +Style/CaseIndentation: + IndentWhenRelativeTo: end From af20674443e9300117af37751ab9c6547cc3b2e1 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Tue, 5 Aug 2014 15:10:21 -0600 Subject: [PATCH 11/25] Drop space before semicolon (style). --- lib/emeril/git_tagger.rb | 4 ++-- lib/emeril/metadata_chopper.rb | 2 +- spec/unit/emeril/publisher_spec.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/emeril/git_tagger.rb b/lib/emeril/git_tagger.rb index ae2962f..6166727 100644 --- a/lib/emeril/git_tagger.rb +++ b/lib/emeril/git_tagger.rb @@ -8,11 +8,11 @@ module Emeril # Exception class raised when a git repo is not clean. # - class GitNotCleanError < StandardError ; end + class GitNotCleanError < StandardError; end # Exception class raised when a git push does not return successfully. # - class GitPushError < StandardError ; end + class GitPushError < StandardError; end # Applies a version tag on a git repository and pushes it to the origin # remote. diff --git a/lib/emeril/metadata_chopper.rb b/lib/emeril/metadata_chopper.rb index 102b327..cc43dbe 100644 --- a/lib/emeril/metadata_chopper.rb +++ b/lib/emeril/metadata_chopper.rb @@ -4,7 +4,7 @@ module Emeril # Exception class raised when there is a metadata.rb parsing issue. # - class MetadataParseError < StandardError ; end + class MetadataParseError < StandardError; end # A rather insane and questionable class to quickly consume a metadata.rb # file and return the cookbook name and version attributes. diff --git a/spec/unit/emeril/publisher_spec.rb b/spec/unit/emeril/publisher_spec.rb index 722e38a..da3f985 100644 --- a/spec/unit/emeril/publisher_spec.rb +++ b/spec/unit/emeril/publisher_spec.rb @@ -8,7 +8,7 @@ class DummyKnife < Emeril::Publisher::SharePlugin - def run ; end + def run; end end describe Emeril::Publisher do From 8b2146b51b578195385eb936a26f86506bdf2925 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Tue, 5 Aug 2014 15:12:51 -0600 Subject: [PATCH 12/25] Prefer $w[..] string style lists (style). --- lib/emeril/logging.rb | 2 +- lib/emeril/metadata_chopper.rb | 2 +- lib/emeril/publisher.rb | 6 +++--- spec/integration/new_release_spec.rb | 4 ++-- spec/unit/emeril/publisher_spec.rb | 4 ++-- spec/unit/emeril/releaser_spec.rb | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/emeril/logging.rb b/lib/emeril/logging.rb index f8b10c7..3e7e51f 100644 --- a/lib/emeril/logging.rb +++ b/lib/emeril/logging.rb @@ -8,7 +8,7 @@ module Emeril # module Logging - %w{debug info warn error fatal}.map(&:to_sym).each do |meth| + %w[debug info warn error fatal].map(&:to_sym).each do |meth| define_method(meth) do |*args| logger && logger.public_send(meth, *args) end diff --git a/lib/emeril/metadata_chopper.rb b/lib/emeril/metadata_chopper.rb index cc43dbe..099a6c7 100644 --- a/lib/emeril/metadata_chopper.rb +++ b/lib/emeril/metadata_chopper.rb @@ -23,7 +23,7 @@ class MetadataChopper < Hash # def initialize(metadata_file) instance_eval(IO.read(metadata_file), metadata_file) - %w{name version}.map(&:to_sym).each do |attr| + %w[name version].map(&:to_sym).each do |attr| next unless self[attr].nil? raise MetadataParseError, diff --git a/lib/emeril/publisher.rb b/lib/emeril/publisher.rb index 35a255d..34c05b9 100644 --- a/lib/emeril/publisher.rb +++ b/lib/emeril/publisher.rb @@ -60,7 +60,7 @@ def run attr_reader :logger, :source_path, :name, :category, :knife_class def validate_chef_config! - %w{node_name client_key}.map(&:to_sym).each do |attr| + %w[node_name client_key].map(&:to_sym).each do |attr| raise "Chef::Config[:#{attr}] must be set" if ::Chef::Config[attr].nil? end end @@ -75,10 +75,10 @@ def sandbox_cookbook end def cookbook_files - entries = %w{ + entries = %w[ README.* CHANGELOG.* metadata.{json,rb} attributes definitions files libraries providers recipes resources templates - } + ] Dir.glob("#{source_path}/{#{entries.join(',')}}") end diff --git a/spec/integration/new_release_spec.rb b/spec/integration/new_release_spec.rb index 7ef703d..7737269 100644 --- a/spec/integration/new_release_spec.rb +++ b/spec/integration/new_release_spec.rb @@ -27,7 +27,7 @@ before do @saved = Hash.new - %w{node_name client_key}.map(&:to_sym).each do |attr| + %w[node_name client_key].map(&:to_sym).each do |attr| @saved[attr] = Chef::Config[attr] end @@ -36,7 +36,7 @@ end after do - %w{node_name client_key}.map(&:to_sym).each do |attr| + %w[node_name client_key].map(&:to_sym).each do |attr| Chef::Config[attr] = @saved.delete(attr) end diff --git a/spec/unit/emeril/publisher_spec.rb b/spec/unit/emeril/publisher_spec.rb index da3f985..9115605 100644 --- a/spec/unit/emeril/publisher_spec.rb +++ b/spec/unit/emeril/publisher_spec.rb @@ -35,7 +35,7 @@ def run; end before do @saved = Hash.new - %w{node_name client_key}.map(&:to_sym).each do |attr| + %w[node_name client_key].map(&:to_sym).each do |attr| @saved[attr] = Chef::Config[attr] end @@ -44,7 +44,7 @@ def run; end end after do - %w{node_name client_key}.map(&:to_sym).each do |attr| + %w[node_name client_key].map(&:to_sym).each do |attr| Chef::Config[attr] = @saved.delete(attr) end end diff --git a/spec/unit/emeril/releaser_spec.rb b/spec/unit/emeril/releaser_spec.rb index 648819b..1d67f82 100644 --- a/spec/unit/emeril/releaser_spec.rb +++ b/spec/unit/emeril/releaser_spec.rb @@ -16,7 +16,7 @@ before do @saved = Hash.new - %w{node_name client_key}.map(&:to_sym).each do |attr| + %w[node_name client_key].map(&:to_sym).each do |attr| @saved[attr] = Chef::Config[attr] end @@ -25,7 +25,7 @@ end after do - %w{node_name client_key}.map(&:to_sym).each do |attr| + %w[node_name client_key].map(&:to_sym).each do |attr| Chef::Config[attr] = @saved.delete(attr) end end From bdde65c75e937d51518a26b8d7d00065ca189518 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Tue, 5 Aug 2014 15:13:55 -0600 Subject: [PATCH 13/25] Use plain old string syntax in gemspect (style). --- emeril.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emeril.gemspec b/emeril.gemspec index 2300059..0eef80e 100644 --- a/emeril.gemspec +++ b/emeril.gemspec @@ -9,7 +9,7 @@ Gem::Specification.new do |spec| spec.version = Emeril::VERSION spec.authors = ["Fletcher Nichol"] spec.email = ["fnichol@nichol.ca"] - spec.description = %q{Release Chef cookbooks} + spec.description = "Release Chef cookbooks" spec.summary = spec.description spec.homepage = "http://fnichol.github.io/emeril/" spec.license = "MIT" From faff74860af30f50627973990bb7a16dd32752d4 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Tue, 5 Aug 2014 15:15:05 -0600 Subject: [PATCH 14/25] Fix multiline hash syntax (style). --- spec/unit/emeril/releaser_spec.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spec/unit/emeril/releaser_spec.rb b/spec/unit/emeril/releaser_spec.rb index 1d67f82..aa09a6d 100644 --- a/spec/unit/emeril/releaser_spec.rb +++ b/spec/unit/emeril/releaser_spec.rb @@ -51,8 +51,11 @@ opts[:source_path] == source_path end - Emeril::Releaser.new(:metadata => metadata, :category => category, - :source_path => source_path) + Emeril::Releaser.new( + :metadata => metadata, + :category => category, + :source_path => source_path + ) end it "defaults :metadata to use MetadataChopper" do From a58254337b1b35036a9209a792d413b8430c0dcd Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Tue, 5 Aug 2014 15:16:18 -0600 Subject: [PATCH 15/25] Remove unused assignment (style). --- spec/unit/emeril/publisher_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/unit/emeril/publisher_spec.rb b/spec/unit/emeril/publisher_spec.rb index 9115605..3a834cd 100644 --- a/spec/unit/emeril/publisher_spec.rb +++ b/spec/unit/emeril/publisher_spec.rb @@ -197,7 +197,6 @@ def ui_without_logger def make_cookbook! FileUtils.mkdir_p("#{cookbook_path}/recipes") - remote_dir = File.join(File.dirname(cookbook_path), "remote") File.open("#{cookbook_path}/metadata.rb", "wb") do |f| f.write <<-METADATA_RB.gsub(/^ {8}/, '') From c67d47145726584352f0af60b63c0c115d1fbb84 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Tue, 5 Aug 2014 15:17:46 -0600 Subject: [PATCH 16/25] Ignore long method in common spec helper (style). --- spec/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 06f5118..a3931fb 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -47,7 +47,7 @@ module Emeril module SpecCommon - def make_cookbook!(opts = {}) + def make_cookbook!(opts = {}) # rubocop:disable Style/MethodLength FileUtils.mkdir_p("#{cookbook_path}/recipes") remote_dir = File.join(File.dirname(cookbook_path), "remote") From 5b5d3cf622cb479d3e88134acb4fb6a3a8e2d871 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Tue, 5 Aug 2014 15:18:46 -0600 Subject: [PATCH 17/25] Fix inner block spacing (style). --- spec/integration/new_release_spec.rb | 2 +- spec/integration/skip_publish_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/integration/new_release_spec.rb b/spec/integration/new_release_spec.rb index 7737269..6979e8b 100644 --- a/spec/integration/new_release_spec.rb +++ b/spec/integration/new_release_spec.rb @@ -43,7 +43,7 @@ FileUtils.remove_dir(cookbook_path) end - let(:cookbook_path) { File.join(Dir.mktmpdir, "emeril")} + let(:cookbook_path) { File.join(Dir.mktmpdir, "emeril") } let(:logger) do if ENV["DEBUG"] diff --git a/spec/integration/skip_publish_spec.rb b/spec/integration/skip_publish_spec.rb index 78b37aa..0fdb0e8 100644 --- a/spec/integration/skip_publish_spec.rb +++ b/spec/integration/skip_publish_spec.rb @@ -14,7 +14,7 @@ include Emeril::SpecCommon - let(:cookbook_path) { File.join(Dir.mktmpdir, "emeril")} + let(:cookbook_path) { File.join(Dir.mktmpdir, "emeril") } let(:logger) do if ENV["DEBUG"] From 62481d6985e258c4a4deb11ad8235e6296f33132 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Tue, 5 Aug 2014 15:22:30 -0600 Subject: [PATCH 18/25] Fix hash formatting & line length (style). --- spec/unit/emeril/releaser_spec.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spec/unit/emeril/releaser_spec.rb b/spec/unit/emeril/releaser_spec.rb index aa09a6d..261cc96 100644 --- a/spec/unit/emeril/releaser_spec.rb +++ b/spec/unit/emeril/releaser_spec.rb @@ -67,11 +67,9 @@ end it "defaults :category to use Category.for_coobook" do - Emeril::Category.expects(:for_cookbook).with("wakka") + Emeril::Category.expects(:for_cookbook).with("wot") - Emeril::Releaser.new({ - :metadata => { :name => "wakka", :version => "1.0.0" } - }) + Emeril::Releaser.new(:metadata => { :name => "wot", :version => "1.0.0" }) end it "defaults :git_tagger to use GitTagger" do From 1b59fb7505eb8d3da12dfa94da68bf237c0c7fed Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Tue, 5 Aug 2014 15:23:25 -0600 Subject: [PATCH 19/25] Remove redundant curly braces for hash parameter (style). --- spec/unit/emeril/releaser_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/unit/emeril/releaser_spec.rb b/spec/unit/emeril/releaser_spec.rb index 261cc96..1851b04 100644 --- a/spec/unit/emeril/releaser_spec.rb +++ b/spec/unit/emeril/releaser_spec.rb @@ -61,7 +61,7 @@ it "defaults :metadata to use MetadataChopper" do Emeril::MetadataChopper.expects(:new).with { |path| path =~ /#{File.join(source_path, "metadata.rb")}$/ - }.returns({ :name => "c", :version => "1.0.0" }) + }.returns(:name => "c", :version => "1.0.0") Emeril::Releaser.new(:category => category, :source_path => source_path) end From b741db4393f811092c1ae2b6187a12599eef71a4 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Tue, 5 Aug 2014 15:25:09 -0600 Subject: [PATCH 20/25] Make regexp literal more explict as a method parameter (style). --- spec/unit/emeril/git_tagger_spec.rb | 6 +++--- spec/unit/emeril/publisher_spec.rb | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/unit/emeril/git_tagger_spec.rb b/spec/unit/emeril/git_tagger_spec.rb index e3653b4..23415b2 100644 --- a/spec/unit/emeril/git_tagger_spec.rb +++ b/spec/unit/emeril/git_tagger_spec.rb @@ -39,7 +39,7 @@ it "tags the repo" do git_tagger.run - run_cmd(%{git tag}).must_match /^v4.1.1$/ + run_cmd(%{git tag}).must_match(/^v4.1.1$/) end it "disables the tag prefix" do @@ -50,7 +50,7 @@ :tag_prefix => false ).run - run_cmd(%{git tag}).must_match /^4.1.1$/ + run_cmd(%{git tag}).must_match(/^4.1.1$/) end it "uses a custom tag prefix" do @@ -61,7 +61,7 @@ :tag_prefix => "version-" ).run - run_cmd(%{git tag}).must_match /^version-4.1.1$/ + run_cmd(%{git tag}).must_match(/^version-4.1.1$/) end it "pushes the tag to the remote" do diff --git a/spec/unit/emeril/publisher_spec.rb b/spec/unit/emeril/publisher_spec.rb index 3a834cd..7ed2185 100644 --- a/spec/unit/emeril/publisher_spec.rb +++ b/spec/unit/emeril/publisher_spec.rb @@ -133,7 +133,7 @@ def run; end it "calls super if logger is nil" do ui_without_logger.msg("yo") - stdout.string.must_match /^yo$/ + stdout.string.must_match(/^yo$/) end end @@ -148,7 +148,7 @@ def run; end it "calls super if logger is nil" do ui_without_logger.err("yolo") - stderr.string.must_match /^yolo$/ + stderr.string.must_match(/^yolo$/) end end @@ -163,7 +163,7 @@ def run; end it "calls super if logger is nil" do ui_without_logger.err("caution") - stderr.string.must_match /^caution$/ + stderr.string.must_match(/^caution$/) end end @@ -178,7 +178,7 @@ def run; end it "calls super if logger is nil" do ui_without_logger.fatal("die") - stderr.string.must_match /die$/ + stderr.string.must_match(/die$/) end end From f59a7626b69bec9b2552da85220ce605b6e7c455 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Tue, 5 Aug 2014 15:29:05 -0600 Subject: [PATCH 21/25] Prefer hash rocket style in spec suite (style). --- spec/integration/new_release_spec.rb | 6 +++--- spec/integration/skip_publish_spec.rb | 18 +++++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/spec/integration/new_release_spec.rb b/spec/integration/new_release_spec.rb index 6979e8b..30641ca 100644 --- a/spec/integration/new_release_spec.rb +++ b/spec/integration/new_release_spec.rb @@ -57,14 +57,14 @@ end it "releases a new cookbook" do - make_cookbook!(version: "1.2.3") + make_cookbook!(:version => "1.2.3") VCR.use_cassette('new_release') do - Emeril::Releaser.new(logger: logger, source_path: cookbook_path).run + Emeril::Releaser.new(:logger => logger, :source_path => cookbook_path).run end # tag was pushed to the remote - git_tag = run_cmd("git tag", in: "#{File.dirname(cookbook_path)}/remote") + git_tag = run_cmd("git tag", :in => "#{File.dirname(cookbook_path)}/remote") git_tag.chomp.must_equal "v1.2.3" end end diff --git a/spec/integration/skip_publish_spec.rb b/spec/integration/skip_publish_spec.rb index 0fdb0e8..9ab988f 100644 --- a/spec/integration/skip_publish_spec.rb +++ b/spec/integration/skip_publish_spec.rb @@ -28,31 +28,35 @@ end it "releases a new cookbook" do - make_cookbook!(version: "4.5.6") + make_cookbook!(:version => "4.5.6") VCR.use_cassette('new_release') do Emeril::Releaser.new( - logger: logger, source_path: cookbook_path, publish_to_community: false + :logger => logger, + :source_path => cookbook_path, + :publish_to_community => false ).run end # tag was pushed to the remote - git_tag = run_cmd("git tag", in: "#{File.dirname(cookbook_path)}/remote") + git_tag = run_cmd("git tag", :in => "#{File.dirname(cookbook_path)}/remote") git_tag.chomp.must_equal "v4.5.6" end it "releases a new cookbook with a custom git tag prefix" do - make_cookbook!(version: "1.0.0") + make_cookbook!(:version => "1.0.0") VCR.use_cassette('new_release') do Emeril::Releaser.new( - logger: logger, source_path: cookbook_path, publish_to_community: false, - tag_prefix: "release-" + :logger => logger, + :source_path => cookbook_path, + :publish_to_community => false, + :tag_prefix => "release-" ).run end # tag was pushed to the remote - git_tag = run_cmd("git tag", in: "#{File.dirname(cookbook_path)}/remote") + git_tag = run_cmd("git tag", :in => "#{File.dirname(cookbook_path)}/remote") git_tag.chomp.must_equal "release-1.0.0" end end From 5ccfa982e279be3c20799d6fe29b5bf957f88179 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Tue, 5 Aug 2014 15:40:55 -0600 Subject: [PATCH 22/25] Refactor spec_helper methods for complexity (style). --- spec/spec_helper.rb | 90 ++++++++++++++++++++++++++------------------- 1 file changed, 53 insertions(+), 37 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a3931fb..bde4bd8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,26 +1,26 @@ # -*- encoding: utf-8 -*- -gem 'minitest' +gem "minitest" if ENV["CODECLIMATE_REPO_TOKEN"] require "codeclimate-test-reporter" CodeClimate::TestReporter.start elsif ENV["COVERAGE"] - require 'simplecov' - SimpleCov.adapters.define 'gem' do - command_name 'Specs' + require "simplecov" + SimpleCov.adapters.define "gem" do + command_name "Specs" - add_filter '.gem/' - add_filter '/spec/' + add_filter ".gem/" + add_filter "/spec/" - add_group 'Libraries', '/lib/' + add_group "Libraries", "/lib/" end - SimpleCov.start 'gem' + SimpleCov.start "gem" end -require 'fakefs/safe' -require 'minitest/autorun' -require 'mocha/setup' +require "fakefs/safe" +require "minitest/autorun" +require "mocha/setup" # Nasty hack to redefine IO.read in terms of File#read for fakefs class IO @@ -29,10 +29,11 @@ def self.read(*args) end end -require 'chef' -require 'chef/cookbook_site_streaming_uploader' +require "chef" +require "chef/cookbook_site_streaming_uploader" class Chef class CookbookSiteStreamingUploader + # Backwards compat class MultipartStream alias_method :read_original, :read @@ -45,35 +46,16 @@ def read(how_much = nil) module Emeril + # Common spec helpers module SpecCommon - def make_cookbook!(opts = {}) # rubocop:disable Style/MethodLength + def make_cookbook!(opts = {}) FileUtils.mkdir_p("#{cookbook_path}/recipes") remote_dir = File.join(File.dirname(cookbook_path), "remote") - File.open("#{cookbook_path}/metadata.rb", "wb") do |f| - f.write <<-METADATA_RB.gsub(/^ {10}/, '') - name "#{opts.fetch(:name, "emeril")}" - maintainer "Michael Bluth" - maintainer_email "michael@bluth.com" - license "Apache 2.0" - description "Doing stuff!" - long_description "Doing stuff!" - version "#{opts.fetch(:version, "4.1.1")}" - METADATA_RB - end - File.open("#{cookbook_path}/recipes/default.rb", "wb") do |f| - f.write <<-DEFAULT_RB.gsub(/^ {10}/, '') - directory "/tmp/yeah" - - package "bash" - DEFAULT_RB - end - File.open("#{cookbook_path}/README.md", "wb") do |f| - f.write <<-README.gsub(/^ {10}/, '') - # The beast of the beasts - README - end + create_metadata(opts) + create_recipe + create_readme run_cmd [ %{git init}, @@ -95,5 +77,39 @@ def make_client_key! def run_cmd(cmd, opts = {}) %x{cd #{opts.fetch(:in, cookbook_path)} && #{cmd}} end + + private + + def create_metadata(opts) + File.open("#{cookbook_path}/metadata.rb", "wb") do |f| + f.write <<-METADATA_RB.gsub(/^ {10}/, "") + name "#{opts.fetch(:name, "emeril")}" + maintainer "Michael Bluth" + maintainer_email "michael@bluth.com" + license "Apache 2.0" + description "Doing stuff!" + long_description "Doing stuff!" + version "#{opts.fetch(:version, "4.1.1")}" + METADATA_RB + end + end + + def create_recipe + File.open("#{cookbook_path}/recipes/default.rb", "wb") do |f| + f.write <<-DEFAULT_RB.gsub(/^ {10}/, "") + directory "/tmp/yeah" + + package "bash" + DEFAULT_RB + end + end + + def create_readme + File.open("#{cookbook_path}/README.md", "wb") do |f| + f.write <<-README.gsub(/^ {10}/, "") + # The beast of the beasts + README + end + end end end From 4fa3356ff083bff9b4637ba821566e51b9e87d9c Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Tue, 5 Aug 2014 15:51:51 -0600 Subject: [PATCH 23/25] One of those tiny String tweak deals (style). --- Rakefile | 12 +++++------ emeril.gemspec | 26 +++++++++++------------ lib/emeril.rb | 12 +++++------ lib/emeril/category.rb | 6 +++--- lib/emeril/git_tagger.rb | 10 ++++----- lib/emeril/publisher.rb | 18 ++++++++-------- lib/emeril/rake.rb | 2 +- lib/emeril/rake_tasks.rb | 6 +++--- lib/emeril/releaser.rb | 8 +++---- lib/emeril/thor.rb | 2 +- lib/emeril/thor_tasks.rb | 6 +++--- spec/integration/new_release_spec.rb | 10 ++++----- spec/integration/skip_publish_spec.rb | 12 +++++------ spec/unit/emeril/category_spec.rb | 16 +++++++------- spec/unit/emeril/git_tagger_spec.rb | 8 +++---- spec/unit/emeril/metadata_chopper_spec.rb | 6 +++--- spec/unit/emeril/publisher_spec.rb | 15 +++++++------ spec/unit/emeril/releaser_spec.rb | 9 ++++---- 18 files changed, 93 insertions(+), 91 deletions(-) diff --git a/Rakefile b/Rakefile index f9b92ba..f5a2b47 100644 --- a/Rakefile +++ b/Rakefile @@ -1,16 +1,16 @@ -require 'bundler/gem_tasks' -require 'rake/testtask' -require 'cane/rake_task' +require "bundler/gem_tasks" +require "rake/testtask" +require "cane/rake_task" Rake::TestTask.new(:unit) do |t| t.libs.push "lib" - t.test_files = FileList['spec/unit/**/*_spec.rb'] + t.test_files = FileList["spec/unit/**/*_spec.rb"] t.verbose = true end Rake::TestTask.new(:integration) do |t| t.libs.push "lib" - t.test_files = FileList['spec/integration/**/*_spec.rb'] + t.test_files = FileList["spec/integration/**/*_spec.rb"] t.verbose = true end @@ -25,7 +25,7 @@ end desc "Run cane to check quality metrics" Cane::RakeTask.new do |cane| - cane.canefile = './.cane' + cane.canefile = "./.cane" end desc "Display LOC stats" diff --git a/emeril.gemspec b/emeril.gemspec index 0eef80e..946a416 100644 --- a/emeril.gemspec +++ b/emeril.gemspec @@ -1,7 +1,7 @@ # coding: utf-8 -lib = File.expand_path('../lib', __FILE__) +lib = File.expand_path("../lib", __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'emeril/version' +require "emeril/version" require "English" Gem::Specification.new do |spec| @@ -19,20 +19,20 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] - spec.required_ruby_version = '>= 1.9.2' + spec.required_ruby_version = ">= 1.9.2" - spec.add_dependency 'chef', '> 0.10.10' + spec.add_dependency "chef", "> 0.10.10" - spec.add_development_dependency 'bundler', '~> 1.3' - spec.add_development_dependency 'rake' - spec.add_development_dependency 'minitest' - spec.add_development_dependency 'mocha' - spec.add_development_dependency 'fakefs' - spec.add_development_dependency 'vcr' - spec.add_development_dependency 'webmock' + spec.add_development_dependency "bundler", "~> 1.3" + spec.add_development_dependency "rake" + spec.add_development_dependency "minitest" + spec.add_development_dependency "mocha" + spec.add_development_dependency "fakefs" + spec.add_development_dependency "vcr" + spec.add_development_dependency "webmock" - spec.add_development_dependency 'simplecov' - spec.add_development_dependency 'countloc' + spec.add_development_dependency "simplecov" + spec.add_development_dependency "countloc" # 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/emeril.rb b/lib/emeril.rb index b551d66..c224c86 100644 --- a/lib/emeril.rb +++ b/lib/emeril.rb @@ -1,11 +1,11 @@ # -*- encoding: utf-8 -*- -require 'emeril/category' -require 'emeril/git_tagger' -require 'emeril/metadata_chopper' -require 'emeril/publisher' -require 'emeril/releaser' -require 'emeril/version' +require "emeril/category" +require "emeril/git_tagger" +require "emeril/metadata_chopper" +require "emeril/publisher" +require "emeril/releaser" +require "emeril/version" module Emeril end diff --git a/lib/emeril/category.rb b/lib/emeril/category.rb index fccb7f1..9eae6d6 100644 --- a/lib/emeril/category.rb +++ b/lib/emeril/category.rb @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- -require 'net/http' -require 'json' +require "net/http" +require "json" module Emeril @@ -20,7 +20,7 @@ class Category def self.for_cookbook(cookbook) path = "/api/v1/cookbooks/#{cookbook}" response = Net::HTTP.get_response("cookbooks.opscode.com", path) - JSON.parse(response.body)['category'] + JSON.parse(response.body)["category"] end end end diff --git a/lib/emeril/git_tagger.rb b/lib/emeril/git_tagger.rb index 6166727..04c8eef 100644 --- a/lib/emeril/git_tagger.rb +++ b/lib/emeril/git_tagger.rb @@ -2,7 +2,7 @@ require "English" -require 'emeril/logging' +require "emeril/logging" module Emeril @@ -63,7 +63,7 @@ def run attr_reader :logger, :source_path, :tag_prefix, :version def already_tagged? - if sh_with_code('git tag')[0].split(/\n/).include?(version_tag) + if sh_with_code("git tag")[0].split(/\n/).include?(version_tag) info("Tag #{version_tag} has already been created.") true end @@ -75,7 +75,7 @@ def clean? def git_push perform_git_push - perform_git_push ' --tags' + perform_git_push " --tags" info("Pushed git commits and tags.") end @@ -86,7 +86,7 @@ def guard_clean end end - def perform_git_push(options = '') + def perform_git_push(options = "") cmd = "git push origin master #{options}" out, code = sh_with_code(cmd) if code != 0 @@ -98,7 +98,7 @@ def perform_git_push(options = '') def sh_with_code(cmd, &block) cmd << " 2>&1" - outbuf = '' + outbuf = "" debug(cmd) Dir.chdir(source_path) { outbuf = `#{cmd}` diff --git a/lib/emeril/publisher.rb b/lib/emeril/publisher.rb index 34c05b9..b2e3643 100644 --- a/lib/emeril/publisher.rb +++ b/lib/emeril/publisher.rb @@ -1,14 +1,14 @@ # -*- encoding: utf-8 -*- -require 'chef/cookbook_uploader' -require 'chef/cookbook_loader' -require 'chef/cookbook_site_streaming_uploader' -require 'chef/knife/cookbook_site_share' -require 'chef/knife/core/ui' -require 'fileutils' -require 'tmpdir' +require "chef/cookbook_uploader" +require "chef/cookbook_loader" +require "chef/cookbook_site_streaming_uploader" +require "chef/knife/cookbook_site_share" +require "chef/knife/core/ui" +require "fileutils" +require "tmpdir" -require 'emeril/logging' +require "emeril/logging" module Emeril @@ -80,7 +80,7 @@ def cookbook_files files libraries providers recipes resources templates ] - Dir.glob("#{source_path}/{#{entries.join(',')}}") + Dir.glob("#{source_path}/{#{entries.join(",")}}") end def logging_ui(ui) diff --git a/lib/emeril/rake.rb b/lib/emeril/rake.rb index 7c5400d..2292d45 100644 --- a/lib/emeril/rake.rb +++ b/lib/emeril/rake.rb @@ -1,5 +1,5 @@ # -*- encoding: utf-8 -*- -require 'emeril/rake_tasks' +require "emeril/rake_tasks" Emeril::RakeTasks.new diff --git a/lib/emeril/rake_tasks.rb b/lib/emeril/rake_tasks.rb index ce2d0b0..6080111 100644 --- a/lib/emeril/rake_tasks.rb +++ b/lib/emeril/rake_tasks.rb @@ -1,9 +1,9 @@ # -*- encoding: utf-8 -*- -require 'rake/tasklib' -require 'chef/knife' +require "rake/tasklib" +require "chef/knife" -require 'emeril' +require "emeril" module Emeril diff --git a/lib/emeril/releaser.rb b/lib/emeril/releaser.rb index e29bd86..c82dc5d 100644 --- a/lib/emeril/releaser.rb +++ b/lib/emeril/releaser.rb @@ -1,9 +1,9 @@ # -*- encoding: utf-8 -*- -require 'emeril/category' -require 'emeril/git_tagger' -require 'emeril/metadata_chopper' -require 'emeril/publisher' +require "emeril/category" +require "emeril/git_tagger" +require "emeril/metadata_chopper" +require "emeril/publisher" module Emeril diff --git a/lib/emeril/thor.rb b/lib/emeril/thor.rb index 221d8df..d1dae6a 100644 --- a/lib/emeril/thor.rb +++ b/lib/emeril/thor.rb @@ -1,5 +1,5 @@ # -*- encoding: utf-8 -*- -require 'emeril/thor_tasks' +require "emeril/thor_tasks" Emeril::ThorTasks.new diff --git a/lib/emeril/thor_tasks.rb b/lib/emeril/thor_tasks.rb index 668659f..798e887 100644 --- a/lib/emeril/thor_tasks.rb +++ b/lib/emeril/thor_tasks.rb @@ -1,9 +1,9 @@ # -*- encoding: utf-8 -*- -require 'thor' -require 'chef/knife' +require "thor" +require "chef/knife" -require 'emeril' +require "emeril" module Emeril diff --git a/spec/integration/new_release_spec.rb b/spec/integration/new_release_spec.rb index 30641ca..e0c7a67 100644 --- a/spec/integration/new_release_spec.rb +++ b/spec/integration/new_release_spec.rb @@ -1,10 +1,10 @@ # -*- encoding: utf-8 -*- -require_relative '../spec_helper' -require 'vcr' +require_relative "../spec_helper" +require "vcr" -require 'chef/knife' -require 'emeril' +require "chef/knife" +require "emeril" VCR.configure do |config| config.ignore_hosts "codeclimate.com" @@ -59,7 +59,7 @@ it "releases a new cookbook" do make_cookbook!(:version => "1.2.3") - VCR.use_cassette('new_release') do + VCR.use_cassette("new_release") do Emeril::Releaser.new(:logger => logger, :source_path => cookbook_path).run end diff --git a/spec/integration/skip_publish_spec.rb b/spec/integration/skip_publish_spec.rb index 9ab988f..7607f2b 100644 --- a/spec/integration/skip_publish_spec.rb +++ b/spec/integration/skip_publish_spec.rb @@ -1,10 +1,10 @@ # -*- encoding: utf-8 -*- -require_relative '../spec_helper' -require 'vcr' +require_relative "../spec_helper" +require "vcr" -require 'chef/knife' -require 'emeril' +require "chef/knife" +require "emeril" VCR.configure do |config| config.ignore_hosts "codeclimate.com" @@ -30,7 +30,7 @@ it "releases a new cookbook" do make_cookbook!(:version => "4.5.6") - VCR.use_cassette('new_release') do + VCR.use_cassette("new_release") do Emeril::Releaser.new( :logger => logger, :source_path => cookbook_path, @@ -46,7 +46,7 @@ it "releases a new cookbook with a custom git tag prefix" do make_cookbook!(:version => "1.0.0") - VCR.use_cassette('new_release') do + VCR.use_cassette("new_release") do Emeril::Releaser.new( :logger => logger, :source_path => cookbook_path, diff --git a/spec/unit/emeril/category_spec.rb b/spec/unit/emeril/category_spec.rb index 793528d..59edb75 100644 --- a/spec/unit/emeril/category_spec.rb +++ b/spec/unit/emeril/category_spec.rb @@ -1,13 +1,13 @@ # -*- encoding: utf-8 -*- -require_relative '../../spec_helper' -require 'vcr' +require_relative "../../spec_helper" +require "vcr" -require 'emeril/category' +require "emeril/category" VCR.configure do |config| config.ignore_hosts "codeclimate.com" - config.cassette_library_dir = 'spec/fixtures/vcr_cassettes' + config.cassette_library_dir = "spec/fixtures/vcr_cassettes" config.hook_into :webmock end @@ -15,14 +15,14 @@ describe ".for_cookbook" do it "returns a category string for a known cookbook" do - VCR.use_cassette('known_cookbook') do - Emeril::Category.for_cookbook('mysql').must_equal 'Databases' + VCR.use_cassette("known_cookbook") do + Emeril::Category.for_cookbook("mysql").must_equal "Databases" end end it "returns nil for a nonexistant cookbook" do - VCR.use_cassette('nonexistant_cookbook') do - Emeril::Category.for_cookbook('fooboobunnyyaya').must_be_nil + VCR.use_cassette("nonexistant_cookbook") do + Emeril::Category.for_cookbook("fooboobunnyyaya").must_be_nil end end end diff --git a/spec/unit/emeril/git_tagger_spec.rb b/spec/unit/emeril/git_tagger_spec.rb index 23415b2..547f578 100644 --- a/spec/unit/emeril/git_tagger_spec.rb +++ b/spec/unit/emeril/git_tagger_spec.rb @@ -1,10 +1,10 @@ # -*- encoding: utf-8 -*- -require_relative '../../spec_helper' -require 'tmpdir' -require 'logger' +require_relative "../../spec_helper" +require "tmpdir" +require "logger" -require 'emeril/git_tagger' +require "emeril/git_tagger" describe Emeril::GitTagger do diff --git a/spec/unit/emeril/metadata_chopper_spec.rb b/spec/unit/emeril/metadata_chopper_spec.rb index 01484ed..fc7a242 100644 --- a/spec/unit/emeril/metadata_chopper_spec.rb +++ b/spec/unit/emeril/metadata_chopper_spec.rb @@ -1,8 +1,8 @@ # -*- encoding: utf-8 -*- -require_relative '../../spec_helper' +require_relative "../../spec_helper" -require 'emeril/metadata_chopper' +require "emeril/metadata_chopper" describe Emeril::MetadataChopper do @@ -56,7 +56,7 @@ def stub_metadata!(name = "foobar", version = "5.2.1") File.open("/tmp/metadata.rb", "wb") do |f| - f.write <<-METADATA_RB.gsub(/^ {8}/, '') + f.write <<-METADATA_RB.gsub(/^ {8}/, "") name "#{name}" maintainer "Michael Bluth" maintainer_email "michael@bluth.com" diff --git a/spec/unit/emeril/publisher_spec.rb b/spec/unit/emeril/publisher_spec.rb index 7ed2185..eac68a3 100644 --- a/spec/unit/emeril/publisher_spec.rb +++ b/spec/unit/emeril/publisher_spec.rb @@ -1,11 +1,12 @@ # -*- encoding: utf-8 -*- -require_relative '../../spec_helper' -require 'chef/knife' -require 'chef/config' +require_relative "../../spec_helper" +require "chef/knife" +require "chef/config" -require 'emeril/publisher' +require "emeril/publisher" +# Dummy Knife plugin class DummyKnife < Emeril::Publisher::SharePlugin def run; end @@ -17,7 +18,7 @@ def run; end let(:category) { "Utilities" } let(:publisher) do - if ENV['DEBUG'] + if ENV["DEBUG"] logger = Logger.new(STDOUT) logger.level = Logger::DEBUG else @@ -199,7 +200,7 @@ def make_cookbook! FileUtils.mkdir_p("#{cookbook_path}/recipes") File.open("#{cookbook_path}/metadata.rb", "wb") do |f| - f.write <<-METADATA_RB.gsub(/^ {8}/, '') + f.write <<-METADATA_RB.gsub(/^ {8}/, "") name "#{name}" maintainer "Michael Bluth" maintainer_email "michael@bluth.com" @@ -210,7 +211,7 @@ def make_cookbook! METADATA_RB end File.open("#{cookbook_path}/recipes/default.rb", "wb") do |f| - f.write <<-DEFAULT_RB.gsub(/^ {8}/, '') + f.write <<-DEFAULT_RB.gsub(/^ {8}/, "") directory "/tmp/yeah" package "bash" diff --git a/spec/unit/emeril/releaser_spec.rb b/spec/unit/emeril/releaser_spec.rb index 1851b04..b6cad2c 100644 --- a/spec/unit/emeril/releaser_spec.rb +++ b/spec/unit/emeril/releaser_spec.rb @@ -1,8 +1,8 @@ # -*- encoding: utf-8 -*- -require_relative '../../spec_helper' +require_relative "../../spec_helper" -require 'emeril/releaser' +require "emeril/releaser" describe Emeril::Releaser do @@ -150,8 +150,9 @@ releaser.run end - describe 'when disabling community site publishing' do - it 'does not call #run on publisher' do + describe "when disabling community site publishing" do + + it "does not call #run on publisher" do releaser = Emeril::Releaser.new( :metadata => metadata, :category => category, From 4accabeab8f5aa7b787902c87d8657154018be66 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Tue, 5 Aug 2014 15:58:39 -0600 Subject: [PATCH 24/25] Add utf-8 encoding comment in Rake (Ruby 1.9 compat). --- Rakefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Rakefile b/Rakefile index f5a2b47..ca174bd 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# -*- encoding: utf-8 -*- + require "bundler/gem_tasks" require "rake/testtask" require "cane/rake_task" From 12f8965d2facf39994ec528cba377fca2d33a80d Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Tue, 5 Aug 2014 17:10:30 -0600 Subject: [PATCH 25/25] Ensure cache path is writable for old Chef/Moneta testing. --- spec/integration/new_release_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/integration/new_release_spec.rb b/spec/integration/new_release_spec.rb index e0c7a67..2b32de1 100644 --- a/spec/integration/new_release_spec.rb +++ b/spec/integration/new_release_spec.rb @@ -33,6 +33,8 @@ Chef::Config[:node_name] = ENV["CHEF_NODE_NAME"] || "opsycodesy" Chef::Config[:client_key] = ENV["CHEF_CLIENT_KEY"] || make_client_key! + Chef::Config[:cache_options][:path] = + File.join(File.dirname(cookbook_path), "cache") end after do @@ -40,7 +42,7 @@ Chef::Config[attr] = @saved.delete(attr) end - FileUtils.remove_dir(cookbook_path) + FileUtils.remove_dir(File.dirname(cookbook_path)) end let(:cookbook_path) { File.join(Dir.mktmpdir, "emeril") }