class XCTestRunner

Constants

VERSION

Public Class Methods

new(opts = {}) click to toggle source
# File lib/xctest-runner.rb, line 12
def initialize(opts = {})
  @clean = opts[:clean] || false
  @scheme = opts[:scheme] || nil
  @project = opts[:project] || nil
  @workspace = opts[:workspace] || nil
  @sdk = opts[:sdk] || 'iphonesimulator'
  @configuration = opts[:configuration] || 'Debug'
  @arch = opts[:arch] || nil
  @test_class = opts[:test] || 'Self'
  @suffix = opts[:suffix] || ''

  @scheme = default_scheme(build_command) unless @scheme
  @env = current_environment(build_command)
  @arch = default_build_arch if @arch.nil?
  @build_option = nil
end

Public Instance Methods

arch_command() click to toggle source
# File lib/xctest-runner.rb, line 57
def arch_command
  unless @arch_command
    @arch_command = native_arch ? "arch -arch #{native_arch}" : ''
  end
  @arch_command
end
build() click to toggle source
# File lib/xctest-runner.rb, line 125
def build
  execute_command("#{build_command} #{@suffix}", true)
end
build_command() click to toggle source
# File lib/xctest-runner.rb, line 111
def build_command
  "#{xcodebuild} #{build_option}"
end
build_option() click to toggle source
# File lib/xctest-runner.rb, line 80
def build_option
  unless @build_option
    options = []
    options << "-scheme #{@scheme}" if @scheme
    options << "-project #{@project}" if @project
    options << "-workspace #{@workspace}" if @workspace
    options << "-sdk #{@sdk}" if @sdk
    options << "-configuration #{@configuration}" if @configuration
    options << "-arch #{@arch} #{valid_archs}" if @arch
    @build_option = options.join(' ')
  end
  @build_option
end
bundle_path() click to toggle source
# File lib/xctest-runner.rb, line 33
def bundle_path
  @bundle_path ||= "#{@env['BUILT_PRODUCTS_DIR']}/#{@env['EXECUTABLE_FOLDER_PATH']}"
end
clean() click to toggle source
# File lib/xctest-runner.rb, line 121
def clean
  execute_command(clean_command, true)
end
clean_command() click to toggle source
# File lib/xctest-runner.rb, line 107
def clean_command
  "#{xcodebuild} clean #{build_option}"
end
default_build_arch() click to toggle source
# File lib/xctest-runner.rb, line 68
def default_build_arch
  if @env && @env && @env['VALID_ARCHS'] && @env['CURRENT_ARCH']
    @env['VALID_ARCHS'].include?(@env['CURRENT_ARCH']) ? nil : 'i386'
  end
end
executable_path() click to toggle source
# File lib/xctest-runner.rb, line 37
def executable_path
  @executable_path ||= "#{@env['BUILT_PRODUCTS_DIR']}/#{@env['EXECUTABLE_PATH']}"
end
is_valid_arch?(arch) click to toggle source
# File lib/xctest-runner.rb, line 41
def is_valid_arch?(arch)
  ['i386', 'x86_64'].include?(arch)
end
native_arch() click to toggle source
# File lib/xctest-runner.rb, line 45
def native_arch
  unless @native_arch
    arch = `file #{executable_path}`.split(' ').last
    if is_valid_arch?(arch)
      @native_arch = arch
    else
      @native_arch = @env['CURRENT_ARCH']
    end
  end
  is_valid_arch?(@native_arch) ? @native_arch : 'i386'
end
run() click to toggle source
# File lib/xctest-runner.rb, line 134
def run
  temp_scheme_path = copy_xcscheme_if_need(@scheme)
  @scheme = temp_scheme if temp_scheme_path

  clean if @clean
  if build
    test(@test_class)
  end

  remove_scheme(temp_scheme_path) if temp_scheme_path
end
sdk_root() click to toggle source
# File lib/xctest-runner.rb, line 29
def sdk_root
  @sdk_root ||= @env['SDK_DIR']
end
test(test_class = 'Self') click to toggle source
# File lib/xctest-runner.rb, line 129
def test(test_class = 'Self')
  command = test_command(test_class)
  execute_command("#{command} #{@suffix}", true)
end
test_command(test_class) click to toggle source
# File lib/xctest-runner.rb, line 115
def test_command(test_class)
  xctest_command = xctest
  additional_options = "-NSTreatUnknownArgumentsAsOpen NO -ApplePersistenceIgnoreState YES"
  "#{xctest_command} -XCTest #{test_class} #{additional_options} #{bundle_path}"
end
valid_archs() click to toggle source
# File lib/xctest-runner.rb, line 74
def valid_archs
  if @env && @env['VALID_ARCHS'] && @env['CURRENT_ARCH']
    @env['VALID_ARCHS'].include?(@env['CURRENT_ARCH']) ? '' : "VALID_ARCHS=#{@arch}"
  end
end
xcodebuild() click to toggle source
# File lib/xctest-runner.rb, line 64
def xcodebuild
  @xcodebuild ||= 'xcodebuild'
end
xctest() click to toggle source
# File lib/xctest-runner.rb, line 99
def xctest
  unless @xctest
    xctest_command = "#{@env['SDK_DIR']}/Developer/usr/bin/xctest"
    @xctest = "#{arch_command} #{xctest_environment} #{xctest_command}"
  end
  @xctest
end
xctest_environment() click to toggle source
# File lib/xctest-runner.rb, line 95
def xctest_environment
  @xctest_environment ||= "-e DYLD_ROOT_PATH='#{sdk_root}'"
end