rayh/xcoder — pull request #58 by blakewatters (2013-03-15 16:57:59+00:00)
Title: Add KIF Output Parser

This pull request adds an output parser for the KIF integration testing framework from Square (see https://github.com/square/KIF). There are a few minor changes under the hood that were necessary to enable the parser:

* Switched the implementation from open3 to PTY to capture output flushed to stderr as well as stdout
* Replace all spaces with underscores in test names in the JUnit formatter. KIF scenarios are typically written as complete sentences.

For reference, I am running this via `ios-sim` with a Rake task:

```ruby
desc 'Run the GateGuru KIF integration tests suite'
task :integration do
scheme = Xcode.workspace(:GateGuru).scheme('Integration Tests')

# Execute the build quietly
cmd = scheme.builder.xcodebuild
cmd << "-sdk iphonesimulator"

output = []
begin
puts "Building target..."
Xcode::Shell.execute(cmd, false) do |line|
raise line if line =~ /BUILD FAILED/
output << line
end
rescue => e
puts output.join("\n")
raise e
end

# Run the Integration Tests
report = Xcode::Test::Report.new
cmd = Xcode::Shell::Command.new(%q{ios-sim launch "build/Products/Test-iphonesimulator/GateGuru (Integration Tests).app" --retina})

report.add_formatter :stdout, { :color_output => true }
report.add_formatter :junit, 'test-reports'

parser = Xcode::Test::Parsers::KIFParser.new(report)

begin
puts "Executing suite via command #{cmd}"
cmd.execute(false) do |line|
parser << line
end
rescue Xcode::Shell::ExecutionError => e
# FIXME: Perhaps we should always raise this?
raise e if report.suites.count==0
ensure
parser.flush
end
end
```