xctasks 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 44c29bdc01e0cd8764098668cd35d90d008c8430
4
- data.tar.gz: e5320e35f36890b7a3d1c41ca7c9c94dc94291e5
3
+ metadata.gz: 34ef1b9b2205fbb90a2c13d2b450f3618de89818
4
+ data.tar.gz: 0418f18b299f9dbea74b8e92886d06986f8c4e30
5
5
  SHA512:
6
- metadata.gz: 3ee30720c15e74fab78fe11e83a3e93f864f73e728eb48a32da3efb0290e221beba7d914812fceb594679339fa67e748e6348715b3f41e8cb62cb6323303550c
7
- data.tar.gz: 830d2731cab1d7200fd60feebd63bc4c744e9fae1f0616fdb929b57170a20c1776562022056d3ec5a3296fca29a181341769eb2dba1789a69f927d3059e7a51a
6
+ metadata.gz: 2141f6cc7d2a563a45f36da9723817fdf12d7cd5c6f50b76d314f29d5aa5c9e7b2baa59759806481a42818701907034b02b2e4b9d0ce03ba29c11d5d5de981bc
7
+ data.tar.gz: 115ca14974f4cb56957a12bfbb2284cbed60f45ec5645003ec2cf4d1d43d8972bfc73c9c01b8c88a56e78eff068336142926f3dcd61405c11d53ae1510bc6933
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # XCTasks Changelog
2
2
 
3
+ ## v0.3.0
4
+
5
+ * Added support for writing environment variables into schemes.
6
+
3
7
  ## v0.2.2
4
8
 
5
9
  * Added pre-flight validation of workspace and schemes dir
data/Gemfile.lock CHANGED
@@ -1,26 +1,29 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- xctasks (0.2.2)
4
+ xctasks (0.3.0)
5
+ nokogiri (~> 1.6.2.1)
6
+ rake (>= 10.0.0)
5
7
 
6
8
  GEM
7
9
  remote: https://rubygems.org/
8
10
  specs:
9
11
  addressable (2.3.5)
12
+ byebug (3.1.2)
13
+ columnize (~> 0.8)
14
+ debugger-linecache (~> 1.2)
10
15
  colored (1.2)
11
- columnize (0.3.6)
16
+ columnize (0.8.9)
12
17
  crack (0.4.2)
13
18
  safe_yaml (~> 1.0.0)
14
- debugger (1.6.6)
15
- columnize (>= 0.3.1)
16
- debugger-linecache (~> 1.2.0)
17
- debugger-ruby_core_source (~> 1.3.2)
18
19
  debugger-linecache (1.2.0)
19
- debugger-ruby_core_source (1.3.2)
20
20
  diff-lcs (1.2.5)
21
21
  excon (0.26.0)
22
+ mini_portile (0.6.0)
22
23
  multi_json (1.9.0)
23
- rake (10.1.1)
24
+ nokogiri (1.6.2.1)
25
+ mini_portile (= 0.6.0)
26
+ rake (10.3.2)
24
27
  rspec (2.14.1)
25
28
  rspec-core (~> 2.14.0)
26
29
  rspec-expectations (~> 2.14.0)
@@ -49,9 +52,8 @@ PLATFORMS
49
52
 
50
53
  DEPENDENCIES
51
54
  bundler (~> 1.3)
52
- debugger (~> 1.6.2)
55
+ byebug (~> 3.1.2)
53
56
  excon (~> 0.26.0)
54
- rake
55
57
  rspec (~> 2.14.0)
56
58
  simplecov (~> 0.7.1)
57
59
  tomdoc (~> 0.2.5)
@@ -1,6 +1,7 @@
1
1
  require 'rake'
2
2
  require 'rake/tasklib'
3
3
  require 'forwardable'
4
+ require 'nokogiri'
4
5
 
5
6
  module XCTasks
6
7
  module Command
@@ -10,37 +11,37 @@ module XCTasks
10
11
  end
11
12
  module_function :run
12
13
  end
13
-
14
+
14
15
  class TestReport
15
16
  include Singleton
16
-
17
+
17
18
  def initialize
18
19
  @subtask_results = {}
19
20
  @success = true
20
-
21
+
21
22
  at_exit do
22
23
  exit(-1) if failure?
23
24
  end
24
25
  end
25
-
26
+
26
27
  def add_result(subtask, options, success)
27
28
  @subtask_results[subtask] ||= {}
28
29
  @subtask_results[subtask][options] = success
29
30
  @success = false unless success
30
31
  end
31
-
32
+
32
33
  def [](ios_version)
33
34
  @namespaces[ios_version]
34
35
  end
35
-
36
+
36
37
  def success?
37
38
  @success
38
39
  end
39
-
40
+
40
41
  def failure?
41
42
  @success == false
42
43
  end
43
-
44
+
44
45
  def report
45
46
  @subtask_results.each do |subtask, options_results|
46
47
  options_results.each do |options, success|
@@ -50,58 +51,58 @@ module XCTasks
50
51
  puts "\033[0;32m** All tests executed successfully\033[0m" if success?
51
52
  end
52
53
  end
53
-
54
+
54
55
  class TestTask < Rake::TaskLib
55
56
  class Destination
56
57
  # Common Keys
57
58
  attr_accessor :platform, :name
58
-
59
+
59
60
  # OS X attributes
60
61
  attr_accessor :arch
61
-
62
+
62
63
  # iOS keys
63
64
  attr_accessor :id
