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.



9
10
11
12
13
14
15
16
# File 'lib/guard/calabash-ios/runner.rb', line 9

def initialize(options)
  self.sdk = init_sdk(options)
  self.device = init_device(options)
  self.project = init_project(options)
  self.target = init_target(options)
  self.config = init_config(options)
  self.bundle_path = init_bundle_path(options)
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

#configObject

Returns the value of attribute config.



8
9
10
# File 'lib/guard/calabash-ios/runner.rb', line 8

def config
  @config
end

#deviceObject

Returns the value of attribute device.



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

def device
  @device
end

#projectObject

Returns the value of attribute project.



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

def project
  @project
end

#sdkObject

Returns the value of attribute sdk.



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

def sdk
  @sdk
end

#targetObject

Returns the value of attribute target.



7
8
9
# File 'lib/guard/calabash-ios/runner.rb', line 7

def target
  @target
end

Instance Method Details

#command(features) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/guard/calabash-ios/runner.rb', line 81

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

#init_bundle_path(options) ⇒ Object



93
94
95
96
97
98
99
100
101
# File 'lib/guard/calabash-ios/runner.rb', line 93

def init_bundle_path(options)
  path = []
  path << "#{Dir::pwd}/DerivedData/"
  path << "#{self.project}/"
  path << "Build/Products/"
  path << "#{self.config}-iphonesimulator/"
  path << "#{self.target}.app"
  path.join
end

#init_config(options) ⇒ Object



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

def init_config(options)
  if options[:config].nil?
    "Debug"
  else
    options[:config]
  end
end

#init_device(options) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/guard/calabash-ios/runner.rb', line 27

def init_device(options)
  devices = [:iphone, :ipad]
  if devices.include? options[:device]
    options[:device]
  else
    :iphone
  end
end

#init_project(options) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/guard/calabash-ios/runner.rb', line 36

def init_project(options)
  if options[:project].nil?
    xproject = Dir.glob("*.xcodeproj").first
    if xproject
      xproject.gsub(".xcodeproj","")
    else
      UI.info "Could not find project"
      nil
    end
  else
    options[:project]
  end
end

#init_sdk(options) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/guard/calabash-ios/runner.rb', line 18

def init_sdk(options)
  sdks = [:ios4, :ios5]
  if sdks.include? options[:sdk]
    options[:sdk]
  else
    :ios5
  end
end

#init_target(options) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/guard/calabash-ios/runner.rb', line 58

def init_target(options)
  if options[:target].nil?
    "#{self.project}-cal"
  else
    options[:target]
  end
end

#run(features) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/guard/calabash-ios/runner.rb', line 66

def run(features)
  unless File.exists? self.bundle_path.to_s
    UI.info "Could not run Calabash. \n'#{self.bundle_path}' not found."
    return false
  end
  if features.eql?("features") or features.empty?
    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