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.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/eaco/rake/default_task.rb', line 28

def initialize
  if running_appraisals?
    task :default do
      run_specs
      run_cucumber
    end

  elsif running_in_travis?
    task :default do
      run_specs
      run_cucumber
      generate_documentation
    end

  else
    desc 'Appraises specs and cucumber, generates documentation'
    task :default do
      run_appraisals
      generate_documentation
    end

  end
end

Instance Method Details

#appraisalString (private)

Returns the current appraisal name, or nil.

Returns:

  • (String)

    the current appraisal name, or nil



171
172
173
174
175
176
177
# File 'lib/eaco/rake/default_task.rb', line 171

def appraisal
  return unless running_appraisals?

  gemfile = ENV['BUNDLE_GEMFILE']

  File.basename(gemfile, '.*') if gemfile
end

#bail(msg) ⇒ Object (private)

Bails out the given error message.

Parameters:

  • msg (String)

    the message to bail

Raises:

  • (RuntimeError)


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

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)


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

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

#fancy(msg) ⇒ String (private)

Makes msg fancy.

Parameters:

  • msg (String)

Returns:

  • (String)


158
159
160
161
162
163
164
165
166
# File 'lib/eaco/rake/default_task.rb', line 158

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_documentationObject

Generate the documentation using Yard.



77
78
79
80
81
# File 'lib/eaco/rake/default_task.rb', line 77

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.



113
114
115
# File 'lib/eaco/rake/default_task.rb', line 113

def invoke(task)
  ::Rake::Task[task].invoke
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.



64
65
66
67
68
69
70
71
72
# File 'lib/eaco/rake/default_task.rb', line 64

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



99
100
101
102
103
# File 'lib/eaco/rake/default_task.rb', line 99

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



88
89
90
91
92
# File 'lib/eaco/rake/default_task.rb', line 88

def run_specs
  croak 'Running specs'

  invoke :spec
end

#running_appraisals?Boolean (private)

Returns Are we running appraisals?.

Returns:

  • (Boolean)

    Are we running appraisals?



182
183
184
# File 'lib/eaco/rake/default_task.rb', line 182

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?



189
190
191
# File 'lib/eaco/rake/default_task.rb', line 189

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)


144
145
146
147
148
149
150
# File 'lib/eaco/rake/default_task.rb', line 144

def with_appraisal(msg)
  if appraisal
    msg = "%s \033[1;31m[%s]" % [msg, appraisal]
  end

  return msg
end