64
-
65
+
65
66
  # iOS Simulator keys
66
67
  attr_accessor :os
67
-
68
+
68
69
  def initialize(options = {})
69
70
  options.each { |k,v| self[k] = v }
70
71
  end
71
-
72
+
72
73
  def platform=(platform)
73
74
  valid_platforms = {osx: 'OS X', ios: 'iOS', iossimulator: 'iOS Simulator'}
74
75
  raise ArgumentError, "Platform must be one of :osx, :ios, or :iossimulator" if platform.kind_of?(Symbol) && !valid_platforms.keys.include?(platform)
75
- raise ArgumentError, "Platform must be one of 'OS X', 'iOS', or 'iOS Simulator'" if platform.kind_of?(String) && !valid_platforms.values.include?(platform)
76
+ raise ArgumentError, "Platform must be one of 'OS X', 'iOS', or 'iOS Simulator'" if platform.kind_of?(String) && !valid_platforms.values.include?(platform)
76
77
  @platform = platform.kind_of?(Symbol) ? valid_platforms[platform] : platform
77
78
  end
78
-
79
+
79
80
  def [](key)
80
81
  send(key)
81
82
  end
82
-
83
+
83
84
  def []=(key, value)
84
85
  send("#{key}=", value)
85
- end
86
-
86
+ end
87
+
87
88
  def to_s
88
- keys = [:platform, :name, :arch, :id, :os].reject { |k| self[k].nil? }
89
+ keys = [:platform, :name, :arch, :id, :os].reject { |k| self[k].nil? }
89
90
  keys.map { |k| "#{key_name(k)}='#{self[k].to_s}'" }.join(',')
90
91
  end
91
-
92
+
92
93
  private
93
94
  def key_name(attr)
94
95
  attr == :os ? 'OS' : attr.to_s
95
96
  end
96
97
  end
97
-
98
- class ConfigurationError < RuntimeError; end
98
+
99
+ class ConfigurationError < RuntimeError; end
99
100
  class Configuration
100
- SETTINGS = [:workspace, :schemes_dir, :sdk, :runner, :xctool_path,
101
+ SETTINGS = [:workspace, :schemes_dir, :sdk, :runner, :xctool_path,
101
102
  :xcodebuild_path, :settings, :destinations, :actions,
102
- :scheme, :ios_versions, :output_log]
103
+ :scheme, :ios_versions, :output_log, :env]
103
104
  HELPERS = [:destination, :xctool?, :xcpretty?, :xcodebuild?]
104
-
105
+
105
106
  # Configures delegations to pass through configuration accessor when extended
106
107
  module Delegations
107
108
  def self.extended(base)
@@ -109,10 +110,10 @@ module XCTasks
109
110
  accessors = SETTINGS.map { |attr| [attr, "#{attr}=".to_sym] }.flatten
110
111
  base.def_delegators :@config, *accessors
111
112
  base.def_delegators :@config, *HELPERS
112
- end
113
+ end
113
114
  end
114
115
  attr_accessor(*SETTINGS)
115
-
116
+
116
117
  def initialize
117
118
  @sdk = :iphonesimulator
118
119
  @schemes_dir = nil
@@ -123,19 +124,20 @@ module XCTasks
123
124
  @platform = 'iOS Simulator'
124
125
  @destinations = []
125
126
  @actions = %w{clean build test}
127
+ @env = {}
126
128
  end
127
-
129
+
128
130
  def runner=(runner)
129
131
  runner_bin = runner.to_s.split(' ')[0]
130
132
  raise ConfigurationError, "Must be :xcodebuild, :xctool or :xcpretty" unless %w{xctool xcodebuild xcpretty}.include?(runner_bin)
131
133
  @runner = runner
132
134
  end
133
-
135
+
134
136
  def sdk=(sdk)
135
137
  raise ArgumentError, "Can only assign sdk from a String or Symbol" unless sdk.kind_of?(String) || sdk.kind_of?(Symbol)
136
138
  @sdk = sdk.to_sym
137
139
  end
138
-
140
+
139
141
  def destination(specifier = {})
140
142
  if specifier.kind_of?(String)
141
143
  raise ArgumentError, "Cannot configure a destination via a block when a complete String specifier is provided" if block_given?
@@ -148,11 +150,11 @@ module XCTasks
148
150
  raise ArgumentError, "Cannot configure a destination with a #{specifier}"
149
151
  end
150
152
  end
151
-
153
+
152
154
  def validate!
153
155
  raise ConfigurationError, "Cannot specify iOS versions with an SDK of :macosx" if sdk == :macosx && ios_versions
154
156
  end
155
-
157
+
156
158
  def xctool?
157
159
  runner =~ /^xctool/
158
160
  end
@@ -160,11 +162,11 @@ module XCTasks
160
162
  def xcodebuild?
161
163
  runner =~ /^xcodebuild/
162
164
  end
163
-
165
+
164
166
  def xcpretty?
165
167
  runner =~ /^xcpretty/
166
168
  end
167
-
169
+
168
170
  # Deep copy any nested structures
169
171
  def dup
170
172
  copy = super
@@ -173,26 +175,26 @@ module XCTasks
173
175
  return copy
174
176
  end
175
177
  end
176
-
178
+
177
179
  class Subtask
178
180
  extend Configuration::Delegations
179
181
  include ::Rake::DSL if defined?(::Rake::DSL)
180
-
182
+
181
183
  attr_reader :name, :config
182
-
184
+
183
185
  def initialize(name_options, config)
