Class: Guard::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/guard/frank/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Runner

Returns a new instance of Runner.



7
8
9
10
11
12
# File 'lib/guard/frank/runner.rb', line 7

def initialize(options)
  self.project = init_project(options)
  self.bundle_path = bundle(options)
  self.target = init_target(options)
  self.config = init_config(options)
end

Instance Attribute Details

#bundle_pathObject

Returns the value of attribute bundle_path.



3
4
5
# File 'lib/guard/frank/runner.rb', line 3

def bundle_path
  @bundle_path
end

#configObject

Returns the value of attribute config.



6
7
8
# File 'lib/guard/frank/runner.rb', line 6

def config
  @config
end

#projectObject

Returns the value of attribute project.



4
5
6
# File 'lib/guard/frank/runner.rb', line 4

def project
  @project
end

#targetObject

Returns the value of attribute target.



5
6
7
# File 'lib/guard/frank/runner.rb', line 5

def target
  @target
end

Instance Method Details

#bundle(options) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/guard/frank/runner.rb', line 65

def bundle(options)
  pwd = Dir::pwd
  if File.exists?"Frank"
    Dir.chdir("Frank")
  end
  project = self.project
  target = self.target
  config = self.config
  device = "iphonesimulator"
  bundle_path = "#{pwd}/DerivedData/#{project}/Build/Products/#{config}-#{device}/#{target}.app"
end

#command(features) ⇒ Object



58
59
60
61
62
63
# File 'lib/guard/frank/runner.rb', line 58

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

#init_config(options) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/guard/frank/runner.rb', line 27

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

#init_project(options) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/guard/frank/runner.rb', line 14

def init_project(options)
  if options[:project].nil?
    Dir.chdir("..")
    xproject = Dir.glob("*.xcodeproj").first
    if xproject
      xproject.gsub(".xcodeproj","")
    else
      UI.info "You must specify project name at your Guardfile."
      nil
    end
  end
end

#init_target(options) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/guard/frank/runner.rb', line 35

def init_target(options)
  if options[:target].nil?
    options[:target]
  else
    "frankified"
  end
end

#run(features) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/guard/frank/runner.rb', line 43

def run(features)
  unless File.exists? self.bundle_path.to_s
    UI.info "Could not run Frank. \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