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:



110
111
112
113
114
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
# File 'lib/right_develop/ci/rake_task.rb', line 110

def initialize(*args)
  @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',
                      '-o', File.join(@output_path, 'rspec', @rspec_output)]

      # RSpec 2
      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',
                      '-f', 'RightDevelop::CI::RSpecFormatter' + ":" + File.join(@output_path, 'rspec', @rspec_output)]

      # 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 = ['--no-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



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

def ci_namespace
  @ci_namespace
end

#cucumber_descObject

The description for the Cucumber task.

Default “Run Cucumber examples”



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

def cucumber_desc
  @cucumber_desc
end

#cucumber_nameObject

The name for the Cucumber task.

Default :cucumber



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

def cucumber_name
  @cucumber_name
end

#output_pathObject

The base directory for all output files.

Default ‘measurement’



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

def output_path
  @output_path
end

#rspec_descObject

The description for the RSpec task.

Default “Run RSpec examples”



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

def rspec_desc
  @rspec_desc
end

#rspec_nameObject

The name for the RSpec task.

Default :spec



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

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"]


98
99
100
# File 'lib/right_develop/ci/rake_task.rb', line 98

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


75
76
77
# File 'lib/right_develop/ci/rake_task.rb', line 75

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)



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

def rspec_pattern
  @rspec_pattern
end