Class: Eaco::Rake::DefaultTask
- Inherits:
-
Object
- Object
- Eaco::Rake::DefaultTask
- Includes:
- Rake::DSL
- Defined in:
- lib/eaco/rake/default_task.rb
Overview
Defines the default Eaco rake task. It runs tests and generates the docs.
Usage:
Eaco::Rake::DefaultTask.new
Instance Method Summary collapse
-
#bail(msg) ⇒ Object
private
Bails out the given error message.
-
#croak(msg) ⇒ nil
private
Fancily logs the given
msgto $stderr. -
#fancy(msg) ⇒ String
private
Makes
msgfancy. -
#generate_documentation ⇒ Object
Generate the documentation using
Yard. -
#initialize ⇒ DefaultTask
constructor
Main
Eacorake task. -
#invoke(task)
private
Invokes the given rake task.
-
#output_coverage
private
Formats code coverage results and prints a summary.
-
#report_coverage
private
Reports coverage data.
-
#run_appraisals
Runs all appraisals (see
Appraisalsin the source root) against the defined Rails version and generates the source documentation using Yard. -
#run_cucumber
Runs all cucumber features in the
features/directory. -
#run_specs
Runs all specs under the
spec/directory. -
#running_appraisals? ⇒ Boolean
private
Are we running appraisals?.
-
#running_in_travis? ⇒ Boolean
private
Are we running on Travis CI?.
-
#with_appraisal(msg) ⇒ String
private
Adds the current appraisal name to msg, if present.
Constructor Details
#initialize ⇒ DefaultTask
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.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# 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 generate_documentation end else desc 'Appraises specs and cucumber, generates documentation' task :default do run_appraisals generate_documentation end end end |
Instance Method Details
#bail(msg) ⇒ Object (private)
Bails out the given error message.
157 158 159 |
# File 'lib/eaco/rake/default_task.rb', line 157 def bail(msg) raise RuntimeError, fancy(msg) end |
#croak(msg) ⇒ nil (private)
Fancily logs the given msg to $stderr.
147 148 149 |
# File 'lib/eaco/rake/default_task.rb', line 147 def croak(msg) $stderr.puts fancy(with_appraisal(msg)) end |
#fancy(msg) ⇒ String (private)
Makes msg fancy.
181 182 183 184 185 186 187 188 189 |
# File 'lib/eaco/rake/default_task.rb', line 181 def fancy(msg) "\\033[0m\n\\033[1;32m>>>\n\\033[1;32m>>> EACO: \\033[1;37m\#{msg}\n\\033[1;32m>>>\n\\033[0m\n EOF\nend\n" |
#generate_documentation ⇒ Object
Generate the documentation using Yard.
81 82 83 84 85 |
# File 'lib/eaco/rake/default_task.rb', line 81 def generate_documentation croak 'Generating documentation' invoke :yard end |
#invoke(task) (private)
This method returns an undefined value.
Invokes the given rake task.
117 118 119 |
# File 'lib/eaco/rake/default_task.rb', line 117 def invoke(task) ::Rake::Task[task].invoke end |
#output_coverage (private)
This method returns an undefined value.
Formats code coverage results and prints a summary
135 136 137 138 |
# File 'lib/eaco/rake/default_task.rb', line 135 def output_coverage summary = Eaco::Coverage.format! croak summary end |
#report_coverage (private)
This method returns an undefined value.
Reports coverage data
126 127 128 |
# File 'lib/eaco/rake/default_task.rb', line 126 def report_coverage Eaco::Coverage.report! end |
#run_appraisals
This method returns an undefined value.
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.
68 69 70 71 72 73 74 75 76 |
# File 'lib/eaco/rake/default_task.rb', line 68 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 |
#run_cucumber
This method returns an undefined value.
Runs all cucumber features in the features/ directory
103 104 105 106 107 |
# File 'lib/eaco/rake/default_task.rb', line 103 def run_cucumber croak 'Evaluating cucumber features' invoke :cucumber end |
#run_specs
This method returns an undefined value.
Runs all specs under the spec/ directory
92 93 94 95 96 |
# File 'lib/eaco/rake/default_task.rb', line 92 def run_specs croak 'Running specs' invoke :spec end |
#running_appraisals? ⇒ Boolean (private)
Returns Are we running appraisals?.
202 203 204 |
# File 'lib/eaco/rake/default_task.rb', line 202 def running_appraisals? ENV["APPRAISAL_INITIALIZED"] end |
#running_in_travis? ⇒ Boolean (private)
Returns Are we running on Travis CI?.
209 210 211 |
# File 'lib/eaco/rake/default_task.rb', line 209 def running_in_travis? ENV["TRAVIS"] end |
#with_appraisal(msg) ⇒ String (private)
Adds the current appraisal name to msg, if present
167 168 169 170 171 172 173 |
# File 'lib/eaco/rake/default_task.rb', line 167 def with_appraisal(msg) if gemfile msg = "%s \033[1;31m[%s]" % [msg, gemfile] end return msg end |