class Eaco::Rake::DefaultTask
Defines the default Eaco
rake task. It runs tests and generates the docs.
Usage:
Eaco::Rake::DefaultTask.new
Public Class Methods
Main Eaco
rake task.
If running appraisals or running within Travis CI, run all specs and cucumber features.
The concept here is to prepare the environment with the gems set we are testing against, and this is done by Appraisals and Travis, albeit in a different way. The first uses the Appraisals
file, the second instead relies on the .travis.yml
configuration.
Documentation is generated at the end, once if running locally, but multiple times, once for each appraisal, on Travis.
# File lib/eaco/rake/default_task.rb, line 30 def initialize if running_appraisals? task :default do run_specs run_cucumber output_coverage end elsif running_in_travis? task :default do run_specs run_cucumber report_coverage end else desc 'Appraises specs and cucumber, generates documentation' task :default do run_appraisals generate_documentation end end end
Public Instance Methods
Generate the documentation using Yard
.
# File lib/eaco/rake/default_task.rb, line 80 def generate_documentation croak 'Generating documentation' invoke :yard 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]
# File lib/eaco/rake/default_task.rb, line 67 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
Runs all cucumber features in the features/
directory
@return [void]
# File lib/eaco/rake/default_task.rb, line 102 def run_cucumber croak 'Evaluating cucumber features' invoke :cucumber end
Runs all specs under the spec/
directory
@return [void]
# File lib/eaco/rake/default_task.rb, line 91 def run_specs croak 'Running specs' invoke :spec end
Private Instance Methods
Bails out the given error message.
@param msg [String] the message to bail @raise [RuntimeError]
# File lib/eaco/rake/default_task.rb, line 156 def bail(msg) raise RuntimeError, fancy(msg) end
Fancily logs the given msg
to +$stderr+.
@param msg [String] the message to bail out.
@return [nil]
# File lib/eaco/rake/default_task.rb, line 146 def croak(msg) $stderr.puts fancy(with_appraisal(msg)) end
Makes msg
fancy.
@param msg [String] @return [String]
# File lib/eaco/rake/default_task.rb, line 180 def fancy(msg) <<-EOF \033[0m \033[1;32m>>> \033[1;32m>>> EACO: \033[1;37m#{msg} \033[1;32m>>> \033[0m EOF end
@see {Rake::Utils.gemfile} @private
# File lib/eaco/rake/default_task.rb, line 194 def gemfile Rake::Utils.gemfile end
Invokes the given rake task.
@param task [Symbol] the task to invoke. @return [void]
# File lib/eaco/rake/default_task.rb, line 116 def invoke(task) ::Rake::Task[task].invoke end
Formats code coverage results and prints a summary
@return [void]
# File lib/eaco/rake/default_task.rb, line 134 def output_coverage summary = Eaco::Coverage.format! croak summary end
Reports coverage data
@return [void]
# File lib/eaco/rake/default_task.rb, line 125 def report_coverage Eaco::Coverage.report! end
@return [Boolean] Are we running appraisals?
# File lib/eaco/rake/default_task.rb, line 201 def running_appraisals? ENV["APPRAISAL_INITIALIZED"] end
@return [Boolean] Are we running on Travis CI?
# File lib/eaco/rake/default_task.rb, line 208 def running_in_travis? ENV["TRAVIS"] end
Adds the current appraisal name to msg, if present
@param msg [String] @return [String]
# File lib/eaco/rake/default_task.rb, line 166 def with_appraisal(msg) if gemfile msg = "%s \033[1;31m[%s]" % [msg, gemfile] end return msg end