diff --git a/Gemfile b/Gemfile index 726c3cc9..563d5d29 100644 --- a/Gemfile +++ b/Gemfile @@ -5,7 +5,7 @@ source 'https://rubygems.org' # Specify your gem's dependencies in hawk.gemspec gemspec -gem 'appraisal' +gem 'appraisal2' gem 'bundler' gem 'byebug' gem 'pry' diff --git a/Rakefile b/Rakefile index ad0c1276..8223eb83 100644 --- a/Rakefile +++ b/Rakefile @@ -8,16 +8,10 @@ require 'bundler/gem_tasks' require 'rspec/core/rake_task' RSpec::Core::RakeTask.new -# Appraisal -require 'appraisal/task' -Appraisal::Task.new - # Yard require 'yard' YARD::Rake::YardocTask.new -# Our default rake task -require 'hawk/rake' -Hawk::Rake::DefaultTask.new +task default: :spec # Thanks for reading. diff --git a/lib/hawk/rake.rb b/lib/hawk/rake.rb deleted file mode 100644 index 2cbaddca..00000000 --- a/lib/hawk/rake.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -module Hawk - ## - # Namespace to all rake-related functionality. - # - module Rake - autoload :Utils, 'hawk/rake/utils.rb' - autoload :DefaultTask, 'hawk/rake/default_task.rb' - end -end diff --git a/lib/hawk/rake/default_task.rb b/lib/hawk/rake/default_task.rb deleted file mode 100644 index 737fe6c9..00000000 --- a/lib/hawk/rake/default_task.rb +++ /dev/null @@ -1,180 +0,0 @@ -# frozen_string_literal: true - -module Hawk - module Rake - ## - # Defines the default Eaco rake task. It runs tests and generates the docs. - # - # Usage: - # - # Eaco::Rake::DefaultTask.new - # - class DefaultTask - include ::Rake::DSL if defined?(::Rake::DSL) - - ## - # Main +Eaco+ rake task. - # - # If running appraisals or running within CI, run all specs. - # - def initialize - if running_appraisals? - task :default do - run_specs - end - - elsif running_in_ci? - task :default do - run_specs - end - - else - desc 'Appraises specs and cucumber, generates documentation' - task :default do - run_appraisals - generate_documentation - end - - end - end - - ## - # Runs all appraisals (see +Appraisals+ in the source root) - # against the defined Rails version and generates the source - # documentation using Yard. - # - # Runs them in a subprocess as the appraisals gem makes use - # of fork/exec hijacking the process session root. - # - # @raise [RuntimeError] if the appraisals run fails. - # - # @return [void] - # - def run_appraisals - croak 'Running all appraisals' - - pid = fork { invoke :appraisal } - _, status = Process.wait2(pid) - unless status.exitstatus == 0 - bail "Appraisals failed with status #{status.exitstatus}" - end - end - - ## - # Generate the documentation using +Yard+. - # - def generate_documentation - croak 'Generating documentation' - - invoke :yard - end - - ## - # Runs all specs under the +spec/+ directory - # - # @return [void] - # - def run_specs - croak 'Running specs' - - invoke :spec - end - - ## - # Runs all cucumber features in the +features/+ directory - # - # @return [void] - # - def run_cucumber - croak 'Evaluating cucumber features' - - invoke :cucumber - end - - private - - ## - # Invokes the given rake task. - # - # @param task [Symbol] the task to invoke. - # @return [void] - # - def invoke(task) - ::Rake::Task[task].invoke - end - - ## - # Fancily logs the given +msg+ to +$stderr+. - # - # @param msg [String] the message to bail out. - # - # @return [nil] - # - def croak(msg) - warn fancy(with_appraisal(msg)) - end - - ## - # Bails out the given error message. - # - # @param msg [String] the message to bail - # @raise [RuntimeError] - # - def bail(msg) - raise fancy(msg).to_s - end - - ## - # Adds the current appraisal name to msg, if present - # - # @param msg [String] - # @return [String] - # - def with_appraisal(msg) - if gemfile - msg = "%s \033[1;31m[%s]" % [msg, gemfile] - end - - msg - end - - ## - # Makes +msg+ fancy. - # - # @param msg [String] - # @return [String] - # - def fancy(msg) - <<~MSG - \033[0m - \033[1;32m>>> - \033[1;32m>>> HAWK: \033[1;37m#{msg} - \033[1;32m>>> - \033[0m - MSG - end - - ## - # @see Rake::Utils.gemfile - # @private - # - def gemfile - Rake::Utils.gemfile - end - - ## - # @return [Boolean] Are we running appraisals? - # - def running_appraisals? - ENV['APPRAISAL_INITIALIZED'] - end - - ## - # @return [Boolean] Are we running on CI? - # - def running_in_ci? - ENV['CI'] - end - end - end -end diff --git a/lib/hawk/rake/utils.rb b/lib/hawk/rake/utils.rb deleted file mode 100644 index bd76e0a6..00000000 --- a/lib/hawk/rake/utils.rb +++ /dev/null @@ -1,38 +0,0 @@ -# frozen_string_literal: true - -module Hawk - module Rake - ## - # Assorted utilities. - # - module Utils - extend self - - ## - # Captures the stdout emitted by the given +block+ - # - # @return [String] the captured output - # - def capture_stdout - stdout = $stdout - string = StringIO.new - $stdout = string - - yield - - string.tap(&:rewind).read - ensure - $stdout = stdout - end - - ## - # @return [String] the current gemfile name - # - def gemfile - gemfile = ENV['BUNDLE_GEMFILE'] - - File.basename(gemfile, '.*') if gemfile - end - end - end -end