Class: Calasmash::Runner
- Inherits:
-
Object
- Object
- Calasmash::Runner
- Defined in:
- lib/calasmash.rb
Instance Method Summary collapse
- #app_path ⇒ Object
- #compile ⇒ Object
-
#initialize(args) ⇒ Runner
constructor
A new instance of Runner.
- #parse(args) ⇒ Object
- #plist_path ⇒ Object
- #run_cucumber ⇒ Object
- #start ⇒ Object
- #update_plist ⇒ Object
- #validate_options(options) ⇒ Object
Constructor Details
#initialize(args) ⇒ Runner
Returns a new instance of Runner.
12 13 14 15 16 17 18 19 |
# File 'lib/calasmash.rb', line 12 def initialize(args) = parse(args) if [:valid] start else puts "Invalid options!" end end |
Instance Method Details
#app_path ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/calasmash.rb', line 162 def app_path files = [] Find.find("#{File.expand_path('~')}/Library/Developer/Xcode/DerivedData/") do |path| files << path if path =~ /#{@options[:scheme]}.app$/ end app_path = files.sort_by { |filename| File.mtime(filename)}.last # get the latest return app_path end |
#compile ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/calasmash.rb', line 80 def compile puts "Compiling..." status = nil xcode_command = "xcodebuild -workspace #{@options[:workspace]} -scheme #{@options[:scheme]} -sdk iphonesimulator CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO" Open3.popen3 xcode_command do |stdin, out, err, wait_thr| [out, err].each do |stream| Thread.new do until (line = stream.gets).nil? do puts line end end end wait_thr.join status = wait_thr.value.exitstatus end if status != 0 puts "Compilation failed: #{status}" exit status end end |
#parse(args) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/calasmash.rb', line 29 def parse(args) = {} @opt_parser = OptionParser.new do |opt| opt. = "Usage: calasmash [OPTIONS]" opt.separator "" opt.separator "Options" opt.on("-t","--tags TAGS","the tags to test against") do || [:tags] = end opt.on("-w","--workspace WORKSPACE","the workspace to build") do || [:workspace] = end opt.on("-s","--scheme SCHEME","the scheme to build") do || [:scheme] = end opt.on("-h","--help","help") do puts @opt_parser end opt.on('-f', "--format FORMAT", "test report format e.g. junit") do || [:format] = end opt.on('-o', "--out OUTPUT", "test report output path e.g. test") do || [:out] = end end @opt_parser.parse! args [:valid] = true () return end |
#plist_path ⇒ Object
174 175 176 177 178 |
# File 'lib/calasmash.rb', line 174 def plist_path plist_path = app_path + "/server_config.plist" return plist_path end |
#run_cucumber ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/calasmash.rb', line 124 def run_cucumber puts "Running cucumber..." optional_params = "" if([:out] && [:format]) optional_params = " --format #{@options[:format]} --out #{@options[:out]} " end if([:tags]) optional_params += " --tags #{@options[:tags]}" end cucumber_command = "cucumber OS=ios7 SDK_VERSION=7.0 DEVICE_TARGET=simulator" cucumber_command += optional_params status = nil Open3.popen3 cucumber_command do |stdin, out, err, wait_thr| [out, err].each do |stream| Thread.new do until (line = stream.gets).nil? do puts line end end end wait_thr.join status = wait_thr.value.exitstatus end if status != 0 puts "Cucumber failed: #{status}" end # exit with whatever status Cucumber has exited exit status end |
#start ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/calasmash.rb', line 21 def start puts "Starting..." compile update_plist sleep(2) run_cucumber end |
#update_plist ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/calasmash.rb', line 105 def update_plist puts "Updating plist..." ip = Socket.ip_address_list.find {|a| a.ipv4? && !a.ipv4_loopback?}.ip_address port = 4567 #sinatras default port plist_file = CFPropertyList::List.new(:file => plist_path) plist = CFPropertyList.native_types(plist_file.value) plist["url_preference"] = ip plist["port_preference"] = port puts("plist: #{plist}") plist_file.value = CFPropertyList.guess(plist) plist_file.save(plist_path, CFPropertyList::List::FORMAT_XML) end |
#validate_options(options) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/calasmash.rb', line 69 def () if [:workspace].nil? puts "Workspace path required, see --help for more information" [:valid] = false elsif [:scheme].nil? puts "Scheme required, see --help for more information" [:valid] = false end end |