motion-calabash 0.9.127 → 0.9.136

Sign up to get free protection for your applications and to get access to all the features.
@@ -34,13 +34,13 @@ namespace 'calabash' do
34
34
 
35
35
  # Retrieve optional Calabash args.
36
36
  def gather_calabash_env
37
- sdk = ENV['sdk'] || ENV['SDK_VERSION'] || "6.0" #Calabash env vars
37
+ sdk = ENV['target'] || ENV['sdk'] || ENV['SDK_VERSION'] || "6.1" #Calabash env vars
38
38
  major = sdk[0]
39
39
  os = ENV['os'] || ENV['OS']
40
40
  if os.nil?
41
41
  os = "ios#{major}"
42
42
  end
43
- device = ENV['device'] || ENV['DEVICE'] || 'iphone' #Calabash env vars
43
+ device = ENV['device_family'] || ENV['device'] || ENV['DEVICE'] || 'iphone' #Calabash env vars
44
44
  {"SDK_VERSION" => sdk, "OS" => os, "DEVICE" => device}
45
45
  end
46
46
 
@@ -49,33 +49,46 @@ namespace 'calabash' do
49
49
  # Retrieve optional args to pass to cucumber.
50
50
  args = ENV["args"] || ""
51
51
 
52
+ ENV['DEVICE_ENDPOINT'] ||= 'http://localhost:37265/'
53
+
54
+ target = ARGV[1] || 'simulator'
55
+
56
+
57
+ project_config_vars = Motion::Project::App.config.variables
58
+
59
+ bundle_id = project_config_vars["identifier"]
60
+
52
61
  calabash_env = gather_calabash_env
53
62
 
54
- # Retrieve optional bundle path.
55
- bundle_path = ENV['APP_BUNDLE_PATH']
56
- unless bundle_path
57
- build = "build"
58
- unless File.exist?(build)
59
- App.fail "No dir found: #{build}. Please build app first."
60
- end
61
- sim_dir = Dir.glob("#{build}/*").find {|d| /Simulator-/.match(d)}
62
- unless sim_dir and File.directory?(sim_dir)
63
- App.fail "No Simulator dir found in #{build}. Please build app for simulator first."
64
- end
65
- app = Dir.glob("#{sim_dir}/*").find {|d| /\.app$/.match(d)}
66
- unless app and File.exist?(app)
67
- App.fail "No .app found in #{sim_dir}. Please build app for simulator first."
63
+ calabash_env['DEVICE_TARGET'] = target
64
+ calabash_env['BUNDLE_ID'] = bundle_id
65
+
66
+ unless target == 'device'
67
+ # Retrieve optional bundle path.
68
+ bundle_path = ENV['APP_BUNDLE_PATH']
69
+ unless bundle_path
70
+ build = "build"
71
+ unless File.exist?(build)
72
+ App.fail "No dir found: #{build}. Please build app first."
73
+ end
74
+ sim_dir = Dir.glob("#{build}/*").find {|d| /Simulator-/.match(d)}
75
+ unless sim_dir and File.directory?(sim_dir)
76
+ App.fail "No Simulator dir found in #{build}. Please build app for simulator first."
77
+ end
78
+ app = Dir.glob("#{sim_dir}/*").find {|d| /\.app$/.match(d)}
79
+ unless app and File.exist?(app)
80
+ App.fail "No .app found in #{sim_dir}. Please build app for simulator first."
81
+ end
82
+ bundle_path = File.expand_path("#{app}")
68
83
  end
69
- bundle_path = File.expand_path("#{app}")
84
+ App.fail "No app found in #{bundle_path} (APP_BUNDLE_PATH)" unless File.exist?(bundle_path)
85
+ calabash_env["APP_BUNDLE_PATH"] = bundle_path
70
86
  end
71
87
 
72
- App.fail "No app found in #{bundle_path} (APP_BUNDLE_PATH)" unless File.exist?(bundle_path)
73
-
74
- calabash_env["APP_BUNDLE_PATH"] = "\"#{bundle_path}\""
75
88
 
76
89
  App.info 'Run', "#{calabash_env} cucumber #{args}"
77
- env_str = calabash_env.map {|envname, envval| "#{envname}=#{envval}"}.join(" ")
78
- system("#{env_str} cucumber #{args}")
90
+
91
+ exec(calabash_env,"cucumber", *(args.split(' ')))
79
92
  end
80
93
 
81
94
  desc "Start Calabash console."
@@ -88,5 +101,26 @@ namespace 'calabash' do
88
101
  exec(calabash_env,"calabash-ios","console")
89
102
  end
90
103
 
