Class: RightDevelop::CI::RakeTask

Inherits:
Rake::TaskLib
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/right_develop/ci/rake_task.rb

Overview

A Rake task definition that creates a CI namespace with appropriate tests.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) {|_self| ... } ⇒ RakeTask

Returns a new instance of RakeTask.

Yields:

  • (_self)

Yield Parameters:



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/right_develop/ci/rake_task.rb', line 115

def initialize(*args)
  @fail_fast ||= false
  @ci_namespace = args.shift || :ci

  yield self if block_given?

  @output_path ||= 'measurement'
  @rspec_output ||= 'rspec.xml'
  @rspec_name ||= :spec
  @rspec_desc ||= "Run RSpec examples"
  @cucumber_name ||= :cucumber
  @cucumber_desc ||= "Run Cucumber examples"
  @rspec_opts ||= []

  namespace @ci_namespace do
    task :prep do
      FileUtils.mkdir_p(@output_path)
      FileUtils.mkdir_p(File.join(@output_path, 'rspec'))
      FileUtils.mkdir_p(File.join(@output_path, 'cucumber'))
    end

    spec = Gem.loaded_specs['rspec']
    ver  = spec && spec.version.to_s

    case ver
    when /^[23]/
      default_opts = ['-r', 'right_develop/ci',
                      '-f', 'RightDevelop::CI::RSpecFormatter',
                      '-c', # colo(u)r
                      '-o', File.join(@output_path, 'rspec', @rspec_output)]

      default_opts << '--fail-fast' if fail_fast

      # RSpec 2/3
      desc @rspec_desc
      RSpec::Core::RakeTask.new(@rspec_name => :prep) do |t|
        t.rspec_opts = default_opts + @rspec_opts
        unless self.rspec_pattern.nil?
          t.pattern = self.rspec_pattern
        end
      end
    when /^1/
      default_opts = ['-r', 'right_develop/ci',
                      '-c', # colo(u)r
                      '-f', 'RightDevelop::CI::RSpecFormatter' + ":" + File.join(@output_path, 'rspec', @rspec_output)]

      # Hackishly inject fail-fast behavior to our formatter living in the RSpec 1.x subprocess
      ENV['RIGHT_DEVELOP_FAIL_FAST'] = '1' if fail_fast

      # RSpec 1
      Spec::Rake::SpecTask.new(@rspec_name => :prep) do |t|
        desc @rspec_desc
        t.spec_opts = default_opts + @rspec_opts
        unless self.rspec_pattern.nil?
          t.spec_files = FileList[self.rspec_pattern]
        end
      end
    when nil
      warn "Cannot define right_develop ci:spec task: RSpec gem is unavailable"
    else
      raise LoadError, "Cannot define RightDevelop ci:spec task: unsupported RSpec version #{ver}"
    end

    spec = Gem.loaded_specs['cucumber']
    ver  = spec && spec.version.to_s

    case ver
    when /^1/
      Cucumber::Rake::Task.new(@cucumber_name, @cucumber_desc) do |t|
        t.cucumber_opts = ['--color',
                           '--format', JavaCucumberFormatter.name,
                           '--out', File.join(@output_path, 'cucumber')]
      end
      task :cucumber => [:prep]
    when nil
      warn "Cannot define right_develop ci:cucumber task: Cucumber gem is unavailable" 
    else
      raise LoadError, "Cannot define RightDevelop ci:cucumber task: unsupported Cucumber version #{ver}"
    end
  end
end

Instance Attribute Details

#ci_namespaceObject

The namespace in which to define the continuous integration tasks.

Default :ci



62
63
64
# File 'lib/right_develop/ci/rake_task.rb', line 62

def ci_namespace
  @ci_namespace
end

#cucumber_descObject

The description for the Cucumber task.

Default “Run Cucumber examples”



113
114
115
# File 'lib/right_develop/ci/rake_task.rb', line 113

def cucumber_desc
  @cucumber_desc
end

#cucumber_nameObject

The name for the Cucumber task.

Default :cucumber



108
109
110
# File 'lib/right_develop/ci/rake_task.rb', line 108

def cucumber_name
  @cucumber_name
end

#fail_fastBoolean

Whether the Rake task should try to configure tests to fail fast. (Behavior varies between rspec and cucumber, and also between versions of rspec.)

Returns:

  • (Boolean)


57
58
59
# File 'lib/right_develop/ci/rake_task.rb', line 57

def fail_fast
  @fail_fast
end

#output_pathObject

The base directory for all output files.

Default ‘measurement’



85
86
87
# File 'lib/right_develop/ci/rake_task.rb', line 85

def output_path
  @output_path
end

#rspec_descObject

The description for the RSpec task.

Default “Run RSpec examples”



95
96
97
# File 'lib/right_develop/ci/rake_task.rb', line 95

def rspec_desc
  @rspec_desc
end

#rspec_nameObject

The name for the RSpec task.

Default :spec



90
91
92
# File 'lib/right_develop/ci/rake_task.rb', line 90

def rspec_name
  @rspec_name
end

#rspec_optsObject

An array of additional options for the RSpec task.

Default: []

Use like:

rspec_opts = ["-t", "~slow_specs"]


103
104
105
# File 'lib/right_develop/ci/rake_task.rb', line 103

def rspec_opts
  @rspec_opts
end

#rspec_outputObject

Filename (without directory!) to which RSpec XML results should be written. The CI task will take output_path, append “rspec” as a subdir and finally append this file name, to come up with a relative path for output. For example:

Default “rspec.xml”

output_path = "my_cool_ci"
rspec_output = "my_awesome_rspec.xml"

Given the options above, the CI harness would write RSpec results to:

my_cool_ci/rspec/my_awesome_rspec.xml


80
81
82
# File 'lib/right_develop/ci/rake_task.rb', line 80

def rspec_output
  @rspec_output
end

#rspec_patternObject

File glob to select which specs will be run with the spec task.

Default nil (let RSpec choose pattern)



67
68
69
# File 'lib/right_develop/ci/rake_task.rb', line 67

def rspec_pattern
  @rspec_pattern
end