184
- @config = config.dup
186
+ @config = config.dup
185
187
  self.name = name_options.kind_of?(Hash) ? name_options.keys.first : name_options.to_s
186
- self.scheme = name_options.values.first if name_options.kind_of?(Hash)
188
+ self.scheme = name_options.values.first if name_options.kind_of?(Hash)
187
189
  end
188
-
190
+
189
191
  def name=(name)
190
192
  @name = name.to_s
191
193
  end
192
-
194
+
193
195
  def define_rake_tasks
194
196
  @config.validate!
195
-
197
+
196
198
  if namespaced?
197
199
  namespace(name) do
198
200
  ios_versions.each do |ios_version|
@@ -202,7 +204,7 @@ module XCTasks
202
204
  end
203
205
  end
204
206
  end
205
-
207
+
206
208
  desc "Run #{name} tests against iOS Simulator #{ios_versions.join(', ')}"
207
209
  task name => ios_versions.map { |ios_version| "#{name}:#{ios_version}" }
208
210
  else
@@ -212,17 +214,21 @@ module XCTasks
212
214
  end
213
215
  end
214
216
  end
215
-
217
+
218
+ def prepare
219
+ write_environment_variables_to_scheme
220
+ end
221
+
216
222
  private
217
-
223
+
218
224
  def namespaced?
219
225
  ios_versions && ios_versions.any?
220
- end
221
-
222
- def run_tests(options = {})
226
+ end
227
+
228
+ def run_tests(options = {})
223
229
  ios_version = options[:ios_version]
224
230
  XCTasks::Command.run(%q{killall "iPhone Simulator"}, false) if sdk == :iphonesimulator
225
-
231
+
226
232
  output_log_command = output_log ? " | tee -a #{output_log} " : ' '
227
233
  success = if xctool?
228
234
  actions_arg << " -freshSimulator" if ios_version
@@ -233,10 +239,10 @@ module XCTasks
233
239
  xcpretty_bin = runner.is_a?(String) ? runner : "xcpretty -c"
234
240
  Command.run("#{xcodebuild_path} -workspace #{workspace} -scheme '#{scheme}' -sdk #{sdk}#{ios_version}#{destination_arg}#{actions_arg}#{settings_arg}#{output_log_command}| #{xcpretty_bin} ; exit ${PIPESTATUS[0]}".strip)
235
241
  end
236
-
242
+
237
243
  XCTasks::TestReport.instance.add_result(self, options, success)
238
244
  end
239
-
245
+
240
246
  def settings_arg
241
247
  if settings.any?
242
248
  " " << settings.map { |k,v| "#{k}=#{v}"}.join(' ')
@@ -244,11 +250,11 @@ module XCTasks
244
250
  nil
245
251
  end
246
252
  end
247
-
253
+
248
254
  def actions_arg
249
255
  " " << actions.join(' ')
250
256
  end
251
-
257
+
252
258
  def destination_arg
253
259
  if destinations.any?
254
260
  " " << destinations.map { |d| "-destination #{d}" }.join(' ')
@@ -256,26 +262,44 @@ module XCTasks
256
262
  nil
257
263
  end
258
264
  end
265
+
266
+ def write_environment_variables_to_scheme
267
+ if env.any?
268
+ path = "#{workspace}/xcshareddata/xcschemes/#{scheme}.xcscheme"
269
+ doc = Nokogiri::XML(File.read(path))
270
+ testable_node = doc.at('TestAction')
271
+ env_variables_node = Nokogiri::XML::Node.new "EnvironmentVariables", doc
272
+ env.each do |key, value|
273
+ node = Nokogiri::XML::Node.new "EnvironmentVariable", doc
274
+ node.set_attribute "key", key
275
+ node.set_attribute "value", value
276
+ node.set_attribute "isEnabled", "YES"
277
+ env_variables_node << node
278
+ end
279
+ testable_node << env_variables_node
280
+ File.open(path, 'w') { |f| f << doc.to_s }
281
+ end
282
+ end
259
283
  end
260
-
284
+
261
285
  include ::Rake::DSL if defined?(::Rake::DSL)
262
-
286
+
263
287
  attr_reader :namespace_name, :prepare_dependency, :config, :subtasks
264
288
  extend Configuration::Delegations
265
-
289
+
266
290
  def initialize(namespace_name = :test)
267
291
  @namespace_name = namespace_name
268
292
  @config = Configuration.new
269
293
  @subtasks = []
270
294
  @namespace_name = namespace_name.kind_of?(Hash) ? namespace_name.keys.first : namespace_name
271
- @prepare_dependency = namespace_name.kind_of?(Hash) ? namespace_name.values.first : nil
272
-
295
+ @prepare_dependency = namespace_name.kind_of?(Hash) ? namespace_name.values.first : nil
296
+
273
297
  yield self if block_given?
274
298
  raise ConfigurationError, "A workspace must be configured" unless workspace
275
299
  raise ConfigurationError, "At least one subtask must be configured" if subtasks.empty?
276
300
  define_rake_tasks
277
301
  end
278
-
302
+
279
303
  def subtasks=(subtasks)
280
304
  if subtasks.kind_of?(Hash)
281
305
  subtasks.each { |name, scheme| subtask(name => scheme) }
@@ -283,13 +307,13 @@ module XCTasks
283
307
  raise ArgumentError, "Cannot assign subtasks from a #{subtasks.class}"
284
308
  end
285
309
  end
286
-
310
+
287
311
  def subtask(name_options)
