iCuke 0.4.8 → 0.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.8
1
+ 0.4.9
data/iCuke.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{iCuke}
8
- s.version = "0.4.8"
8
+ s.version = "0.4.9"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Rob Holland"]
@@ -83,7 +83,6 @@ Gem::Specification.new do |s|
83
83
  "features/support/env.rb",
84
84
  "iCuke.gemspec",
85
85
  "lib/icuke.rb",
86
- "lib/icuke/core_ext.rb",
87
86
  "lib/icuke/cucumber.rb",
88
87
  "lib/icuke/simulate.rb",
89
88
  "lib/icuke/simulator.rb"
@@ -1,10 +1,84 @@
1
- require 'icuke/core_ext'
2
-
3
1
  require 'httparty'
4
2
  require 'appscript'
5
3
  require 'timeout'
6
4
 
7
5
  module ICuke
6
+ class XCode
7
+ def self.app
8
+ @app ||= Appscript.app('Xcode.app')
9
+ end
10
+
11
+ def self.open_project(project_file)
12
+ unless open_project?(project_file)
13
+ app.launch
14
+ app.open project_file
15
+ end
16
+ app.active_project_document.project
17
+ end
18
+
19
+ def self.open_project?(project_file)
20
+ running? and
21
+ app.active_project_document.get and
22
+ app.active_project_document.project.path.get == project_file
23
+ end
24
+
25
+ def self.interface
26
+ Appscript.app('System Events').application_processes['Xcode']
27
+ end
28
+
29
+ def self.running?
30
+ app.is_running?
31
+ end
32
+
33
+ def self.quit
34
+ IPhoneSimulator.quit
35
+ app.quit if running?
36
+ sleep(0.2) until !running?
37
+ end
38
+
39
+ def self.status
40
+ interface.windows[1].static_texts[0].value.get
41
+ end
42
+
43
+ def self.launched_app?
44
+ status =~ /launched$/
45
+ end
46
+
47
+ def self.installing_app?
48
+ status =~ /^Installing/
49
+ end
50
+
51
+ def self.with_settings(project, settings, &block)
52
+ initial_settings = {}
53
+
54
+ settings.each_key { |setting| initial_settings[setting] = project.send(setting).get }
55
+ settings.each_pair do |setting, value|
56
+ project.send(setting).set value
57
+ end
58
+
59
+ yield
60
+ ensure
61
+ initial_settings.each_pair do |setting, value|
62
+ project.send(setting).set value
63
+ end if running?
64
+ end
65
+ end
66
+
67
+ class IPhoneSimulator
68
+ def self.app
69
+ @app ||= Appscript.app('iPhone Simulator.app')
70
+ end
71
+
72
+ def self.quit
73
+ app.quit if running?
74
+ sleep(0.2) until !running?
75
+ end
76
+
77
+ def self.running?
78
+ app.is_running?
79
+ end
80
+ end
81
+
8
82
  class Simulator
9
83
  include Timeout
10
84
  include HTTParty
@@ -20,11 +94,10 @@ module ICuke
20
94
 
21
95
  # If we don't kill the simulator first the rest of this function becomes
22
96
  # a no-op and we don't land on the applications first page
23
- simulator = Appscript.app('iPhone Simulator.app')
24
- simulator.quit if simulator.is_running?
97
+ IPhoneSimulator.quit
25
98
 
26
99
  begin
27
- project = open_project(project_file)
100
+ project = XCode.open_project(project_file)
28
101
 
29
102
  settings = {
30
103
  :active_build_configuration_type => project.build_configuration_types[options[:configuration]]
@@ -33,7 +106,7 @@ module ICuke
33
106
  settings[:active_target] = project.targets[options[:target]]
34
107
  end
35
108
 
36
- with_settings(project, settings) do
109
+ XCode.with_settings(project, settings) do
37
110
  executable = project.active_executable.get
38
111
  options[:env].each_pair do |name, value|
39
112
  executable.make :new => :environment_variable,
@@ -42,53 +115,18 @@ module ICuke
42
115
 
43
116
  project.launch_
44
117
 
45
- timeout(30) do
46
- sleep(0.5) until simulator.is_running?
118
+ sleep(0.5) while XCode.installing_app?
119
+
120
+ unless XCode.launched_app?
121
+ XCode.quit
122
+ retry
47
123
  end
48
124
  end
49
- rescue Timeout::Error
50
- xcode = Appscript.app('Xcode.app')
51
- xcode.quit if xcode.is_running?
52
- sleep(0.5) until !xcode.is_running?
53
- retry
54
- end
55
-
56
- timeout(30) do
57
- begin
58
- view
59
- rescue Errno::ECONNREFUSED
60
- sleep(0.5)
61
- retry
62
- end
63
- end
64
- end
65
-
66
- def open_project(project_file)
67
- xcode = Appscript.app('Xcode.app')
68
- unless xcode.active_project_document.get and xcode.active_project_document.project.path.get == project_file
69
- xcode.launch
70
- xcode.open project_file
71
- end
72
- xcode.active_project_document.project
73
- end
74
-
75
- def with_settings(project, settings, &block)
76
- initial_settings = {}
77
-
78
- settings.each_key { |setting| initial_settings[setting] = project.send(setting).get }
79
- settings.each_pair do |setting, value|
80
- project.send(setting).set value
81
- end
82
-
83
- yield
84
- ensure
85
- initial_settings.each_pair do |setting, value|
86
- project.send(setting).set value
87
125
  end
88
126
  end
89
127
 
90
128
  def quit
91
- Appscript.app('iPhone Simulator.app').quit
129
+ IPhoneSimulator.quit
92
130
  end
93
131
 
94
132
  def view
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 8
9
- version: 0.4.8
8
+ - 9
9
+ version: 0.4.9
10
10
  platform: ruby
11
11
  authors:
12
12
  - Rob Holland
@@ -140,7 +140,6 @@ files:
140
140
  - features/support/env.rb
141
141
  - iCuke.gemspec
142
142
  - lib/icuke.rb
143
- - lib/icuke/core_ext.rb
144
143
  - lib/icuke/cucumber.rb
145
144
  - lib/icuke/simulate.rb
146
145
  - lib/icuke/simulator.rb
@@ -1,26 +0,0 @@
1
- require 'net/http'
2
-
3
- module RequestWithSocketCheck
4
- def self.included(base)
5
- base.instance_eval do
6
- alias_method :request_without_socket_check, :request
7
- alias_method :request, :request_with_socket_check
8
- end
9
- end
10
-
11
- def request_with_socket_check(*args)
12
- begin
13
- request_without_socket_check(*args)
14
- rescue NoMethodError => e
15
- if e.message =~ /undefined method `closed\?' for nil/
16
- raise Errno::ECONNREFUSED
17
- else
18
- raise e
19
- end
20
- end
21
- end
22
- end
23
-
24
- if Net::HTTP::Revision.to_i == 25851
25
- Net::HTTP.send :include, RequestWithSocketCheck
26
- end