ghunit 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f8638f90dde2cbeef02f93482452a754bd4c5680
4
+ data.tar.gz: d966cbfe9b37f23cf3c3e7cddba49cd64036bc06
5
+ SHA512:
6
+ metadata.gz: af75e8afaa8d464e198d47badf975fa7ceb52b09cbe0343fb5bc7fee87ba6dedfe6d7aaba0280e5bef392be89b2b01d3a1ea3ad222faf19d11b33814acff65aa
7
+ data.tar.gz: bcc2c167b724589f66a7a88e862ecab7f58df9d383a07c43fdd3e83a1bc2129bf652255067ae9317e1963dfb6104d5c3ce35e9ec6a85ec9cb41ee6b608069aff
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'slop'
4
+ require 'ghunit'
5
+ require 'colorize'
6
+
7
+ opts = Slop.parse do
8
+ banner "Usage: ghunit [options]"
9
+
10
+ on :n, :name=, "Project name"
11
+ on :p, :path=, "Project path, defaults to <Project Name>.xcodeproj", argument: :optional
12
+ on :t, :test_target=, "Test target name, defaults to Tests", argument: :optional
13
+
14
+ end
15
+
16
+ if !opts[:name]
17
+ puts " "
18
+ puts "Need to specify project name.".red
19
+ puts " "
20
+ puts opts.to_s
21
+ puts " "
22
+ exit 1
23
+ end
24
+
25
+ target_name = opts[:name]
26
+ project_path = opts[:path] || "#{target_name}.xcodeproj"
27
+ test_target_name = opts[:test_target] || "Tests"
28
+
29
+ project = GHUnit::Project.open(project_path, target_name, test_target_name)
30
+ if project
31
+ puts " "
32
+ puts " "
33
+ project.create_test_target
34
+ end
35
+
36
+
@@ -0,0 +1,4 @@
1
+
2
+ module GHUnit; end
3
+
4
+ require 'ghunit/project'
@@ -0,0 +1,204 @@
1
+ require 'xcodeproj'
2
+ require 'xcodeproj/ext'
3
+ require 'fileutils'
4
+ require 'logger'
5
+ require 'colorize'
6
+
7
+ class GHUnit::Project
8
+
9
+ attr_reader :project_path, :target_name, :test_target_name, :logger
10
+
11
+ attr_reader :project, :main_target
12
+
13
+ def initialize(project_path, target_name, test_target_name, logger=nil)
14
+ @target_name = target_name
15
+ @project_path = project_path
16
+ @test_target_name = test_target_name
17
+ @logger ||= begin
18
+ logger = Logger.new(STDOUT)
19
+ logger.formatter = proc do |severity, datetime, progname, msg|
20
+ case severity
21
+ when "ERROR"
22
+ "#{msg}\n".red
23
+ when "DEBUG"
24
+ "#{msg}\n".green
25
+ else
26
+ "#{msg}\n"
27
+ end
28
+ end
29
+ logger
30
+ end
31
+ end
32
+
33
+ def open
34
+ if !File.exists?(project_path)
35
+ logger.error "Can't find project path at #{project_path}"
36
+ return false
37
+ end
38
+
39
+ @project = Xcodeproj::Project.open(project_path)
40
+
41
+ # Find the main target for the test dependency
42
+ @main_target = project.targets.select { |t| t.name == target_name }.first
43
+ if !@main_target
44
+ logger.error "No target with name #{target_name}"
45
+ return false
46
+ end
47
+
48
+ true
49
+ end
50
+
51
+ class << self
52
+ def open(project_path, target_name, test_target_name, logger=nil)
53
+ project = GHUnit::Project.new(project_path, target_name, test_target_name, logger)
54
+ if project.open
55
+ project
56
+ else
57
+ nil
58
+ end
59
+ end
60
+ end
61
+
62
+ def find_test_target
63
+ project.targets.select { |t| t.name == test_target_name }.first
64
+ end
65
+
66
+ # Create the test target and setup everything
67
+ #
68
+ def create_test_target
69
+ Dir.chdir(File.dirname(project_path))
70
+ FileUtils.mkdir_p(test_target_name)
71
+
72
+ # Write the Tests-Info.plist
73
+ test_info = {
74
+ "CFBundleDisplayName" => "${PRODUCT_NAME}",
75
+ "CFBundleExecutable" => "${EXECUTABLE_NAME}",
76
+ "CFBundleIdentifier" => "tests.${PRODUCT_NAME:rfc1034identifier}",
77
+ "CFBundleInfoDictionaryVersion" => "6.0",
78
+ "CFBundleName" => "${PRODUCT_NAME}",
79
+ "CFBundlePackageType" => "APPL",
80
+ "CFBundleShortVersionString" => "1.0",
81
+ "CFBundleVersion" => "1.0",
82
+ "LSRequiresIPhoneOS" => true,
83
+ "UISupportedInterfaceOrientations" => ["UIInterfaceOrientationPortrait"]
84
+ }
85
+ test_info_path = File.join(test_target_name, "#{test_target_name}-Info.plist")
86
+ if !File.exists?(test_info_path)
87
+ logger.debug "Creating: #{test_info_path}"
88
+ Xcodeproj.write_plist(test_info, test_info_path)
89
+ else
90
+ logger.debug "#{test_info_path} already exists, skipping..."
91
+ end
92
+
93
+ test_target = find_test_target
94
+ if !test_target
95
+
96
+ # Create the test target
97
+ logger.debug "Creating target: #{test_target_name}"
98
+ test_target = project.new_target(:application, test_target_name, :ios, "7.0")
99
+ test_target.add_dependency(main_target)
100
+
101
+ create_test_file("main.m", template("main.m"), true)
102
+ create_test("MyTest")
103
+
104
+ else
105
+ logger.debug "Test target already exists, skipping..."
106
+ end
107
+
108
+ # Use same resources build phase as main target
109
+ # Have to compare with class name because of funky const loading in xcodeproj gem
110
+ resources_build_phase = main_target.build_phases.select { |p|
111
+ p.class.to_s == "Xcodeproj::Project::Object::PBXResourcesBuildPhase" }.first
112
+ test_target.build_phases << resources_build_phase if resources_build_phase
113
+
114
+ # Get main target prefix header
115
+ prefix_header = main_target.build_settings("Debug")["GCC_PREFIX_HEADER"]
116
+
117
+ # Clear default OTHER_LDFLAGS (otherwise CocoaPods gives a warning)
118
+ test_target.build_configurations.each do |c|
119
+ c.build_settings.delete("OTHER_LDFLAGS")
120
+ c.build_settings["INFOPLIST_FILE"] = test_info_path
121
+ c.build_settings["GCC_PREFIX_HEADER"] = prefix_header if prefix_header
122
+ end
123
+
124
+ # Create test scheme if it doesn't exist
125
+ logger.debug "Checking for Test scheme..."
126
+ schemes = Xcodeproj::Project.schemes(project_path)
127
+ test_scheme = schemes.select { |s| s == test_target_name }.first
128
+ if !test_scheme
129
+ logger.debug "Test scheme not found, creating..."
130
+ scheme = Xcodeproj::XCScheme.new
131
+ scheme.set_launch_target(test_target)
132
+ scheme.save_as(project_path, test_target_name)
133
+ else
134
+ logger.debug "Test scheme already exists, skipping..."
135
+ end
136
+
137
+ logger.debug "Saving project..."
138
+ project.save
139
+
140
+ check_pod
141
+ end
142
+
143
+ def template(name)
144
+ template_path = File.join(File.dirname(__FILE__), "templates", name)
145
+ File.read(template_path)
146
+ end
147
+
148
+ # Create a file with content and add to the test target
149
+ #
150
+ def create_test_file(file_name, content, force=false)
151
+ # Create main.m for test target
152
+ path = File.join(test_target_name, file_name)
153
+
154
+ if !force && File.exists?(path)
155
+ logger.info "Test file already exists, skipping"
156
+ end
157
+
158
+ logger.debug "Creating: #{path}"
159
+ File.open(path, "w") { |f| f.write(content) }
160
+
161
+ add_test_file(path)
162
+ path
163
+ end
164
+
165
+ # Add a file to the test target
166
+ #
167
+ def add_test_file(path)
168
+ test_target = find_test_target
169
+ if !test_target
170
+ logger.error "No test target to add to"
171
+ return false
172
+ end
173
+
174
+ tests_group = project.groups.select { |g| g.name == test_target_name }.first
175
+ tests_group ||= project.new_group(test_target_name)
176
+
177
+ test_file = tests_group.find_file_by_path(path)
178
+ if !test_file
179
+ test_file = tests_group.new_file(path)
180
+ end
181
+ test_target.add_file_references([test_file])
182
+ true
183
+ end
184
+
185
+ def create_test(name)
186
+ name = "#{name}.m" unless name.end_with?(".m")
187
+ path = create_test_file(name, template("Test.m"))
188
+ logger.debug "Created test: #{path}"
189
+ end
190
+
191
+ # Check the Podfile or just display some Podfile help
192
+ #
193
+ def check_pod
194
+ logger.info <<-EOS
195
+
196
+ Add the following to your Podfile and run pod install.
197
+
198
+ #{template("Podfile")}
199
+
200
+ Make sure to open the .xcworkspace.
201
+
202
+ EOS
203
+ end
204
+ end
@@ -0,0 +1,3 @@
1
+ target :Tests do
2
+ pod 'GHUnit'
3
+ end
@@ -0,0 +1,12 @@
1
+ #import <GHUnit/GHUnit.h>
2
+
3
+ @interface MyTest : GHTestCase
4
+ @end
5
+
6
+ @implementation MyTest
7
+
8
+ - (void)test {
9
+
10
+ }
11
+
12
+ @end
@@ -0,0 +1,8 @@
1
+ // This file auto-generated by ghunit gem
2
+ #import <UIKit/UIKit.h>
3
+
4
+ int main(int argc, char *argv[]) {
5
+ @autoreleasepool {
6
+ return UIApplicationMain(argc, argv, nil, @"GHUnitIOSAppDelegate");
7
+ }
8
+ }
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ghunit
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Gabriel Handford
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: xcodeproj
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: slop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: colorize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Utilities for GHUnit iOS/MacOSX test framework.
56
+ email: gabrielh@gmail.com
57
+ executables:
58
+ - ghunit
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/ghunit.rb
63
+ - lib/ghunit/project.rb
64
+ - lib/ghunit/templates/Podfile
65
+ - lib/ghunit/templates/Test.m
66
+ - lib/ghunit/templates/main.m
67
+ - bin/ghunit
68
+ homepage: https://github.com/gh-unit/gh-unit
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.1.10
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: GHUnit
92
+ test_files: []