288
312
  subtask = Subtask.new(name_options, config)
289
313
  yield subtask if block_given?
290
314
  @subtasks << subtask
291
315
  end
292
-
316
+
293
317
  def define_rake_tasks
294
318
  namespace self.namespace_name do
295
319
  task (prepare_dependency ? { prepare: prepare_dependency} : :prepare ) do
@@ -300,11 +324,12 @@ module XCTasks
300
324
  FileUtils::Verbose.mkdir_p "#{workspace}/xcshareddata/xcschemes"
301
325
  FileUtils::Verbose.cp Dir.glob("#{schemes_dir}/*.xcscheme"), "#{workspace}/xcshareddata/xcschemes"
302
326
  end
327
+ subtasks.each { |subtask| subtask.prepare }
303
328
  end
304
-
329
+
305
330
  subtasks.each { |subtask| subtask.define_rake_tasks }
306
331
  end
307
-
332
+
308
333
  subtask_names = subtasks.map { |subtask| subtask.name }
309
334
  desc "Run all tests (#{subtask_names.join(', ')})"
310
335
  task namespace_name => subtask_names.map { |subtask_name| "#{namespace_name}:#{subtask_name}" } do
@@ -1,3 +1,3 @@
1
1
  module XCTasks
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -0,0 +1,69 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Scheme
3
+ LastUpgradeVersion = "0510"
4
+ version = "1.3">
5
+ <BuildAction
6
+ parallelizeBuildables = "YES"
7
+ buildImplicitDependencies = "YES">
8
+ <BuildActionEntries>
9
+ <BuildActionEntry
10
+ buildForTesting = "YES"
11
+ buildForRunning = "YES"
12
+ buildForProfiling = "YES"
13
+ buildForArchiving = "YES"
14
+ buildForAnalyzing = "YES">
15
+ <BuildableReference
16
+ BuildableIdentifier = "primary"
17
+ BlueprintIdentifier = "258DC9F818DA6C8100391C84"
18
+ BuildableName = "Unit Tests.xctest"
19
+ BlueprintName = "Unit Tests"
20
+ ReferencedContainer = "container:LayerKit.xcodeproj">
21
+ </BuildableReference>
22
+ </BuildActionEntry>
23
+ </BuildActionEntries>
24
+ </BuildAction>
25
+ <TestAction
26
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
27
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
28
+ shouldUseLaunchSchemeArgsEnv = "NO"
29
+ buildConfiguration = "Debug">
30
+ <Testables>
31
+ <TestableReference
32
+ skipped = "NO">
33
+ <BuildableReference
34
+ BuildableIdentifier = "primary"
35
+ BlueprintIdentifier = "258DC9F818DA6C8100391C84"
36
+ BuildableName = "Unit Tests.xctest"
37
+ BlueprintName = "Unit Tests"
38
+ ReferencedContainer = "container:LayerKit.xcodeproj">
39
+ </BuildableReference>
40
+ </TestableReference>
41
+ </Testables>
42
+ </TestAction>
43
+ <LaunchAction
44
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
45
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
46
+ launchStyle = "0"
47
+ useCustomWorkingDirectory = "NO"
48
+ buildConfiguration = "Debug"
49
+ ignoresPersistentStateOnLaunch = "NO"
50
+ debugDocumentVersioning = "YES"
51
+ allowLocationSimulation = "YES">
52
+ <AdditionalOptions>
53
+ </AdditionalOptions>
54
+ </LaunchAction>
55
+ <ProfileAction
56
+ shouldUseLaunchSchemeArgsEnv = "YES"
57
+ savedToolIdentifier = ""
58
+ useCustomWorkingDirectory = "NO"
59
+ buildConfiguration = "Release"
60
+ debugDocumentVersioning = "YES">
61
+ </ProfileAction>
62
+ <AnalyzeAction
63
+ buildConfiguration = "Debug">
64
+ </AnalyzeAction>
65
+ <ArchiveAction
66
+ buildConfiguration = "Release"
67
+ revealArchiveInOrganizer = "YES">
68
+ </ArchiveAction>
69
+ </Scheme>
data/spec/spec_helper.rb CHANGED
@@ -3,8 +3,7 @@ Bundler.setup
3
3
 
4
4
  require 'xctasks'
5
5
 
6
- require 'debugger'
7
- Debugger.start
6
+ require 'byebug'
8
7
 
9
8
  RSpec.configure do |config|
10
9
  # some (optional) config here
@@ -14,210 +14,235 @@ describe XCTasks::TestTask do
14
14
  FileUtils::Verbose.stub(:cp) do |src, dst|
15
15
  @commands << "cp #{src} #{dst}"
16
16
  end
17
-
17
+
18
18
  Rake.application = rake
19
-
19
+
20
20
  Dir.mktmpdir.tap do |path|
21
- FileUtils.touch(path + '/LayerKit.xcworkspace')
21
+ FileUtils.mkdir_p(path + '/LayerKit.xcworkspace/xcshareddata/xcschemes')
22
22
  FileUtils.mkdir_p(path + '/Tests/Schemes')
23
23
  Dir.chdir(path)
24
24
  end
25
25
  end
26
-
26
+
27
27
  let(:rake) { Rake::Application.new }
28
-
28
+
29
29
  describe "test:prepare" do
30
30
  subject { Rake.application['test:prepare'] }
31
-
31
+
32
32
  context "when the given workspace does not exist" do
33
33
  let!(:task) do
34
34
  XCTasks::TestTask.new do |t|
