Class: Calasmash::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/calasmash.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Runner

Returns a new instance of Runner.



11
12
13
14
15
16
# File 'lib/calasmash.rb', line 11

def initialize(args)
  @options = parse(args)
  if @options[:valid] 
          start
      end
end

Instance Method Details

#app_pathObject



101
102
103
104
105
106
107
108
109
110
111
# File 'lib/calasmash.rb', line 101

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

#compileObject



68
69
70
71
72
73
# File 'lib/calasmash.rb', line 68

def compile
  puts "Compiling..."
  IO.popen("xcodebuild -workspace #{@options[:workspace]} -scheme #{@options[:scheme]} -sdk iphonesimulator CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO") {|output|
    puts output.read
  }
end

#parse(args) ⇒ Object



26
27
28
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
# File 'lib/calasmash.rb', line 26

def parse(args)
  options = {} 
  @opt_parser = OptionParser.new do |opt|
      opt.banner = "Usage: calasmash [OPTIONS]"
      opt.separator  ""
      opt.separator  "Options"
  
    opt.on("-t","--tags TAGS","the tags to test against") do |tags|
        options[:tags] = tags
    end

    opt.on("-w","--workspace WORKSPACE","the workspace to build") do |tags|
        options[:workspace] = tags
    end

    opt.on("-s","--scheme SCHEME","the scheme to build") do |tags|
        options[:scheme] = tags
    end

    opt.on("-h","--help","help") do
      puts @opt_parser
    end
  end

  @opt_parser.parse! args

  options[:valid] = true

  validate_options(options)
end

#plist_pathObject



113
114
115
116
117
# File 'lib/calasmash.rb', line 113

def plist_path
  
  plist_path = app_path + "/server_config.plist"
  return plist_path
end

#run_cucumberObject



94
95
96
97
98
99
# File 'lib/calasmash.rb', line 94

def run_cucumber
  puts "Running cucumber..."
  IO.popen("cucumber OS=ios7 SDK_VERSION=7.0 DEVICE_TARGET=simulator --tags #{@options[:tags]}") {|output|
    puts output.read
  }
end

#startObject



18
19
20
21
22
23
24
# File 'lib/calasmash.rb', line 18

def start
  puts "Starting..."
  compile
  update_plist
  sleep(2)
  run_cucumber
end

#update_plistObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/calasmash.rb', line 75

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



57
58
59
60
61
62
63
64
65
66
# File 'lib/calasmash.rb', line 57

def validate_options(options)
  if options[:workspace].nil?
    puts "Workspace path required, see --help for more information"
    options[:valid] = false
  elsif options[:scheme].nil?
    puts "Scheme required, see --help for more information"
    options[:valid] = false
  end
  options
end