uispecrunner 0.2.4 → 0.3.0
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/README.md +1 -1
- data/VERSION +1 -1
- data/lib/uispecrunner/drivers/osascript.rb +98 -0
- data/lib/uispecrunner/drivers/shell.rb +83 -0
- data/lib/uispecrunner/options.rb +7 -0
- data/lib/uispecrunner.rb +17 -75
- data/uispecrunner.gemspec +4 -2
- metadata +6 -4
data/README.md
CHANGED
@@ -31,11 +31,11 @@ to the spec runner. Example:
|
|
31
31
|
- Will read common arguments from uispec.opts file for easy per project configuration
|
32
32
|
- Includes a sample Rakefile for running your UISpec's
|
33
33
|
- Support for setting arbitrary environment variables on the runner
|
34
|
+
- Supports running specs via shell (xcodebuild) or AppleScript (osascript)
|
34
35
|
|
35
36
|
## TODO
|
36
37
|
- Auto-detect SDK versions available
|
37
38
|
- Support for running specific files
|
38
|
-
- Support for running non-headless (either via AppleScript or iphonesim)
|
39
39
|
- Generate a Kicker script
|
40
40
|
- Enabling Zombies (or other debugging flags, see http://code.google.com/p/google-toolbox-for-mac/source/browse/trunk/UnitTesting/RunIPhoneUnitTest.sh)
|
41
41
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
@@ -0,0 +1,98 @@
|
|
1
|
+
class UISpecRunner
|
2
|
+
class Drivers
|
3
|
+
class OSAScript
|
4
|
+
attr_reader :config
|
5
|
+
|
6
|
+
def initialize(config)
|
7
|
+
@config = config
|
8
|
+
end
|
9
|
+
|
10
|
+
def run_specs(env)
|
11
|
+
# Set the environment variables requested by the runner...
|
12
|
+
env_definitions = env.map do |key, value|
|
13
|
+
"my setEnvironmentVariable(\"#{key}\", \"#{value}\")"
|
14
|
+
end.join("\n")
|
15
|
+
|
16
|
+
script = <<-SCRIPT
|
17
|
+
on deactivateEnvironmentVariable(variableName)
|
18
|
+
|
19
|
+
tell application "Xcode"
|
20
|
+
tell active project document
|
21
|
+
set executableName to name of executable of active target as string
|
22
|
+
tell executable executableName
|
23
|
+
|
24
|
+
-- Check to see if the fallback path already exists
|
25
|
+
set hasVariable to false as boolean
|
26
|
+
|
27
|
+
repeat with environmentVariable in environment variables
|
28
|
+
if name of environmentVariable is equal to variableName then
|
29
|
+
set active of environmentVariable to no
|
30
|
+
end if
|
31
|
+
end repeat
|
32
|
+
|
33
|
+
end tell -- executable
|
34
|
+
end tell -- active project document
|
35
|
+
end tell -- Xcode
|
36
|
+
|
37
|
+
end deactivateEnvironmentVariable
|
38
|
+
|
39
|
+
on setEnvironmentVariable(variableName, variableValue)
|
40
|
+
|
41
|
+
tell application "Xcode"
|
42
|
+
tell active project document
|
43
|
+
set executableName to name of executable of active target as string
|
44
|
+
tell executable executableName
|
45
|
+
|
46
|
+
-- Check to see if the fallback path already exists
|
47
|
+
set hasVariable to false as boolean
|
48
|
+
|
49
|
+
repeat with environmentVariable in environment variables
|
50
|
+
if name of environmentVariable is equal to variableName then
|
51
|
+
-- Overwrite any value
|
52
|
+
set value of environmentVariable to variableValue
|
53
|
+
set active of environmentVariable to yes
|
54
|
+
set hasVariable to true as boolean
|
55
|
+
exit repeat
|
56
|
+
end if
|
57
|
+
end repeat
|
58
|
+
|
59
|
+
-- Since the fallback path doesn't exist yet, create it
|
60
|
+
if not hasVariable then
|
61
|
+
make new environment variable with properties {name:variableName, value:variableValue, active:yes}
|
62
|
+
end if
|
63
|
+
end tell -- executable
|
64
|
+
end tell -- active project document
|
65
|
+
end tell -- Xcode
|
66
|
+
|
67
|
+
end setEnvironmentVariable
|
68
|
+
|
69
|
+
application "iPhone Simulator" quit
|
70
|
+
-- application "iPhone Simulator" activate
|
71
|
+
|
72
|
+
tell application "Xcode"
|
73
|
+
set targetProject to project of active project document
|
74
|
+
#{env_definitions}
|
75
|
+
|
76
|
+
tell targetProject
|
77
|
+
set active build configuration type to build configuration type "Debug"
|
78
|
+
set active SDK to "iphonesimulator4.0"
|
79
|
+
set the active target to the target named "UISpec"
|
80
|
+
-- set value of build setting "SDKROOT" of build configuration "Debug" of active target to "iphoneos4.0"
|
81
|
+
|
82
|
+
build targetProject
|
83
|
+
launch targetProject
|
84
|
+
|
85
|
+
-- Clear out the environment variables
|
86
|
+
my deactivateEnvironmentVariable("UISPEC_PROTOCOL")
|
87
|
+
my deactivateEnvironmentVariable("UISPEC_SPEC")
|
88
|
+
my deactivateEnvironmentVariable("UISPEC_EXAMPLE")
|
89
|
+
end tell
|
90
|
+
end tell
|
91
|
+
SCRIPT
|
92
|
+
# puts "#{script}"
|
93
|
+
# exit
|
94
|
+
`osascript <<SCRIPT\n#{script}\nSCRIPT`
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'tmpdir'
|
2
|
+
|
3
|
+
class UISpecRunner
|
4
|
+
class Drivers
|
5
|
+
class Shell
|
6
|
+
attr_reader :config
|
7
|
+
|
8
|
+
def initialize(config)
|
9
|
+
@config = config
|
10
|
+
end
|
11
|
+
|
12
|
+
def run_specs(env)
|
13
|
+
if build_project!
|
14
|
+
run_env = self.env.merge(env)
|
15
|
+
run_env.merge!('DYLD_ROOT_PATH' => sdk_dir, 'IPHONE_SIMULATOR_ROOT' => sdk_dir, 'CFFIXED_USER_HOME' => Dir.tmpdir)
|
16
|
+
puts "Setting environment variables: #{run_env.inspect}" if uispec_runner.verbose?
|
17
|
+
with_env(run_env) do
|
18
|
+
start_securityd if config.securityd
|
19
|
+
command = "#{build_dir}/#{configuration}-iphonesimulator/#{target}.app/#{target} -RegisterForSystemEvents"
|
20
|
+
puts "Executing: #{command}" if config.verbose?
|
21
|
+
output = `#{command}`
|
22
|
+
exit_code = $?
|
23
|
+
unless exit_code == 0
|
24
|
+
puts "[!] Failed to run UISpec target: #{output}"
|
25
|
+
exit 1
|
26
|
+
end
|
27
|
+
end
|
28
|
+
else
|
29
|
+
puts "[!] Failed to build UISpecs.app"
|
30
|
+
exit 1
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def with_env(env)
|
35
|
+
before = env.inject({}) { |h, (k, _)| h[k] = ENV[k]; h }
|
36
|
+
env.each { |k, v| ENV[k] = v }
|
37
|
+
yield
|
38
|
+
ensure
|
39
|
+
before.each { |k, v| ENV[k] = v }
|
40
|
+
end
|
41
|
+
|
42
|
+
def project_switch
|
43
|
+
"-project #{config.project}" if config.project
|
44
|
+
end
|
45
|
+
|
46
|
+
def sdk_switch
|
47
|
+
"-sdk #{sdk_dir}" if config.sdk_version
|
48
|
+
end
|
49
|
+
|
50
|
+
def sdk_dir
|
51
|
+
"/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator#{config.sdk_version}.sdk"
|
52
|
+
end
|
53
|
+
|
54
|
+
def build_project!
|
55
|
+
command = "xcodebuild #{project_switch} -target #{config.target} -configuration #{config.configuration} #{sdk_switch} > /dev/null"
|
56
|
+
puts "Building project with: #{command}" if config.verbose?
|
57
|
+
system(command)
|
58
|
+
end
|
59
|
+
|
60
|
+
def run_command(command)
|
61
|
+
puts "Executing: #{command}" if config.verbose?
|
62
|
+
system(command)
|
63
|
+
end
|
64
|
+
|
65
|
+
def path_to_securityd
|
66
|
+
"#{sdk_dir}/usr/libexec/securityd"
|
67
|
+
end
|
68
|
+
|
69
|
+
def start_securityd
|
70
|
+
run_command("launchctl submit -l UISpecRunnerDaemons -- #{path_to_securityd}")
|
71
|
+
@securityd_running = true
|
72
|
+
Signal.trap("INT") { stop_securityd }
|
73
|
+
Signal.trap("TERM") { stop_securityd }
|
74
|
+
Signal.trap("EXIT") { stop_securityd }
|
75
|
+
end
|
76
|
+
|
77
|
+
def stop_securityd
|
78
|
+
run_command("launchctl remove UISpecRunnerDaemons") if @securityd_running
|
79
|
+
@securityd_running = false
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/lib/uispecrunner/options.rb
CHANGED
@@ -19,6 +19,7 @@ class UISpecRunner
|
|
19
19
|
self[:build_dir] = './build'
|
20
20
|
self[:verbose] = false
|
21
21
|
self[:sdk_version] = '3.0'
|
22
|
+
self[:driver] = :shell
|
22
23
|
|
23
24
|
require 'optparse'
|
24
25
|
@opts = OptionParser.new do |o|
|
@@ -52,6 +53,12 @@ class UISpecRunner
|
|
52
53
|
self[:project] = project
|
53
54
|
end
|
54
55
|
|
56
|
+
o.on('--driver [DRIVER]', [:shell, :osascript],
|
57
|
+
"Select driver (shell, osascript)",
|
58
|
+
'Default: shell') do |driver|
|
59
|
+
self[:driver] = driver.to_sym
|
60
|
+
end
|
61
|
+
|
55
62
|
o.on('--sdk [VERSION]',
|
56
63
|
'Run the UISpec target against the iPhone SDK version',
|
57
64
|
'Default: 3.0') do |sdk_version|
|
data/lib/uispecrunner.rb
CHANGED
@@ -2,10 +2,11 @@
|
|
2
2
|
# By: Blake Watters <blake@twotoasters.com>
|
3
3
|
# Portions borrowed from Eloy Duran's Kicker script (http://github.com/alloy/UISpec)
|
4
4
|
|
5
|
-
require '
|
5
|
+
require 'uispecrunner/drivers/shell'
|
6
|
+
require 'uispecrunner/drivers/osascript'
|
6
7
|
|
7
|
-
class UISpecRunner
|
8
|
-
attr_accessor :project, :target, :configuration, :sdk_version, :build_dir, :verbose, :securityd, :env
|
8
|
+
class UISpecRunner
|
9
|
+
attr_accessor :project, :target, :configuration, :sdk_version, :build_dir, :verbose, :securityd, :driver, :env
|
9
10
|
|
10
11
|
# private
|
11
12
|
attr_accessor :run_mode, :spec, :example, :protocol
|
@@ -16,11 +17,12 @@ class UISpecRunner
|
|
16
17
|
self.configuration ||= 'Debug'
|
17
18
|
self.build_dir ||= './build'
|
18
19
|
self.run_mode ||= :all
|
20
|
+
self.driver ||= :shell
|
19
21
|
self.env ||= {}
|
20
22
|
end
|
21
23
|
|
22
24
|
def run!
|
23
|
-
case run_mode
|
25
|
+
case self.run_mode
|
24
26
|
when :all
|
25
27
|
run_all!
|
26
28
|
when :spec
|
@@ -30,7 +32,7 @@ class UISpecRunner
|
|
30
32
|
when :protocol
|
31
33
|
run_protocol!(self.protocol)
|
32
34
|
else
|
33
|
-
raise ArgumentError, "Unknown run mode: #{run_mode}"
|
35
|
+
raise ArgumentError, "Unknown run mode: #{config.run_mode}"
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
@@ -48,84 +50,24 @@ class UISpecRunner
|
|
48
50
|
|
49
51
|
def run_spec_example!(spec_name, example_name)
|
50
52
|
run_specs('UISPEC_SPEC' => spec_name, 'UISPEC_EXAMPLE' => example_name)
|
51
|
-
end
|
53
|
+
end
|
52
54
|
|
53
55
|
def verbose?
|
54
56
|
self.verbose
|
55
57
|
end
|
56
58
|
|
57
59
|
private
|
58
|
-
def
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
"#{sdk_dir}/usr/libexec/securityd"
|
65
|
-
end
|
66
|
-
|
67
|
-
def start_securityd
|
68
|
-
run_command("launchctl submit -l UISpecRunnerDaemons -- #{path_to_securityd}")
|
69
|
-
@securityd_running = true
|
70
|
-
Signal.trap("INT") { stop_securityd }
|
71
|
-
Signal.trap("TERM") { stop_securityd }
|
72
|
-
Signal.trap("EXIT") { stop_securityd }
|
73
|
-
end
|
74
|
-
|
75
|
-
def stop_securityd
|
76
|
-
run_command("launchctl remove UISpecRunnerDaemons") if @securityd_running
|
77
|
-
@securityd_running = false
|
60
|
+
def driver_class
|
61
|
+
if self.driver == :shell
|
62
|
+
UISpecRunner::Drivers::Shell
|
63
|
+
elsif self.driver == :osascript
|
64
|
+
UISpecRunner::Drivers::OSAScript
|
65
|
+
end
|
78
66
|
end
|
79
67
|
|
80
68
|
def run_specs(env = {})
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
puts "Setting environment variables: #{run_env.inspect}" if verbose?
|
85
|
-
with_env(run_env) do
|
86
|
-
start_securityd if securityd
|
87
|
-
command = "#{build_dir}/#{configuration}-iphonesimulator/#{target}.app/#{target} -RegisterForSystemEvents"
|
88
|
-
puts "Executing: #{command}" if verbose?
|
89
|
-
output = `#{command}`
|
90
|
-
exit_code = $?
|
91
|
-
unless exit_code == 0
|
92
|
-
puts "[!] Failed to run UISpec target: #{output}"
|
93
|
-
exit 1
|
94
|
-
end
|
95
|
-
end
|
96
|
-
else
|
97
|
-
puts "[!] Failed to build UISpecs.app"
|
98
|
-
exit 1
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def sdk_dir
|
103
|
-
"/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator#{sdk_version}.sdk"
|
104
|
-
end
|
105
|
-
|
106
|
-
def tmpdir
|
107
|
-
Dir.tmpdir
|
108
|
-
end
|
109
|
-
|
110
|
-
def project_switch
|
111
|
-
"-project #{project}" if project
|
112
|
-
end
|
113
|
-
|
114
|
-
def sdk_switch
|
115
|
-
"-sdk #{sdk_dir}" if sdk_version
|
116
|
-
end
|
117
|
-
|
118
|
-
def build_project!
|
119
|
-
command = "xcodebuild #{project_switch} -target #{target} -configuration #{configuration} #{sdk_switch} > /dev/null"
|
120
|
-
puts "Building project with: #{command}" if verbose?
|
121
|
-
system(command)
|
122
|
-
end
|
123
|
-
|
124
|
-
def with_env(env)
|
125
|
-
before = env.inject({}) { |h, (k, _)| h[k] = ENV[k]; h }
|
126
|
-
env.each { |k, v| ENV[k] = v }
|
127
|
-
yield
|
128
|
-
ensure
|
129
|
-
before.each { |k, v| ENV[k] = v }
|
69
|
+
puts "Running specs via #{driver}..."
|
70
|
+
driver = driver_class.new(self)
|
71
|
+
driver.run_specs(env)
|
130
72
|
end
|
131
73
|
end
|
data/uispecrunner.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{uispecrunner}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Blake Watters"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-08-02}
|
13
13
|
s.default_executable = %q{uispec}
|
14
14
|
s.description = %q{Provides a simple Ruby interface for running UISpec iPhone tests}
|
15
15
|
s.email = %q{blake@twotoasters.com}
|
@@ -28,6 +28,8 @@ Gem::Specification.new do |s|
|
|
28
28
|
"bin/uispec",
|
29
29
|
"lib/uispecrunner.rb",
|
30
30
|
"lib/uispecrunner/application.rb",
|
31
|
+
"lib/uispecrunner/drivers/osascript.rb",
|
32
|
+
"lib/uispecrunner/drivers/shell.rb",
|
31
33
|
"lib/uispecrunner/options.rb",
|
32
34
|
"spec/options_spec.rb",
|
33
35
|
"spec/spec.opts",
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Blake Watters
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-08-02 00:00:00 -04:00
|
18
18
|
default_executable: uispec
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -50,6 +50,8 @@ files:
|
|
50
50
|
- bin/uispec
|
51
51
|
- lib/uispecrunner.rb
|
52
52
|
- lib/uispecrunner/application.rb
|
53
|
+
- lib/uispecrunner/drivers/osascript.rb
|
54
|
+
- lib/uispecrunner/drivers/shell.rb
|
53
55
|
- lib/uispecrunner/options.rb
|
54
56
|
- spec/options_spec.rb
|
55
57
|
- spec/spec.opts
|