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.



11
12
13
14
15
16
17
18
19
20
# File 'lib/guard/calabash-ios/runner.rb', line 11

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.no_launch = init_no_launch(options)
  self.reset_between_scenarios = init_reset_between_scenarios(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

#no_launchObject

Returns the value of attribute no_launch.



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

def no_launch
  @no_launch
end

#projectObject

Returns the value of attribute project.



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

def project
  @project
end

#reset_between_scenariosObject

Returns the value of attribute reset_between_scenarios.



10
11
12
# File 'lib/guard/calabash-ios/runner.rb', line 10

def reset_between_scenarios
  @reset_between_scenarios
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



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/guard/calabash-ios/runner.rb', line 103

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 << "NO_LAUNCH=#{self.no_launch}" if self.no_launch
  cmd << "RESET_BETWEEN_SCENARIOS=#{self.reset_between_scenarios}" if self.reset_between_scenarios
  cmd << "cucumber #{features} --require features"      
  cmd.join ' '
end

#init_bundle_path(options) ⇒ Object



117
118
119
120
121
122
123
124
125
# File 'lib/guard/calabash-ios/runner.rb', line 117

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



54
55
56
57
58
59
60
# File 'lib/guard/calabash-ios/runner.rb', line 54

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

#init_device(options) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/guard/calabash-ios/runner.rb', line 31

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

#init_no_launch(options) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/guard/calabash-ios/runner.rb', line 62

def init_no_launch(options)
  case options[:no_launch]
  when true
    1
  when false
    0
  end
end

#init_project(options) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/guard/calabash-ios/runner.rb', line 40

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_reset_between_scenarios(options) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/guard/calabash-ios/runner.rb', line 71

def init_reset_between_scenarios(options)
  case options[:reset_between_scenarios]
  when true
    1
  when false
    0
  end
end

#init_sdk(options) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/guard/calabash-ios/runner.rb', line 22

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

#init_target(options) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/guard/calabash-ios/runner.rb', line 80

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

#run(features) ⇒ Object



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

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