35
- t.workspace = 'Invalid.xcworkspace'
36
- t.schemes_dir = 'Tests/Schemes'
35
+ t.workspace = 'Invalid.xcworkspace'
36
+ t.schemes_dir = 'Tests/Schemes'
37
37
  t.runner = :xcpretty
38
38
  t.subtasks = { unit: 'Unit Tests', functional: 'Functional Tests' }
39
39
  end
40
40
  end
41
-
41
+
42
42
  it "fails" do
43
43
  expect { subject.invoke }.to raise_error(RuntimeError, "No such workspace: Invalid.xcworkspace")
44
44
  end
45
45
  end
46
-
46
+
47
47
  context "when the given schemes_dir is nil" do
48
48
  let!(:task) do
49
49
  XCTasks::TestTask.new do |t|
50
- t.workspace = 'LayerKit.xcworkspace'
50
+ t.workspace = 'LayerKit.xcworkspace'
51
51
  t.schemes_dir = nil
52
52
  t.runner = :xcpretty
53
53
  t.subtasks = { unit: 'Unit Tests', functional: 'Functional Tests' }
54
54
  end
55
55
  end
56
-
56
+
57
57
  it "succeeds" do
58
58
  expect { subject.invoke }.not_to raise_error
59
59
  end
60
60
  end
61
-
61
+
62
62
  context "when the given schemes_dir does not exist" do
63
63
  let!(:task) do
64
64
  XCTasks::TestTask.new do |t|
65
- t.workspace = 'LayerKit.xcworkspace'
65
+ t.workspace = 'LayerKit.xcworkspace'
66
66
  t.schemes_dir = 'this/path/is/invalid'
67
67
  t.runner = :xcpretty
68
68
  t.subtasks = { unit: 'Unit Tests', functional: 'Functional Tests' }
69
69
  end
70
70
  end
71
-
71
+
72
72
  it "fails" do
73
73
  expect { subject.invoke }.to raise_error(RuntimeError, "Invalid schemes directory: this/path/is/invalid")
74
74
  end
75
75
  end
76
76
  end
77
-
77
+
78
78
  describe 'simple task' do
79
79
  let!(:task) do
80
80
  XCTasks::TestTask.new do |t|
81
- t.workspace = 'LayerKit.xcworkspace'
82
- t.schemes_dir = 'Tests/Schemes'
81
+ t.workspace = 'LayerKit.xcworkspace'
82
+ t.schemes_dir = 'Tests/Schemes'
83
83
  t.runner = :xcpretty
84
84
  t.subtasks = { unit: 'Unit Tests', functional: 'Functional Tests' }
85
85
  end
86
86
  end
87
-
87
+
88
88
  it "configures the workspace" do
89
89
  task.workspace.should == 'LayerKit.xcworkspace'
90
90
  end
91
-
91
+
92
92
  it "configures the schemes dir" do
93
93
  task.schemes_dir.should == 'Tests/Schemes'
94
94
  end
95
-
95
+
96
96
  it "configures the runner" do
97
97
  task.runner.should == :xcpretty
98
98
  end
99
-
99
+
100
100
  it "configures the tasks" do
101
101
  expect(task.subtasks.count).to eq(2)
102
102
  task.subtasks.map { |t| t.name }.should == ["unit", "functional"]
103
103
  end
104
-
104
+
105
105
  it "configures xcpretty for all tasks" do
106
106
  task.subtasks.map { |t| t.runner }.should == [:xcpretty, :xcpretty]
107
107
  end
108
-
108
+
109
109
  describe 'tasks' do
110
110
  describe 'spec:unit' do
111
111
  subject { Rake.application['test:unit'] }
112
-
112
+
113
113
  it "executes the appropriate commands" do
114
114
  subject.invoke
