Class: XCTasks::TestTask

Inherits:
Rake::TaskLib
  • Object
show all
Extended by:
Configuration::Delegations
Includes:
Rake::DSL
Defined in:
lib/xctasks/test_task.rb

Defined Under Namespace

Classes: Configuration, ConfigurationError, Destination, Subtask

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Configuration::Delegations

extended

Constructor Details

#initialize(namespace_name = :test) {|_self| ... } ⇒ TestTask

Returns a new instance of TestTask.

Yields:

  • (_self)

Yield Parameters:

Raises:



304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/xctasks/test_task.rb', line 304

def initialize(namespace_name = :test)
  @namespace_name = namespace_name
  @config = Configuration.new
  @subtasks = []
  @destination
  @namespace_name = namespace_name.kind_of?(Hash) ? namespace_name.keys.first : namespace_name
  @prepare_dependency = namespace_name.kind_of?(Hash) ? namespace_name.values.first : nil

  yield self if block_given?
  raise ConfigurationError, "A workspace or project must be configured" unless workspace || project
  raise ConfigurationError, "At least one subtask must be configured" if subtasks.empty?
  define_rake_tasks
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



301
302
303
# File 'lib/xctasks/test_task.rb', line 301

def config
  @config
end

#destination(specifier = {}) ⇒ Object (readonly)

Returns the value of attribute destination.



301
302
303
# File 'lib/xctasks/test_task.rb', line 301

def destination
  @destination
end

#namespace_nameObject (readonly)

Returns the value of attribute namespace_name.



301
302
303
# File 'lib/xctasks/test_task.rb', line 301

def namespace_name
  @namespace_name
end

#prepare_dependencyObject (readonly)

Returns the value of attribute prepare_dependency.



301
302
303
# File 'lib/xctasks/test_task.rb', line 301

def prepare_dependency
  @prepare_dependency
end

#subtasksObject

Returns the value of attribute subtasks.



301
302
303
# File 'lib/xctasks/test_task.rb', line 301

def subtasks
  @subtasks
end

Instance Method Details

#define_rake_tasksObject



349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
# File 'lib/xctasks/test_task.rb', line 349

def define_rake_tasks
  namespace self.namespace_name do
    task (prepare_dependency ? { prepare: prepare_dependency} : :prepare ) do
      if workspace
        fail "No such workspace: #{workspace}" unless File.exists?(workspace)
      else
        fail "No such project: #{project}" unless File.exists?(project)
      end

      fail "Invalid schemes directory: #{schemes_dir}" unless schemes_dir.nil? || File.exists?(schemes_dir)
      File.truncate(output_log, 0) if output_log && File.exists?(output_log)
      if schemes_dir
        FileUtils::Verbose.mkdir_p "#{workspace || project}/xcshareddata/xcschemes"
        FileUtils::Verbose.cp Dir.glob("#{schemes_dir}/*.xcscheme"), "#{workspace || project}/xcshareddata/xcschemes"
      end
      subtasks.each { |subtask| subtask.prepare }
    end

    subtasks.each { |subtask| subtask.define_rake_tasks }
  end

  subtask_names = subtasks.map { |subtask| subtask.name }
  desc "Run all tests (#{subtask_names.join(', ')})"
  task namespace_name => subtask_names.map { |subtask_name| "#{namespace_name}:#{subtask_name}" } do
    XCTasks::TestReport.instance.report
  end
end

#subtask(name_options) {|subtask| ... } ⇒ Object

Yields:



326
327
328
329
330
331
332
333
# File 'lib/xctasks/test_task.rb', line 326

def subtask(name_options)
  subtask = Subtask.new(name_options, config)
  yield subtask if block_given?
  if @destination
    subtask.destination @destination
  end
  @subtasks << subtask
end