Class: Guard::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/guard/calabash-ios/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Runner

Returns a new instance of Runner.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/guard/calabash-ios/runner.rb', line 6

def initialize(options)
  devices = [:iphone, :ipad]
  sdks = [:ios4, :ios5]
  if options[:project].nil?
    project = Dir.glob("*.xcodeproj").first
    if project
      options[:project] = project.gsub(".xcodeproj","")
    else
      UI.info "You must specify project name at your Guardfile."
    end
  end
  self.bundle_path = bundle(options)
  self.sdk =:ios5
  if sdks.include? options[:sdk]
    self.sdk = options[:sdk]
  end
  self.device = :iphone
  if devices.include? options[:device]
    self.device = options[:device]
  end
end

Instance Attribute Details

#bundle_pathObject

Returns the value of attribute bundle_path.



3
4
5
# File 'lib/guard/calabash-ios/runner.rb', line 3

def bundle_path
  @bundle_path
end

#deviceObject

Returns the value of attribute device.



5
6
7
# File 'lib/guard/calabash-ios/runner.rb', line 5

def device
  @device
end

#sdkObject

Returns the value of attribute sdk.



4
5
6
# File 'lib/guard/calabash-ios/runner.rb', line 4

def sdk
  @sdk
end

Instance Method Details

#bundle(options) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/guard/calabash-ios/runner.rb', line 50

def bundle(options)
  pwd = Dir::pwd
  project = options[:project]
  target = options[:target] || "frankified"
  config = options[:config] || "Debug"
  bundle_path = "#{pwd}/DerivedData/#{project}/Build/Products/#{config}-iphonesimulator/#{project}-cal.app"
end

#command(features) ⇒ Object



43
44
45
46
47
48
# File 'lib/guard/calabash-ios/runner.rb', line 43

def command(features)
  if features.kind_of? Array
    features = features.join(' ')
  end
  "APP_BUNDLE_PATH='#{self.bundle_path}' OS=#{self.sdk} DEVICE=#{self.device} cucumber #{features} --require features"
end

#run(features) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/guard/calabash-ios/runner.rb', line 28

def run(features)
  unless File.exists? self.bundle_path
    UI.info "Could not run Calabash. \n'#{self.bundle_path}' not found."
    return false
  end
  if features.eql?("features")
    start_message = "Run all features"
  else
    features = features.join(' ') if features.kind_of? Array
    start_message = "Run #{features}"
  end
  UI.info start_message
  system(command(features))
end