115
- @commands.should == ["mkdir -p LayerKit.xcworkspace/xcshareddata/xcschemes",
116
- "cp [] LayerKit.xcworkspace/xcshareddata/xcschemes",
117
- "killall \"iPhone Simulator\"",
115
+ @commands.should == ["mkdir -p LayerKit.xcworkspace/xcshareddata/xcschemes",
116
+ "cp [] LayerKit.xcworkspace/xcshareddata/xcschemes",
117
+ "killall \"iPhone Simulator\"",
118
118
  "/usr/bin/xcodebuild -workspace LayerKit.xcworkspace -scheme 'Unit Tests' -sdk iphonesimulator clean build test | xcpretty -c ; exit ${PIPESTATUS[0]}"]
119
119
  end
120
120
  end
121
-
121
+
122
122
  describe 'spec:functional' do
123
123
  subject { Rake.application['test:functional'] }
124
-
124
+
125
125
  it "executes the appropriate commands" do
126
126
  subject.invoke
127
- @commands.should == ["mkdir -p LayerKit.xcworkspace/xcshareddata/xcschemes",
128
- "cp [] LayerKit.xcworkspace/xcshareddata/xcschemes",
127
+ @commands.should == ["mkdir -p LayerKit.xcworkspace/xcshareddata/xcschemes",
128
+ "cp [] LayerKit.xcworkspace/xcshareddata/xcschemes",
129
129
  "killall \"iPhone Simulator\"",
130
130
  "/usr/bin/xcodebuild -workspace LayerKit.xcworkspace -scheme 'Functional Tests' -sdk iphonesimulator clean build test | xcpretty -c ; exit ${PIPESTATUS[0]}"]
131
131
  end
132
132
  end
133
133
  end
134
134
  end
135
-
135
+
136
136
  describe 'task with log' do
137
137
  let!(:task) do
138
138
  XCTasks::TestTask.new do |t|
139
- t.workspace = 'LayerKit.xcworkspace'
140
- t.schemes_dir = 'Tests/Schemes'
139
+ t.workspace = 'LayerKit.xcworkspace'
140
+ t.schemes_dir = 'Tests/Schemes'
141
141
  t.runner = 'xcpretty -s'
142
142
  t.output_log = 'output.log'
143
143
  t.subtasks = { unit: 'Unit Tests', functional: 'Functional Tests' }
144
144
  end
145
145
  end
146
-
146
+
147
147
  describe 'tasks' do
148
148
  describe 'spec:unit' do
149
149
  subject { Rake.application['test:unit'] }
150
-
150
+
151
151
  it "executes the appropriate commands" do
152
152
  subject.invoke
153
- @commands.should == ["mkdir -p LayerKit.xcworkspace/xcshareddata/xcschemes",
154
- "cp [] LayerKit.xcworkspace/xcshareddata/xcschemes",
155
- "killall \"iPhone Simulator\"",
153
+ @commands.should == ["mkdir -p LayerKit.xcworkspace/xcshareddata/xcschemes",
154
+ "cp [] LayerKit.xcworkspace/xcshareddata/xcschemes",
155
+ "killall \"iPhone Simulator\"",
156
156
  "/usr/bin/xcodebuild -workspace LayerKit.xcworkspace -scheme 'Unit Tests' -sdk iphonesimulator clean build test | tee -a output.log | xcpretty -s ; exit ${PIPESTATUS[0]}"]
157
157
  end
158
158
  end
159
-
159
+
160
160
  describe 'spec:functional' do
161
161
  subject { Rake.application['test:functional'] }
162
-
162
+
163
163
  it "executes the appropriate commands" do
164
164
  subject.invoke
165
- @commands.should == ["mkdir -p LayerKit.xcworkspace/xcshareddata/xcschemes",
166
- "cp [] LayerKit.xcworkspace/xcshareddata/xcschemes",
165
+ @commands.should == ["mkdir -p LayerKit.xcworkspace/xcshareddata/xcschemes",
166
+ "cp [] LayerKit.xcworkspace/xcshareddata/xcschemes",
167
167
  "killall \"iPhone Simulator\"",
168
168
  "/usr/bin/xcodebuild -workspace LayerKit.xcworkspace -scheme 'Functional Tests' -sdk iphonesimulator clean build test | tee -a output.log | xcpretty -s ; exit ${PIPESTATUS[0]}"]
169
169
  end
170
170
  end
171
171
  end
172
172
  end
173
-
173
+
174
+ describe 'task with environment variables' do
175
+ let!(:task) do
176
+ XCTasks::TestTask.new do |t|
177
+ t.workspace = 'LayerKit.xcworkspace'
178
+ t.schemes_dir = 'Tests/Schemes'
179
+ t.runner = 'xcpretty -s'
180
+ t.output_log = 'output.log'
181
+ t.env["LAYER_TEST_HOST"] = "10.66.0.35"
182
+ t.subtasks = { unit: 'Unit Tests' }
183
+ end
184
+ end
185
+
186
+ subject { Rake.application['test:unit'] }
187
+
188
+ it "writes the environment variables into the scheme" do
189
+ FileUtils.cp File.dirname(__FILE__) + '/Unit Tests.xcscheme', "LayerKit.xcworkspace/xcshareddata/xcschemes/"
190
+ subject.invoke
191
+ doc = Nokogiri::XML File.read("LayerKit.xcworkspace/xcshareddata/xcschemes/Unit Tests.xcscheme")
192
+ node = doc.at('TestAction/EnvironmentVariables/EnvironmentVariable')
193
+ expect(node).not_to be_nil
194
+ attributes = node.attributes.inject({}) { |hash, pair| hash[pair[0]] = pair[1].to_s; hash }
195
+ attributes.should == {"key"=>"LAYER_TEST_HOST", "value"=>"10.66.0.35", "isEnabled"=>"YES"}
196
+ end
197
+ end
198
+
174
199
  describe 'advanced task' do
175
200
  let!(:task) do
176
201
  XCTasks::TestTask.new do |t|
177
202
  t.workspace = 'LayerKit.xcworkspace'
178
203
  t.runner = :xctool
179
-
204
+
180
205
  t.subtask(unit: 'Unit Tests') do |s|
181
206
  s.ios_versions = %w{7.0 7.1}
182
207
  end
183
-
208
+
184
209
  t.subtask :functional do |s|
185
210
  s.runner = :xcodebuild
186
211
  s.scheme = 'Functional Tests'
187
212
  end
188
213
  end
189
214
  end
190
-
215
+
191
216
  context "when the task overrides base options" do
192
217
  it "uses the original runner by default" do
193
218
  subtask = task.subtasks.detect { |t| t.name == 'unit' }
194
219
  subtask.runner.should == :xctool
195
220
  end
196
-
221
+
197
222
  it "respects the override" do
198
223
  subtask = task.subtasks.detect { |t| t.name == 'functional' }
199
224
  subtask.runner.should == :xcodebuild
200
225
  end
201
226
  end
202
-
227
+
203
228
  describe 'tasks' do
204
229
  describe 'test:unit' do
205
230
  subject { Rake.application['test:unit'] }
206
-
231
+
207
232
  it "executes the appropriate commands" do
208
233
  subject.invoke
209
234
  @commands.should == [
210
- "killall \"iPhone Simulator\"",
211
- "/usr/local/bin/xctool -workspace LayerKit.xcworkspace -scheme 'Unit Tests' -sdk iphonesimulator7.0 clean build test",
212
- "killall \"iPhone Simulator\"",
235
+ "killall \"iPhone Simulator\"",
236
+ "/usr/local/bin/xctool -workspace LayerKit.xcworkspace -scheme 'Unit Tests' -sdk iphonesimulator7.0 clean build test",
237
+ "killall \"iPhone Simulator\"",
213
238
  "/usr/local/bin/xctool -workspace LayerKit.xcworkspace -scheme 'Unit Tests' -sdk iphonesimulator7.1 clean build test"
214
239
  ]
215
240
  end
216
241
  end
217
-
242
+
218
243
  describe 'test:functional' do
219
244
  subject { Rake.application['test:functional'] }
220
-
245
+
221
246
  it "executes the appropriate commands" do
222
247
  subject.invoke
223
248
  @commands.should == [
@@ -228,17 +253,17 @@ describe XCTasks::TestTask do
228
253
  end
229
254
  end
230
255
  end
231
-
256
+
232
257
  describe 'Destination Configuration' do
233
258
  let!(:task) do
234
259
  XCTasks::TestTask.new(:spec) do |t|
235
260
  t.workspace = 'LayerKit.xcworkspace'
236
261
  t.runner = :xctool
237
-
262
+
238
263
  t.subtask(unit: 'Unit Tests') do |s|
239
264
  s.ios_versions = %w{7.0 7.1}
240
265
  end
241
-
266
+
242
267
  t.subtask :functional do |s|
243
268
  s.runner = :xcodebuild
244
269
  s.scheme = 'Functional Tests'
@@ -252,53 +277,53 @@ describe XCTasks::TestTask do
252
277
  end
253
278
  end
254
279
  end
255
-
280
+
256
281
  describe 'spec:unit' do
257
282
  subject { Rake.application['spec:unit'] }
258
-
283
+
259
284
  it "executes the appropriate commands" do
260
285
  subject.invoke
261
286
  @commands.should == [
262
- "killall \"iPhone Simulator\"",
263
- "/usr/local/bin/xctool -workspace LayerKit.xcworkspace -scheme 'Unit Tests' -sdk iphonesimulator7.0 clean build test",
264
- "killall \"iPhone Simulator\"",
287
+ "killall \"iPhone Simulator\"",
288
+ "/usr/local/bin/xctool -workspace LayerKit.xcworkspace -scheme 'Unit Tests' -sdk iphonesimulator7.0 clean build test",
289
+ "killall \"iPhone Simulator\"",
265
290
  "/usr/local/bin/xctool -workspace LayerKit.xcworkspace -scheme 'Unit Tests' -sdk iphonesimulator7.1 clean build test"
266
291
  ]
267
292
  end
268
293
  end
269
-
294
+
270
295
  describe 'spec:functional' do
271
296
  subject { Rake.application['spec:functional'] }
272
-
297
+
273
298
  it "executes the appropriate commands" do
274
299
  subject.invoke
275
300
  @commands.should == [
276
- "killall \"iPhone Simulator\"",
301
+ "killall \"iPhone Simulator\"",
277
302
  "/usr/bin/xcodebuild -workspace LayerKit.xcworkspace -scheme 'Functional Tests' -sdk iphonesimulator -destination platform='iOS Simulator',name='iPad Retina',OS='latest' -destination platform\\=iOS\\ Simulator,OS\\=7.1,name\\=iPhone\\ Retina\\ \\(4-inch\\) -destination platform='iOS',id='437750527b43cff55a46f42ae86dbf870c7591b1' clean build test"]
278
303
  end
279
304
  end
280
305
  end
281
-
306
+
282
307
  describe 'SDK Configuration' do
283
308
  let!(:task) do
284
309
  XCTasks::TestTask.new(:spec) do |t|
285
310
  t.workspace = 'LayerKit.xcworkspace'
286
311
  t.runner = :xctool
287
-
312
+
288
313
  t.subtask(unit: 'Unit Tests') do |s|
289
314
  s.sdk = :macosx
290
315
  end
291
316
  end
292
317
  end
293
-
318
+
294
319
  subject { Rake.application['spec:unit'] }
295
-
320
+
296
321
  it "executes the appropriate commands" do
297
322
  subject.invoke
298
323
  @commands.should == ["/usr/local/bin/xctool -workspace LayerKit.xcworkspace -scheme 'Unit Tests' -sdk macosx clean build test"]
299
324
  end
300
325
  end
301
-
326
+
302
327
  describe 'validations' do
303
328
  it "raises an exception when an invalid value is assigned to the sdk" do
304
329
  expect do
@@ -307,7 +332,7 @@ describe XCTasks::TestTask do
307
332
  end
308
333
  end.to raise_error(ArgumentError, "Can only assign sdk from a String or Symbol")
309
334
  end
310
-
335
+
311
336
  context "when an invalid runner is specified" do
312
337
  it "raises an exception" do
313
338
  expect do
@@ -317,7 +342,7 @@ describe XCTasks::TestTask do
317
342
  end.to raise_error(XCTasks::TestTask::ConfigurationError, "Must be :xcodebuild, :xctool or :xcpretty")
318
343
  end
319
344
  end
320
-
345
+
321
346
  context "when a workspace is not configured" do
322
347
  it "raises an exception" do
323
348
  expect do
@@ -327,59 +352,59 @@ describe XCTasks::TestTask do
327
352
  end.to raise_error(XCTasks::TestTask::ConfigurationError, "A workspace must be configured")
328
353
  end
329
354
  end
330
-
355
+
331
356
  context "when an SDK of macosx and ios versions is specified" do
332
357
  it "raises an exception" do
333
358
  expect do
334
359
  XCTasks::TestTask.new do |t|
335
360
  t.workspace = 'Workspace.workspace'
336
361
  t.sdk = :macosx
337
- t.ios_versions = %w{7.0}
362
+ t.ios_versions = %w{7.0}
338
363
  t.subtasks = {unit: 'MyWorkspaceTests'}
339
364
  end
340
365
  end.to raise_error(XCTasks::TestTask::ConfigurationError, "Cannot specify iOS versions with an SDK of :macosx")
341
366
  end
342
367
  end
343
368
  end
344
-
369
+
345
370
  describe XCTasks::TestTask::Destination do
346
371
  let(:destination) { XCTasks::TestTask::Destination.new }
347
-
372
+
348
373
  describe '#platform=' do
349
374
  it "allows assignment of :osx" do
350
375
  destination.platform = :osx
351
376
  expect(destination.platform).to eq('OS X')
352
377
  end
353
-
378
+
354
379
  it "allows assignment of 'OS X'" do
355
380
  destination.platform = 'OS X'
356
381
  expect(destination.platform).to eq('OS X')
357
382
  end
358
-
383
+
359
384
  it "allows assignment of :ios" do
360
385
  destination.platform = :ios
361
386
  expect(destination.platform).to eq('iOS')
362
387
  end
363
-
388
+
364
389
  it "allows assignment of 'iOS'" do
365
390
  destination.platform = 'iOS'
366
391
  expect(destination.platform).to eq('iOS')
367
392
  end
368
-
393
+
369
394
  it "allows assignment of :iossimulator" do
370
395
  destination.platform = :iossimulator
371
396
  expect(destination.platform).to eq('iOS Simulator')
372
397
  end
373
-
398
+
374
399
  it "allows assignment of 'iOS Simulator'" do
375
400
  destination.platform = 'iOS Simulator'
376
401
  expect(destination.platform).to eq('iOS Simulator')
377
402
  end
378
-
403
+
379
404
  it "disallows other values" do
380
405
  expect { destination.platform = 'sdadsa' }.to raise_error(ArgumentError)
381
406
  end
382
407
  end
383
-
408
+
384
409
  end
385
410
  end
data/xctasks.gemspec CHANGED
@@ -17,12 +17,14 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
-
20
+
21
+ spec.add_dependency "rake", ">= 10.0.0"
22
+ spec.add_dependency "nokogiri", "~> 1.6.2.1"
23
+
21
24
  spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
23
25
  spec.add_development_dependency "rspec", "~> 2.14.0"
24
26
  spec.add_development_dependency "simplecov", "~> 0.7.1"
25
- spec.add_development_dependency "debugger", "~> 1.6.2"
27
+ spec.add_development_dependency "byebug", "~> 3.1.2"
26
28
  spec.add_development_dependency "webmock", "~> 1.13.0"
27
29
  spec.add_development_dependency "excon", "~> 0.26.0"
28
30
  spec.add_development_dependency "tomdoc", "~> 0.2.5"
metadata CHANGED
@@ -1,43 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xctasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.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-06-11 00:00:00.000000000 Z
11
+ date: 2014-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 10.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 10.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - ~>
18
32
  - !ruby/object:Gem::Version
19
- version: '1.3'
20
- type: :development
33
+ version: 1.6.2.1
34
+ type: :runtime
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - ~>
25
39
  - !ruby/object:Gem::Version
26
- version: '1.3'
40
+ version: 1.6.2.1
27
41
  - !ruby/object:Gem::Dependency
28
- name: rake
42
+ name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - '>='
45
+ - - ~>
32
46
  - !ruby/object:Gem::Version
33
- version: '0'
47
+ version: '1.3'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - '>='
52
+ - - ~>
39
53
  - !ruby/object:Gem::Version
40
- version: '0'
54
+ version: '1.3'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -67,19 +81,19 @@ dependencies:
67
81
  - !ruby/object:Gem::Version
68
82
  version: 0.7.1
69
83
  - !ruby/object:Gem::Dependency
70
- name: debugger
84
+ name: byebug
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - ~>
74
88
  - !ruby/object:Gem::Version
75
- version: 1.6.2
89
+ version: 3.1.2
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - ~>
81
95
  - !ruby/object:Gem::Version
82
- version: 1.6.2
96
+ version: 3.1.2
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: webmock
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -140,6 +154,7 @@ files:
140
154
  - lib/xctasks.rb
141
155
  - lib/xctasks/test_task.rb
142
156
  - lib/xctasks/version.rb
157
+ - spec/Unit Tests.xcscheme
143
158
  - spec/spec_helper.rb
144
159
  - spec/test_task_spec.rb
145
160
  - xctasks.gemspec
@@ -168,5 +183,6 @@ signing_key:
168
183
  specification_version: 4
169
184
  summary: Provides a rich library of automation tasks for Xcode
170
185
  test_files:
186
+ - spec/Unit Tests.xcscheme
171
187
  - spec/spec_helper.rb
172
188
  - spec/test_task_spec.rb