Class: Eaco::Rake::DefaultTask

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeDefaultTask

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
# 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

Instance Method Details

#bail(msg) ⇒ Object (private)

Bails out the given error message.

Parameters:

  • msg (String)

    the message to bail

Raises:

  • (RuntimeError)

156
157
158
# File 'lib/eaco/rake/default_task.rb', line 156

def bail(msg)
  raise RuntimeError, fancy(msg)
end

#croak(msg) ⇒ nil (private)

Fancily logs the given msg to $stderr.

Parameters:

  • msg (String)

    the message to bail out.

Returns:

  • (nil)

146
147
148
# File 'lib/eaco/rake/default_task.rb', line 146

def croak(msg)
  $stderr.puts fancy(with_appraisal(msg))
end

#fancy(msg) ⇒ String (private)

Makes msg fancy.

Parameters:

  • msg (String)

Returns:

  • (String)

180
181
182
183
184
185
186
187
188
# 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

#generate_documentationObject

Generate the documentation using Yard.


80
81
82
83
84
# File 'lib/eaco/rake/default_task.rb', line 80

def generate_documentation
  croak 'Generating documentation'

  invoke :yard
end

#invoke(task) (private)

This method returns an undefined value.

Invokes the given rake task.

Parameters:

  • task (Symbol)

    the task to invoke.


116
117
118
# File 'lib/eaco/rake/default_task.rb', line 116

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


134
135
136
137
# File 'lib/eaco/rake/default_task.rb', line 134

def output_coverage
  summary = Eaco::Coverage.format!
  croak summary
end

#report_coverage (private)

This method returns an undefined value.

Reports coverage data


125
126
127
# File 'lib/eaco/rake/default_task.rb', line 125

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.

Raises:

  • (RuntimeError)

    if the appraisals run fails.


67
68
69
70
71
72
73
74
75
# 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

#run_cucumber

This method returns an undefined value.

Runs all cucumber features in the features/ directory


102
103
104
105
106
# File 'lib/eaco/rake/default_task.rb', line 102

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


91
92
93
94
95
# File 'lib/eaco/rake/default_task.rb', line 91

def run_specs
  croak 'Running specs'

  invoke :spec
end

#running_appraisals?Boolean (private)

Returns Are we running appraisals?.

Returns:

  • (Boolean)

    Are we running appraisals?


201
202
203
# File 'lib/eaco/rake/default_task.rb', line 201

def running_appraisals?
  ENV["APPRAISAL_INITIALIZED"]
end

#running_in_travis?Boolean (private)

Returns Are we running on Travis CI?.

Returns:

  • (Boolean)

    Are we running on Travis CI?


208
209
210
# File 'lib/eaco/rake/default_task.rb', line 208

def running_in_travis?
  ENV["TRAVIS"]
end

#with_appraisal(msg) ⇒ String (private)

Adds the current appraisal name to msg, if present

Parameters:

  • msg (String)

Returns:

  • (String)

166
167
168
169
170
171
172
# 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