Skip to content

Instantly share code, notes, and snippets.

@AlexDenisov
Created May 24, 2012 06:31

Revisions

  1. AlexDenisov revised this gist May 24, 2012. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions calabash-ios-ci.rb
    Original file line number Diff line number Diff line change
    @@ -2,9 +2,7 @@
    require "getoptlong"

    getoptlong = GetoptLong.new(
    [ '--sdk', '-s', GetoptLong::REQUIRED_ARGUMENT ],
    [ '--target', '-t', GetoptLong::REQUIRED_ARGUMENT ],
    [ '--configuration', '-c', GetoptLong::REQUIRED_ARGUMENT ],
    [ '--log-file', '-l', GetoptLong::REQUIRED_ARGUMENT ],
    [ '--source-root', '-r', GetoptLong::REQUIRED_ARGUMENT ]

  2. AlexDenisov created this gist May 24, 2012.
    80 changes: 80 additions & 0 deletions calabash-ios-ci.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,80 @@
    #!/usr/bin/ruby
    require "getoptlong"

    getoptlong = GetoptLong.new(
    [ '--sdk', '-s', GetoptLong::REQUIRED_ARGUMENT ],
    [ '--target', '-t', GetoptLong::REQUIRED_ARGUMENT ],
    [ '--configuration', '-c', GetoptLong::REQUIRED_ARGUMENT ],
    [ '--log-file', '-l', GetoptLong::REQUIRED_ARGUMENT ],
    [ '--source-root', '-r', GetoptLong::REQUIRED_ARGUMENT ]

    )

    def printUsage()
    puts "Usage:"
    puts "calabash-ios.rb --source-root source_path --target project_target"
    end

    source_root = nil
    target = nil
    arch = "iphonesimulator"
    configuration = "Release"
    log_file = nil

    begin
    getoptlong.each do |opt, arg|
    case opt
    when "--source-root"
    source_root = arg
    when "--target"
    target = arg
    when "--log-file"
    log_file = arg
    end
    end
    rescue StandardError=>my_error_message
    puts
    puts my_error_message
    printUsage()
    puts
    exit 1
    end

    if target.nil? or source_root.nil?
    puts "You must specify target and source root"
    printUsage
    exit 1
    end
    app_path = "#{source_root}/build/#{configuration}-#{arch}/#{target}.app"
    %x[ rm -rf #{app_path}]

    cedar_test_target = "cd #{source_root} && xcodebuild -target '#{target}' -sdk #{arch} -configuration #{configuration} clean build "
    cedar_test_target_exit_code = system(cedar_test_target)

    if cedar_test_target_exit_code
    puts "Calabash target build succeeded"
    puts
    else
    puts "Calabash target build failed"
    exit 1
    end

    log_file = "/tmp/calabash-#{target}-#{Time.now.to_i}.log" if log_file.nil?

    test_command = "cucumber"

    system("APP_BUNDLE_PATH='#{app_path}' OS=ios5 #{test_command} -o #{log_file} --no-color --require features")

    grep_exit_code = system("grep -q \"failed\" #{log_file}")

    File.open(log_file, 'r') do |f1|
    while line = f1.gets
    puts line
    end
    end

    if grep_exit_code
    puts "Cucumber failed"
    exit 1
    end
    exit 0