104
+ desc "Scaffold Calabash features folder."
105
+ task :scaffold do
106
+ # Retrieve configuration settings.
107
+ calabash_env = gather_calabash_env
108
+ cmd = '(echo "" | calabash-ios gen) &> /dev/null'
109
+ App.info 'Run', "Scaffolding features"
110
+ App.info 'Info', "Run rake calabash:run to try"
111
+
112
+ env_str = calabash_env.map {|envname, envval| "export #{envname}=#{envval};"}.join(" ")
113
+ system("(#{env_str}) && #{cmd}")
114
+
115
+
116
+ this_path = File.expand_path(__FILE__)
117
+ launch_path = File.join(this_path,'..','..','..','..','scripts','launch.rb')
118
+ launch_path = File.expand_path(launch_path)
119
+ puts "Copy launch file #{launch_path} to features/support/launch.rb"
120
+ FileUtils.cp(launch_path,File.join('features','support','launch.rb'))
121
+
122
+
123
+ end
124
+
91
125
  end
92
126
 
@@ -7,12 +7,12 @@ Gem::Specification.new do |s|
7
7
  s.author = 'Karl Krukow'
8
8
  s.email = 'karl@lesspainful.com'
9
9
  s.homepage = 'http://www.lesspainful.com'
10
- s.version = '0.9.127'
10
+ s.version = '0.9.136'
11
11
  s.summary = %q{Calabash support for RubyMotion}
12
- s.description = %q{This link-in calabash for iOS}
13
- s.files = ["lib/framework/libcalabashuni-0.9.126.a"].concat(`git ls-files`.split("\n"))
12
+ s.description = %q{This linkes-in calabash for iOS}
13
+ s.files = ["lib/framework/libcalabashuni-0.9.136.a"].concat(`git ls-files`.split("\n"))
14
14
  s.require_paths = ["lib"]
15
15
 
16
- s.add_dependency("calabash-cucumber", "0.9.126")
16
+ s.add_dependency("calabash-cucumber", "0.9.136")
17
17
 
18
18
  end
