Class: GHRunit
Instance Method Summary collapse
-
#buffer ⇒ Object
Will store all ‘stdout`-output.
- #default_options ⇒ Object
-
#error ⇒ Object
Not being used for now.
-
#initialize(options = {}) ⇒ GHRunit
constructor
Can be initialized with an Xcode ‘target` and a specified `Configuration`.
-
#log(message) ⇒ Object
A very thin wrapper around ‘log`, mainly added so we can test more easily.
-
#log_suite(name) ⇒ Object
## Log methods.
- #log_summary(summary) ⇒ Object
- #log_test(document, method) ⇒ Object
- #log_test_response(response, time) ⇒ Object
-
#parse_line(line) ⇒ Object
This parses the actual the output, we’re using some basic regex matching, so pretty brittle at the moment.
-
#run_build! ⇒ Object
Runs the actual build.
-
#start_suite! ⇒ Object
This function does all the work.
-
#xcode_command_line_command ⇒ Object
The ‘Xcode` command line build argument.
Constructor Details
#initialize(options = {}) ⇒ GHRunit
Can be initialized with an Xcode ‘target` and a specified `Configuration`.
GHRunit.new(:target => "Tests")
Will start off a test build and run it.
31 32 33 34 35 36 37 |
# File 'lib/ghrunit.rb', line 31 def initialize( = {}) = .merge() @target = [:target] @configuration = [:configuration] start_suite! end |
Instance Method Details
#buffer ⇒ Object
Will store all ‘stdout`-output
40 41 42 |
# File 'lib/ghrunit.rb', line 40 def buffer @buffer ||= StringIO.new end |
#default_options ⇒ Object
49 50 51 |
# File 'lib/ghrunit.rb', line 49 def {:target => "tests", :configuration => "Debug"} end |
#error ⇒ Object
Not being used for now.
45 46 47 |
# File 'lib/ghrunit.rb', line 45 def error @error ||= StringIO.new end |
#log(message) ⇒ Object
A very thin wrapper around ‘log`, mainly added so we can test more easily.
138 139 140 |
# File 'lib/ghrunit.rb', line 138 def log() puts end |
#log_suite(name) ⇒ Object
## Log methods
105 106 107 |
# File 'lib/ghrunit.rb', line 105 def log_suite(name) log "Starting for #{name}..." end |
#log_summary(summary) ⇒ Object
126 127 128 129 130 131 132 133 134 |
# File 'lib/ghrunit.rb', line 126 def log_summary(summary) log "\n" if /(\d) failures/.match(summary)[1] == "0" summary.gsub!(/(\d failures?)/, Turn::Colorize.green('\1')) else summary.gsub!(/(\d failures?)/, Turn::Colorize.red('\1')) end log summary end |
#log_test(document, method) ⇒ Object
109 110 111 112 113 114 115 116 |
# File 'lib/ghrunit.rb', line 109 def log_test(document, method) if document != @document log Turn::Colorize.bold("#{document}").tabto(2) end @document = document @test_method = method end |
#log_test_response(response, time) ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/ghrunit.rb', line 118 def log_test_response(response, time) colorized = Turn::Colorize.red(response) colorized = Turn::Colorize.green(response) if response == "OK" method = @test_method.tabto(4) if @test_method log "#{method} #{colorized} (#{time})" end |
#parse_line(line) ⇒ Object
This parses the actual the output, we’re using some basic regex matching, so pretty brittle at the moment.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/ghrunit.rb', line 84 def parse_line(line) case line when '' # Skip blank lines when /Test Suite '([a-zA-Z ]*)' started./ log_suite($1) when /^Starting ([a-zA-Z]*)\/([a-zA-Z]*)/ log_test($1, $2) when /^\s(OK|FAIL)\s\((.+)\)/ log_test_response($1, $2) when /Test Suite '([a-zA-Z ]*)' finished./ # Another hook, but for now skipping when /^(Executed(.?)+)$/ log_summary($1) else # do nothing end end |
#run_build! ⇒ Object
Runs the actual build
59 60 61 |
# File 'lib/ghrunit.rb', line 59 def run_build! log %x{#{xcode_command_line_command}} end |
#start_suite! ⇒ Object
This function does all the work.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/ghrunit.rb', line 64 def start_suite! # Redirect output to ourselves $stdout = buffer $stderr = error # PREPARING THE BUILD! run_build! # Giving back output $stdout = STDOUT buffer.rewind # Parsing and outputting until buffer.eof? parse_line(buffer.readline) end end |
#xcode_command_line_command ⇒ Object
The ‘Xcode` command line build argument.
54 55 56 |
# File 'lib/ghrunit.rb', line 54 def xcode_command_line_command "xcodebuild -target #{@target} -configuration #{@configuration} -sdk iphonesimulator build" end |