xctasks 0.0.2 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8db63f529626e3355fb3ae6f57b384b8e430a7ae
4
- data.tar.gz: 83332db154670503b49a8efbd56736338b08044a
3
+ metadata.gz: e4e9db110bad3a10cdf968711f467637ea95f036
4
+ data.tar.gz: 73cf4abd0e9a47844c6281d9040f158c03c35af8
5
5
  SHA512:
6
- metadata.gz: 8ac9293c4cea8e9c1b544f415562628d918beed532a1273c11d2e6f97f24a0e7e2d871d2c8e30c687c7d11a9307464266f36c55d56288e8f19041e6486d54d3b
7
- data.tar.gz: c5f5d848b388301d63d7944dd0da6d309846ec2ef109b93f646baf24a62a7e10a00bb0a8abd229884087ccd689a5f69d1ef4c67fd3a85d3d0922636397eafd53
6
+ metadata.gz: b8a8fd14a1c5721a0c9803bc58a9dd249bfb6329561d59f5a205e102e182e042616d310950038e1f87381b429fb8659206f53ead410854a34c17870afd1d3b46
7
+ data.tar.gz: 43b8207d2f6ff79db039201d318ecfe152f3f355e58a562ec3694b4afb64713a96e48c5622919429f04f5b14ebd7febc6c6b8e0daebfe59b1e52f97bec8e1b30
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.0.0-p353
1
+ 2.0.0-p451
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- xctasks (0.0.1)
4
+ xctasks (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -17,11 +17,14 @@ XCTasks provides an interface for executing Xcode tests in a few ways using a un
17
17
  ```ruby
18
18
  require 'xctasks/test_task'
19
19
  XCTasks::TestTask.new(test: 'server:autostart') do |t|
20
- t.workspace = 'LayerKit.xcworkspace'
21
- t.ios_versions = %w{6.0 7.0}
22
- t.schemes = { unit: 'LayerKit Tests' }
20
+ t.workspace = 'LayerKit.xcworkspace'
23
21
  t.schemes_dir = 'Tests/Schemes' # Location where you store your shared schemes, will copy into workspace
24
22
  t.runner = :xctool # or :xcodebuild/:xcpretty
23
+
24
+ t.subtask(unit: 'LayerKit Tests') do |s|
25
+ s.ios_versions = %w{7.0 7.1}
26
+ end
27
+ t.schemes = { unit: 'LayerKit Tests' }
25
28
  end
26
29
  ```
27
30
 
@@ -37,6 +40,59 @@ rake test:unit:6.0 # Run unit tests against iOS Simulator 6.0
37
40
  rake test:unit:7.0 # Run unit tests against iOS Simulator 7.0
38
41
  ```
39
42
 
43
+ #### Kiwi on iOS and OS X Example
44
+
45
+ The following example is taken from [TransitionKit](http://github.com/blakewatters/TransitionKit) and executes a
46
+ [Kiwi](https://github.com/allending/Kiwi) test suite on OS X and iOS.
47
+
48
+ ```ruby
49
+ require 'xctasks/test_task'
50
+
51
+ XCTasks::TestTask.new(:spec) do |t|
52
+ t.workspace = 'TransitionKit.xcworkspace'
53
+ t.schemes_dir = 'Specs/Schemes'
54
+ t.runner = :xcpretty
55
+ t.actions = %w{clean test}
56
+
57
+ t.subtask(ios: 'iOS Specs') do |s|
58
+ s.sdk = :iphonesimulator
59
+ end
60
+
61
+ t.subtask(osx: 'OS X Specs') do |s|
62
+ s.sdk = :macosx
63
+ end
64
+ end
65
+ ```
66
+
67
+ #### Running Tests on Multiple Destinations
68
+
69
+ XCTasks supports a flexible syntax for specifying multiple destinations for your tests to execute on:
70
+
71
+ ```ruby
72
+ XCTasks::TestTask.new(:spec) do |t|
73
+ t.workspace = 'LayerKit.xcworkspace'
74
+ t.runner = :xctool
75
+
76
+ t.subtask :functional do |s|
77
+ s.runner = :xcodebuild
78
+ s.scheme = 'Functional Tests'
79
+
80
+ # Run on iOS Simulator, iPad, latest iOS
81
+ s.destination do |d|
82
+ d.platform = :iossimulator
83
+ d.name = 'iPad'
84
+ d.os = :latest
85
+ end
86
+
87
+ # Specify a complete destination as a string
88
+ s.destination('platform=iOS Simulator,OS=7.1,name=iPhone Retina (4-inch)')
89
+
90
+ # Quickly specify a physical device destination
91
+ s.destination platform: :ios, id: '437750527b43cff55a46f42ae86dbf870c7591b1'
92
+ end
93
+ end
94
+ ```
95
+
40
96
  ## Credits
41
97
 
42
98
  Blake Watters
data/Rakefile CHANGED
@@ -0,0 +1,5 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new(:spec)
4
+
5
+ task :default => :spec
@@ -2,11 +2,19 @@ require 'rake'
2
2
  require 'rake/tasklib'
3
3
 
4
4
  module XCTasks
5
+ module Command
6
+ def run(command, echo = true)
7
+ puts "Executing `#{command}`" if echo
8
+ system(command)
9
+ end
10
+ module_function :run
11
+ end
12
+
5
13
  class TestReport
6
14
  include Singleton
7
15
 
8
16
  def initialize
9
- @namespaces = {}
17
+ @subtask_results = {}
10
18
  @success = true
11
19
 
12
20
  at_exit do
@@ -14,9 +22,9 @@ module XCTasks
14
22
  end
15
23
  end
16
24
 
17
- def add_result(namespace, ios_version, success)
18
- @namespaces[namespace] ||= {}
19
- @namespaces[namespace][ios_version] = success
25
+ def add_result(subtask, options, success)
26
+ @subtask_results[subtask] ||= {}
27
+ @subtask_results[subtask][options] = success
20
28
  @success = false unless success
21
29
  end
22
30
 
@@ -33,9 +41,9 @@ module XCTasks
33
41
  end
34
42
 
35
43
  def report
36
- @namespaces.each do |namespace, version_status|
37
- version_status.each do |ios_version, success|
38
- puts "\033[0;31m!! #{namespace} tests failed under iOS #{ios_version}" unless success
44
+ @subtask_results.each do |subtask, options_results|
45
+ options_results.each do |options, success|
46
+ puts "\033[0;31m!! #{subtask.name} tests failed with options #{options}" unless success
39
47
  end
40
48
  end
41
49
  puts "\033[0;32m** All tests executed successfully" if success?
@@ -44,56 +52,241 @@ module XCTasks
44
52
 
45
53
  class TestTask < Rake::TaskLib
46
54
  class Destination
55
+ # Common Keys
47
56
  attr_accessor :platform, :name
48
57
 
58
+ # OS X attributes
59
+ attr_accessor :arch
60
+
61
+ # iOS keys
62
+ attr_accessor :id
63
+
64
+ # iOS Simulator keys
65
+ attr_accessor :os
66
+
67
+ def initialize(options = {})
68
+ options.each { |k,v| self[k] = v }
69
+ end
70
+
71
+ def platform=(platform)
72
+ valid_platforms = {osx: 'OS X', ios: 'iOS', iossimulator: 'iOS Simulator'}
73
+ raise ArgumentError, "Platform must be one of :osx, :ios, or :iossimulator" if platform.kind_of?(Symbol) && !valid_platforms.keys.include?(platform)
74
+ raise ArgumentError, "Platform must be one of 'OS X', 'iOS', or 'iOS Simulator'" if platform.kind_of?(String) && !valid_platforms.values.include?(platform)
75
+ @platform = platform.kind_of?(Symbol) ? valid_platforms[platform] : platform
76
+ end
77
+
78
+ def [](key)
79
+ send(key)
80
+ end
81
+
82
+ def []=(key, value)
83
+ send("#{key}=", value)
84
+ end
85
+
86
+ def to_s
87
+ keys = [:platform, :name, :arch, :id, :os].reject { |k| self[k].nil? }
88
+ keys.map { |k| "#{key_name(k)}='#{self[k].to_s.shellescape}'" }.join(',')
89
+ end
90
+
91
+ private
92
+ def key_name(attr)
93
+ attr == :os ? 'OS' : attr.to_s
94
+ end
95
+ end
96
+
97
+ class ConfigurationError < RuntimeError; end
98
+ class Configuration
99
+ SETTINGS = [:workspace, :schemes_dir, :sdk, :runner, :xctool_path,
100
+ :xcodebuild_path, :settings, :destinations, :actions,
101
+ :scheme, :ios_versions]
102
+ HELPERS = [:destination, :xctool?, :xcpretty?, :xcodebuild?]
103
+
104
+ # Configures delegations to pass through configuration accessor when extended
105
+ module Delegations
106
+ def self.extended(base)
107
+ base.extend Forwardable
108
+ accessors = SETTINGS.map { |attr| [attr, "#{attr}=".to_sym] }.flatten
109
+ base.def_delegators :@config, *accessors
110
+ base.def_delegators :@config, *HELPERS
111
+ end
112
+ end
113
+ attr_accessor(*SETTINGS)
114
+
49
115
  def initialize
116
+ @sdk = :iphonesimulator
117
+ @schemes_dir = nil
118
+ @xctool_path = '/usr/local/bin/xctool'
119
+ @xcodebuild_path = '/usr/bin/xcodebuild'
120
+ @runner = :xcodebuild
121
+ @settings = {}
50
122
  @platform = 'iOS Simulator'
51
- @name = 'iPhone Retina (4-inch)'
123
+ @destinations = []
124
+ @actions = %w{clean build test}
125
+ end
126
+
127
+ def runner=(runner)
128
+ raise ConfigurationError, "Must be :xcodebuild, :xctool or :xcpretty" unless %w{xctool xcodebuild xcpretty}.include?(runner.to_s)
129
+ @runner = runner.to_sym
130
+ end
131
+
132
+ def sdk=(sdk)
133
+ raise ArgumentError, "Can only assign sdk from a String or Symbol" unless sdk.kind_of?(String) || sdk.kind_of?(Symbol)
134
+ @sdk = sdk.to_sym
135
+ end
136
+
137
+ def destination(specifier = {})
138
+ if specifier.kind_of?(String)
139
+ raise ArgumentError, "Cannot configure a destination via a block when a complete String specifier is provided" if block_given?
140
+ @destinations << specifier.shellescape
141
+ elsif specifier.kind_of?(Hash)
142
+ destination = Destination.new(specifier)
143
+ yield destination if block_given?
144
+ @destinations << destination
145
+ else
146
+ raise ArgumentError, "Cannot configure a destination with a #{specifier}"
147
+ end
148
+ end
149
+
150
+ def validate!
151
+ raise ConfigurationError, "Cannot specify iOS versions with an SDK of :macosx" if sdk == :macosx && ios_versions
152
+ end
153
+
154
+ def xctool?
155
+ runner == :xctool
156
+ end
157
+
158
+ def xcodebuild?
159
+ runner == :xcodebuild
160
+ end
161
+
162
+ def xcpretty?
163
+ runner == :xcpretty
164
+ end
165
+
166
+ # Deep copy any nested structures
167
+ def dup
168
+ copy = super
169
+ copy.settings = settings.dup
170
+ copy.destinations = destinations.dup
171
+ return copy
172
+ end
173
+ end
174
+
175
+ class Subtask
176
+ extend Configuration::Delegations
177
+ include ::Rake::DSL if defined?(::Rake::DSL)
178
+
179
+ attr_reader :name, :config
180
+
181
+ def initialize(name_options, config)
182
+ @config = config.dup
183
+ self.name = name_options.kind_of?(Hash) ? name_options.keys.first : name_options.to_s
184
+ self.scheme = name_options.values.first if name_options.kind_of?(Hash)
185
+ end
186
+
187
+ def name=(name)
188
+ @name = name.to_s
189
+ end
190
+
191
+ def define_rake_tasks
192
+ @config.validate!
193
+
194
+ if namespaced?
195
+ namespace(name) do
196
+ ios_versions.each do |ios_version|
197
+ desc "Run #{name} tests against iOS Simulator #{ios_version} SDK"
198
+ task ios_version => :prepare do
199
+ run_tests(ios_version: ios_version)
200
+ end
201
+ end
202
+ end
203
+
204
+ desc "Run #{name} tests against iOS Simulator #{ios_versions.join(', ')}"
205
+ task name => ios_versions.map { |ios_version| "#{name}:#{ios_version}" }
206
+ else
207
+ desc "Run #{name} tests"
208
+ task self.name => :prepare do
209
+ run_tests
210
+ end
211
+ end
52
212
  end
53
213
 
54
- def to_arg(os_version)
55
- "platform='#{platform}',OS=#{os_version},name='#{name}'"
214
+ private
215
+
216
+ def namespaced?
217
+ ios_versions && ios_versions.any?
218
+ end
219
+
220
+ def run_tests(options = {})
221
+ ios_version = options[:ios_version]
222
+ XCTasks::Command.run(%q{killall "iPhone Simulator"}, false) if sdk == :iphonesimulator
223
+
224
+ success = if xctool?
225
+ actions_arg << " -freshSimulator" if ios_version
226
+ Command.run("#{xctool_path} -workspace #{workspace} -scheme '#{scheme}' -sdk #{sdk}#{ios_version}#{destination_arg}#{actions_arg}#{settings_arg}".strip)
227
+ elsif xcodebuild?
228
+ Command.run("#{xcodebuild_path} -workspace #{workspace} -scheme '#{scheme}' -sdk #{sdk}#{ios_version}#{destination_arg}#{actions_arg}#{settings_arg}".strip)
229
+ elsif xcpretty?
230
+ Command.run("#{xcodebuild_path} -workspace #{workspace} -scheme '#{scheme}' -sdk #{sdk}#{ios_version}#{destination_arg}#{actions_arg}#{settings_arg} | xcpretty -c ; exit ${PIPESTATUS[0]}".strip)
231
+ end
232
+
233
+ XCTasks::TestReport.instance.add_result(self, options, success)
234
+ end
235
+
236
+ def settings_arg
237
+ if settings.any?
238
+ " " << settings.map { |k,v| "#{k}=#{v}"}.join(' ')
239
+ else
240
+ nil
241
+ end
242
+ end
243
+
244
+ def actions_arg
245
+ " " << actions.join(' ')
246
+ end
247
+
248
+ def destination_arg
249
+ if destinations.any?
250
+ " " << destinations.map { |d| "-destination #{d}" }.join(' ')
251
+ else
252
+ nil
253
+ end
56
254
  end
57
255
  end
58
256
 
59
257
  include ::Rake::DSL if defined?(::Rake::DSL)
60
258
 
61
- attr_reader :namespace_name, :prepare_dependency
62
- attr_accessor :workspace, :schemes_dir, :schemes, :ios_versions
63
- attr_accessor :runner, :xctool_path, :xcodebuild_path
64
- attr_accessor :ios_versions, :destination, :settings, :actions
259
+ attr_reader :namespace_name, :prepare_dependency, :config, :subtasks
260
+ extend Configuration::Delegations
65
261
 
66
262
  def initialize(namespace_name = :test)
67
- @namespace_name = namespace_name.is_a?(Hash) ? namespace_name.keys.first : namespace_name
68
- @prepare_dependency = namespace_name.is_a?(Hash) ? namespace_name.values.first : nil
69
- @schemes_dir = nil
70
- @ios_versions = %w{7.0}
71
- @xctool_path = '/usr/local/bin/xctool'
72
- @xcodebuild_path = '/usr/bin/xcodebuild'
73
- @runner = :xcodebuild
74
- @destination = "platform='iOS Simulator',name='iPhone Retina (4-inch)'"
75
- @settings = {}
76
- @platform = 'iOS Simulator'
77
- @destination = Destination.new
78
- @actions = %w{clean build test}
263
+ @namespace_name = namespace_name
264
+ @config = Configuration.new
265
+ @subtasks = []
266
+ @namespace_name = namespace_name.kind_of?(Hash) ? namespace_name.keys.first : namespace_name
267
+ @prepare_dependency = namespace_name.kind_of?(Hash) ? namespace_name.values.first : nil
79
268
 
80
269
  yield self if block_given?
81
- raise "A workspace must be configured" unless workspace
82
- raise "At least one scheme must be configured" unless schemes
83
- define_tasks
270
+ raise ConfigurationError, "A workspace must be configured" unless workspace
271
+ raise ConfigurationError, "At least one subtask must be configured" if subtasks.empty?
272
+ define_rake_tasks
84
273
  end
85
274
 
86
- def runner=(runner)
87
- raise ArgumentError, "Must be :xcodebuild, :xctool or :xcpretty" unless %w{xctool xcodebuild xcpretty}.include?(runner.to_s)
88
- @runner = runner.to_sym
275
+ def subtasks=(subtasks)
276
+ if subtasks.kind_of?(Hash)
277
+ subtasks.each { |name, scheme| subtask(name => scheme) }
278
+ else
279
+ raise ArgumentError, "Cannot assign subtasks from a #{subtasks.class}"
280
+ end
89
281
  end
90
282
 
91
- def destination
92
- yield @destination if block_given?
93
- @destination
283
+ def subtask(name_options)
284
+ subtask = Subtask.new(name_options, config)
285
+ yield subtask if block_given?
286
+ @subtasks << subtask
94
287
  end
95
288
 
96
- def define_tasks
289
+ def define_rake_tasks
97
290
  namespace self.namespace_name do
98
291
  task (prepare_dependency ? { prepare: prepare_dependency} : :prepare ) do
99
292
  if schemes_dir
@@ -102,63 +295,14 @@ module XCTasks
102
295
  end
103
296
  end
104
297
 
105
- # Iterate across the schemes and define a task for each version of iOS and an aggregate task
106
- schemes.each do |scheme_namespace, scheme_name|
107
- namespace scheme_namespace do
108
- ios_versions.each do |ios_version|
109
- desc "Run #{scheme_namespace} tests against iOS Simulator #{ios_version} SDK"
110
- task ios_version => :prepare do
111
- test_scheme(scheme_name, namespace: scheme_namespace, ios_version: ios_version)
112
- end
113
- end
114
- end
115
-
116
- desc "Run #{scheme_namespace} tests against iOS Simulator #{ios_versions.join(', ')}"
117
- task scheme_namespace => ios_versions.map { |ios_version| "#{scheme_namespace}:#{ios_version}" }
118
- end
298
+ subtasks.each { |subtask| subtask.define_rake_tasks }
119
299
  end
120
300
 
121
- desc "Run the #{schemes.keys.join(', ')} tests"
122
- task namespace_name => schemes.keys.map { |scheme| "#{namespace_name}:#{scheme}" } do
301
+ subtask_names = subtasks.map { |subtask| subtask.name }
302
+ desc "Run all tests (#{subtask_names.join(', ')})"
303
+ task namespace_name => subtask_names.map { |subtask_name| "#{namespace_name}:#{subtask_name}" } do
123
304
  XCTasks::TestReport.instance.report
124
305
  end
125
306
  end
126
-
127
- private
128
- def run(command)
129
- puts "Executing `#{command}`"
130
- system(command)
131
- end
132
-
133
- def test_scheme(scheme, options)
134
- system(%q{killall "iPhone Simulator"})
135
- namespace = options[:namespace]
136
- ios_version = options[:ios_version]
137
- test_sdk = "#{ios_version}"
138
-
139
- settings_arg = settings.map { |k,v| "#{k}=#{v}"}.join(' ')
140
- destination_arg = destination.to_arg(ios_version)
141
- actions_arg = actions.join(' ')
142
- success = if xctool?
143
- run("#{xctool_path} -workspace #{workspace} -scheme '#{scheme}' -sdk iphonesimulator #{actions_arg} -freshSimulator -destination #{destination_arg} #{settings_arg}")
144
- elsif xcodebuild?
145
- run("#{xcodebuild_path} -workspace #{workspace} -scheme '#{scheme}' -sdk iphonesimulator #{actions_arg} -destination #{destination_arg} #{settings_arg}")
146
- elsif xcpretty?
147
- run("#{xcodebuild_path} -workspace #{workspace} -scheme '#{scheme}' -sdk iphonesimulator #{actions_arg} -destination #{destination_arg} #{settings_arg} | xcpretty -c ; exit ${PIPESTATUS[0]}")
148
- end
149
- XCTasks::TestReport.instance.add_result(namespace, ios_version, success)
150
- end
151
-
152
- def xctool?
153
- runner == :xctool
154
- end
155
-
156
- def xcodebuild?
157
- runner == :xcodebuild
158
- end
159
-
160
- def xcpretty?
161
- runner == :xcpretty
162
- end
163
307
  end
164
308
  end
@@ -1,3 +1,3 @@
1
1
  module XCTasks
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,11 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'xctasks'
5
+
6
+ require 'debugger'
7
+ Debugger.start
8
+
9
+ RSpec.configure do |config|
10
+ # some (optional) config here
11
+ end
@@ -0,0 +1,291 @@
1
+ require 'spec_helper'
2
+ require 'xctasks/test_task'
3
+
4
+ describe XCTasks::TestTask do
5
+ before(:each) do
6
+ @commands = []
7
+ XCTasks::Command.stub(:run) do |command|
8
+ @commands << command
9
+ end
10
+ FileUtils::Verbose.stub(:mkdir_p) do |path|
11
+ @commands << "mkdir -p #{path}"
12
+ end
13
+ FileUtils::Verbose.stub(:cp) do |src, dst|
14
+ @commands << "cp #{src} #{dst}"
15
+ end
16
+
17
+ Rake.application = rake
18
+ end
19
+
20
+ let(:rake) { Rake::Application.new }
21
+
22
+ describe 'simple task' do
23
+ let!(:task) do
24
+ XCTasks::TestTask.new do |t|
25
+ t.workspace = 'LayerKit.xcworkspace'
26
+ t.schemes_dir = 'Tests/Schemes'
27
+ t.runner = :xcpretty
28
+ t.subtasks = { unit: 'Unit Tests', functional: 'Functional Tests' }
29
+ end
30
+ end
31
+
32
+ it "configures the workspace" do
33
+ task.workspace.should == 'LayerKit.xcworkspace'
34
+ end
35
+
36
+ it "configures the schemes dir" do
37
+ task.schemes_dir.should == 'Tests/Schemes'
38
+ end
39
+
40
+ it "configures the runner" do
41
+ task.runner.should == :xcpretty
42
+ end
43
+
44
+ it "configures the tasks" do
45
+ expect(task.subtasks.count).to eq(2)
46
+ task.subtasks.map { |t| t.name }.should == ["unit", "functional"]
47
+ end
48
+
49
+ it "configures xcpretty for all tasks" do
50
+ task.subtasks.map { |t| t.runner }.should == [:xcpretty, :xcpretty]
51
+ end
52
+
53
+ describe 'tasks' do
54
+ describe 'spec:unit' do
55
+ subject { Rake.application['test:unit'] }
56
+
57
+ it "executes the appropriate commands" do
58
+ subject.invoke
59
+ @commands.should == ["mkdir -p LayerKit.xcworkspace/xcshareddata/xcschemes",
60
+ "cp [] LayerKit.xcworkspace/xcshareddata/xcschemes",
61
+ "killall \"iPhone Simulator\"",
62
+ "/usr/bin/xcodebuild -workspace LayerKit.xcworkspace -scheme 'Unit Tests' -sdk iphonesimulator clean build test | xcpretty -c ; exit ${PIPESTATUS[0]}"]
63
+ end
64
+ end
65
+
66
+ describe 'spec:functional' do
67
+ subject { Rake.application['test:functional'] }
68
+
69
+ it "executes the appropriate commands" do
70
+ subject.invoke
71
+ @commands.should == ["mkdir -p LayerKit.xcworkspace/xcshareddata/xcschemes",
72
+ "cp [] LayerKit.xcworkspace/xcshareddata/xcschemes",
73
+ "killall \"iPhone Simulator\"",
74
+ "/usr/bin/xcodebuild -workspace LayerKit.xcworkspace -scheme 'Functional Tests' -sdk iphonesimulator clean build test | xcpretty -c ; exit ${PIPESTATUS[0]}"]
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ describe 'advanced task' do
81
+ let!(:task) do
82
+ XCTasks::TestTask.new do |t|
83
+ t.workspace = 'LayerKit.xcworkspace'
84
+ t.runner = :xctool
85
+
86
+ t.subtask(unit: 'Unit Tests') do |s|
87
+ s.ios_versions = %w{7.0 7.1}
88
+ end
89
+
90
+ t.subtask :functional do |s|
91
+ s.runner = :xcodebuild
92
+ s.scheme = 'Functional Tests'
93
+ end
94
+ end
95
+ end
96
+
97
+ context "when the task overrides base options" do
98
+ it "uses the original runner by default" do
99
+ subtask = task.subtasks.detect { |t| t.name == 'unit' }
100
+ subtask.runner.should == :xctool
101
+ end
102
+
103
+ it "respects the override" do
104
+ subtask = task.subtasks.detect { |t| t.name == 'functional' }
105
+ subtask.runner.should == :xcodebuild
106
+ end
107
+ end
108
+
109
+ describe 'tasks' do
110
+ describe 'test:unit' do
111
+ subject { Rake.application['test:unit'] }
112
+
113
+ it "executes the appropriate commands" do
114
+ subject.invoke
115
+ @commands.should == [
116
+ "killall \"iPhone Simulator\"",
117
+ "/usr/local/bin/xctool -workspace LayerKit.xcworkspace -scheme 'Unit Tests' -sdk iphonesimulator7.0 clean build test",
118
+ "killall \"iPhone Simulator\"",
119
+ "/usr/local/bin/xctool -workspace LayerKit.xcworkspace -scheme 'Unit Tests' -sdk iphonesimulator7.1 clean build test"
120
+ ]
121
+ end
122
+ end
123
+
124
+ describe 'test:functional' do
125
+ subject { Rake.application['test:functional'] }
126
+
127
+ it "executes the appropriate commands" do
128
+ subject.invoke
129
+ @commands.should == [
130
+ "killall \"iPhone Simulator\"",
131
+ "/usr/bin/xcodebuild -workspace LayerKit.xcworkspace -scheme 'Functional Tests' -sdk iphonesimulator clean build test"
132
+ ]
133
+ end
134
+ end
135
+ end
136
+ end
137
+
138
+ describe 'Destination Configuration' do
139
+ let!(:task) do
140
+ XCTasks::TestTask.new(:spec) do |t|
141
+ t.workspace = 'LayerKit.xcworkspace'
142
+ t.runner = :xctool
143
+
144
+ t.subtask(unit: 'Unit Tests') do |s|
145
+ s.ios_versions = %w{7.0 7.1}
146
+ end
147
+
148
+ t.subtask :functional do |s|
149
+ s.runner = :xcodebuild
150
+ s.scheme = 'Functional Tests'
151
+ s.destination do |d|
152
+ d.platform = :iossimulator
153
+ d.name = 'iPad'
154
+ d.os = :latest
155
+ end
156
+ s.destination('platform=iOS Simulator,OS=7.1,name=iPhone Retina (4-inch)')
157
+ s.destination platform: :ios, id: '437750527b43cff55a46f42ae86dbf870c7591b1'
158
+ end
159
+ end
160
+ end
161
+
162
+ describe 'spec:unit' do
163
+ subject { Rake.application['spec:unit'] }
164
+
165
+ it "executes the appropriate commands" do
166
+ subject.invoke
167
+ @commands.should == [
168
+ "killall \"iPhone Simulator\"",
169
+ "/usr/local/bin/xctool -workspace LayerKit.xcworkspace -scheme 'Unit Tests' -sdk iphonesimulator7.0 clean build test",
170
+ "killall \"iPhone Simulator\"",
171
+ "/usr/local/bin/xctool -workspace LayerKit.xcworkspace -scheme 'Unit Tests' -sdk iphonesimulator7.1 clean build test"
172
+ ]
173
+ end
174
+ end
175
+
176
+ describe 'spec:functional' do
177
+ subject { Rake.application['spec:functional'] }
178
+
179
+ it "executes the appropriate commands" do
180
+ subject.invoke
181
+ @commands.should == [
182
+ "killall \"iPhone Simulator\"",
183
+ "/usr/bin/xcodebuild -workspace LayerKit.xcworkspace -scheme 'Functional Tests' -sdk iphonesimulator -destination platform='iOS\\ Simulator',name='iPad',OS='latest' -destination platform\\=iOS\\ Simulator,OS\\=7.1,name\\=iPhone\\ Retina\\ \\(4-inch\\) -destination platform='iOS',id='437750527b43cff55a46f42ae86dbf870c7591b1' clean build test"]
184
+ end
185
+ end
186
+ end
187
+
188
+ describe 'SDK Configuration' do
189
+ let!(:task) do
190
+ XCTasks::TestTask.new(:spec) do |t|
191
+ t.workspace = 'LayerKit.xcworkspace'
192
+ t.runner = :xctool
193
+
194
+ t.subtask(unit: 'Unit Tests') do |s|
195
+ s.sdk = :macosx
196
+ end
197
+ end
198
+ end
199
+
200
+ subject { Rake.application['spec:unit'] }
201
+
202
+ it "executes the appropriate commands" do
203
+ subject.invoke
204
+ @commands.should == ["/usr/local/bin/xctool -workspace LayerKit.xcworkspace -scheme 'Unit Tests' -sdk macosx clean build test"]
205
+ end
206
+ end
207
+
208
+ describe 'validations' do
209
+ it "raises an exception when an invalid value is assigned to the sdk" do
210
+ expect do
211
+ XCTasks::TestTask.new do |t|
212
+ t.sdk = []
213
+ end
214
+ end.to raise_error(ArgumentError, "Can only assign sdk from a String or Symbol")
215
+ end
216
+
217
+ context "when an invalid runner is specified" do
218
+ it "raises an exception" do
219
+ expect do
220
+ XCTasks::TestTask.new do |t|
221
+ t.runner = 'phantomjs'
222
+ end
223
+ end.to raise_error(XCTasks::TestTask::ConfigurationError, "Must be :xcodebuild, :xctool or :xcpretty")
224
+ end
225
+ end
226
+
227
+ context "when a workspace is not configured" do
228
+ it "raises an exception" do
229
+ expect do
230
+ XCTasks::TestTask.new do |t|
231
+ t.workspace = nil
232
+ end
233
+ end.to raise_error(XCTasks::TestTask::ConfigurationError, "A workspace must be configured")
234
+ end
235
+ end
236
+
237
+ context "when an SDK of macosx and ios versions is specified" do
238
+ it "raises an exception" do
239
+ expect do
240
+ XCTasks::TestTask.new do |t|
241
+ t.workspace = 'Workspace.workspace'
242
+ t.sdk = :macosx
243
+ t.ios_versions = %w{7.0}
244
+ t.subtasks = {unit: 'MyWorkspaceTests'}
245
+ end
246
+ end.to raise_error(XCTasks::TestTask::ConfigurationError, "Cannot specify iOS versions with an SDK of :macosx")
247
+ end
248
+ end
249
+ end
250
+
251
+ describe XCTasks::TestTask::Destination do
252
+ let(:destination) { XCTasks::TestTask::Destination.new }
253
+
254
+ describe '#platform=' do
255
+ it "allows assignment of :osx" do
256
+ destination.platform = :osx
257
+ expect(destination.platform).to eq('OS X')
258
+ end
259
+
260
+ it "allows assignment of 'OS X'" do
261
+ destination.platform = 'OS X'
262
+ expect(destination.platform).to eq('OS X')
263
+ end
264
+
265
+ it "allows assignment of :ios" do
266
+ destination.platform = :ios
267
+ expect(destination.platform).to eq('iOS')
268
+ end
269
+
270
+ it "allows assignment of 'iOS'" do
271
+ destination.platform = 'iOS'
272
+ expect(destination.platform).to eq('iOS')
273
+ end
274
+
275
+ it "allows assignment of :iossimulator" do
276
+ destination.platform = :iossimulator
277
+ expect(destination.platform).to eq('iOS Simulator')
278
+ end
279
+
280
+ it "allows assignment of 'iOS Simulator'" do
281
+ destination.platform = 'iOS Simulator'
282
+ expect(destination.platform).to eq('iOS Simulator')
283
+ end
284
+
285
+ it "disallows other values" do
286
+ expect { destination.platform = 'sdadsa' }.to raise_error(ArgumentError)
287
+ end
288
+ end
289
+
290
+ end
291
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xctasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Watters
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-08 00:00:00.000000000 Z
11
+ date: 2014-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -139,6 +139,8 @@ files:
139
139
  - lib/xctasks.rb
140
140
  - lib/xctasks/test_task.rb
141
141
  - lib/xctasks/version.rb
142
+ - spec/spec_helper.rb
143
+ - spec/test_task_spec.rb
142
144
  - xctasks.gemspec
143
145
  homepage: http://github.com/layerhq/xctasks
144
146
  licenses:
@@ -164,4 +166,6 @@ rubygems_version: 2.2.2
164
166
  signing_key:
165
167
  specification_version: 4
166
168
  summary: Provides a rich library of automation tasks for Xcode
167
- test_files: []
169
+ test_files:
170
+ - spec/spec_helper.rb
171
+ - spec/test_task_spec.rb