data/scripts/launch.rb ADDED
@@ -0,0 +1,171 @@
1
+ ########################################
2
+ # #
3
+ # Important Note #
4
+ # #
5
+ # When running calabash-ios tests at #
6
+ # www.lesspainful.com #
7
+ # this file will be overwritten by #
8
+ # a file which automates #
9
+ # app launch on devices. #
10
+ # #
11
+ # Don't rely on this file being #
12
+ # present when running at #
13
+ # www.lesspainful.com. #
14
+ # #
15
+ # Only put stuff here to automate #
16
+ # iOS Simulator. #
17
+ # #
18
+ # You can put your app bundle path #
19
+ # for automating simulator app start: #
20
+ # Uncomment APP_BUNDLE_PATH =.. #
21
+ # #
22
+ ########################################
23
+
24
+ require 'calabash-cucumber/launch/simulator_helper'
25
+ require 'sim_launcher'
26
+ require 'run_loop'
27
+
28
+ # Uncomment and replace ?? appropriately
29
+ # This should point to your Simulator build
30
+ # which includes calabash framework
31
+ # this is usually the Calabash build configuration
32
+ # of your production target.
33
+ #APP_BUNDLE_PATH = "~/Library/Developer/Xcode/DerivedData/??/Build/Products/Calabash-iphonesimulator/??.app"
34
+ #
35
+
36
+
37
+ def calabash_no_stop?
38
+ ENV['NO_LAUNCH']=="1" or ENV['NO_STOP']=="1"
39
+ end
40
+
41
+ def device_target?
42
+ ENV['DEVICE_TARGET'] == 'device'
43
+ end
44
+
45
+
46
+ class MotionLauncherTimeoutErr < Timeout::Error
47
+ end
48
+
49
+ class MotionLauncher
50
+ attr_accessor :run_loop
51
+
52
+ def reset_app_jail(sdk, app_path)
53
+ return if device_target?
54
+
55
+ app = File.basename(app_path)
56
+ bundle = `find "#{ENV['HOME']}/Library/Application Support/iPhone Simulator/#{sdk}/Applications/" -type d -depth 2 -name "#{app}" | head -n 1`
57
+ return if bundle.empty? # Assuming we're already clean
58
+
59
+ sandbox = File.dirname(bundle)
60
+ ['Library', 'Documents', 'tmp'].each do |dir|
61
+ FileUtils.rm_rf(File.join(sandbox, dir))
62
+ end
63
+ end
64
+
65
+ def relaunch(args=nil)
66
+ if run_loop
67
+ RunLoop.stop(run_loop)
68
+ end
69
+ if device_target?
70
+ self.run_loop = RunLoop.run(:app => ENV['BUNDLE_ID'])
71
+ ensure_connectivity
72
+ else
73
+ sdk = ENV['SDK_VERSION'] || SimLauncher::SdkDetector.new().latest_sdk_version
74
+ path = Calabash::Cucumber::SimulatorHelper.app_bundle_or_raise(app_path)
75
+ if ENV['RESET_BETWEEN_SCENARIOS']=="1"
76
+ reset_app_jail(sdk, path)
77
+ end
78
+ Calabash::Cucumber::SimulatorHelper.relaunch(path, sdk, ENV['DEVICE'] || 'iphone', args)
79
+ end
80
+
81
+ end
82
+
83
+ def ensure_connectivity
84
+ begin
85
+ max_retry_count = (ENV['MAX_CONNECT_RETRY'] || 10).to_i
86
+ timeout = (ENV['CONNECT_TIMEOUT'] || 30).to_i
87
+ retry_count = 0
88
+ connected = false
89
+ puts "Waiting for App to be ready"
90
+ until connected do
91
+ raise "MAX_RETRIES" if retry_count == max_retry_count
92
+ retry_count += 1
93
+ begin
94
+ Timeout::timeout(timeout, MotionLauncherTimeoutErr) do
95
+ until connected
96
+ begin
97
+ connected = (ping_app == '200')
98
+ break if connected
99
+ rescue Exception => e
100
+ #p e
101
+ #retry
102
+ ensure
103
+ sleep 1 unless connected
104
+ end
105
+ end
106
+ end
107
+ rescue MotionLauncherTimeoutErr => e
108
+ puts "Timed out...Retry.."
109
+ end
110
+ end
111
+ rescue e
112
+ p e
113
+ msg = "Unable to make connection to Calabash Server at #{ENV['DEVICE_ENDPOINT']|| "http://localhost:37265/"}\n"
114
+ msg << "Make sure you don't have a firewall blocking traffic to #{ENV['DEVICE_ENDPOINT']|| "http://localhost:37265/"}.\n"
115
+ raise msg
116
+ end
117
+ end
118
+
119
+ def ping_app
120
+ url = URI.parse(ENV['DEVICE_ENDPOINT']|| "http://localhost:37265/")
121
+
122
+ http = Net::HTTP.new(url.host, url.port)
123
+ res = http.start do |sess|
124
+ sess.request Net::HTTP::Get.new "version"
125
+ end
126
+ status = res.code
127
+ begin
128
+ http.finish if http and http.started?
129
+ rescue Exception => e
130
+
131
+ end
132
+
133
+ status
134
+ end
135
+
136
+ def stop
137
+ RunLoop.stop(run_loop)
138
+ end
139
+
140
+ def app_path
141
+ ENV['APP_BUNDLE_PATH'] || (defined?(APP_BUNDLE_PATH) && APP_BUNDLE_PATH)
142
+ end
143
+
144
+ def calabash_notify(world)
145
+ if world.respond_to?(:on_launch)
146
+ world.on_launch
147
+ end
148
+ end
149
+
150
+
151
+ end
152
+
153
+ AfterConfiguration do
154
+ system("rake device") if device_target?
155
+ end
156
+
157
+ Before do |scenario|
158
+ @launcher = MotionLauncher.new
159
+ @launcher.relaunch
160
+ @launcher.calabash_notify(self)
161
+ end
162
+
163
+ After do |scenario|
164
+ unless calabash_no_stop?
165
+ if device_target?
166
+ @launcher.stop
167
+ else
168
+ Calabash::Cucumber::SimulatorHelper.stop
169
+ end
170
+ end
171
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-calabash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.127
4
+ version: 0.9.136
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-15 00:00:00.000000000 Z
12
+ date: 2013-03-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: calabash-cucumber
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.9.126
21
+ version: 0.9.136
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,14 +26,14 @@ dependencies:
26
26
  requirements:
27
27
  - - '='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.9.126
30
- description: This link-in calabash for iOS
29
+ version: 0.9.136
30
+ description: This linkes-in calabash for iOS
31
31
  email: karl@lesspainful.com
32
32
  executables: []
33
33
  extensions: []
34
34
  extra_rdoc_files: []
35
35
  files:
36
- - lib/framework/libcalabashuni-0.9.126.a
36
+ - lib/framework/libcalabashuni-0.9.136.a
37
37
  - .gitignore
38
38
  - LICENSE
39
39
  - README.rdoc
@@ -41,6 +41,7 @@ files:
41
41
  - lib/motion-calabash.rb
42
42
  - lib/motion/project/calabash.rb
43
43
  - motion-calabash.gemspec
44
+ - scripts/launch.rb
44
45
  homepage: http://www.lesspainful.com
45
46
  licenses: []
46
47
  post_install_message:
@@ -66,3 +67,4 @@ signing_key:
66
67
  specification_version: 3
67
68
  summary: Calabash support for RubyMotion
68
69
  test_files: []
70
+ has_rdoc:
Binary file