rxcode 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,132 @@
1
1
  # rxcode
2
2
 
3
- RXCode is a ruby interface to XCode, useful for writing scripts to automate activities within an XCode project.
3
+ RXCode allows you to use Ruby to interact with your XCode projects and test your Objective-C code using MacRuby and
4
+ RSpec 2.
5
+
6
+ ## Getting Started
7
+
8
+ RXCode is just a 'gem install' away:
9
+
10
+ $ gem install bundler
11
+ $ gem install rxcode
12
+ $ cd MyProjectRoot # The directory containing your MyProject.xcodeproj or MyProjects.xcworkspace
13
+ $ rxcode init
14
+ $ bundle install # optional, though recommended
15
+
16
+ This will bootstrap your XCode project with support for writing utility scripts (a.k.a. 'tasks') with Rake, testing your
17
+ code using MacRuby & RSpec, and managing Ruby library dependencies with Bundler.
18
+
19
+ To see what tasks RXCode provides by default, try the following command:
20
+
21
+ $ rake -T
22
+
23
+ ## Testing Objective-C Code
24
+
25
+ RXCode brings the ease of BDD-style testing to Objective-C, allowing you to write tests for your Objective-C classes
26
+ using MacRuby and RSpec 2. While writing specs in MacRuby and RSpec provides a significant productivity boost, you will
27
+ want to review the following pros and cons of this approach:
28
+
29
+ **Pros**
30
+
31
+ * Quickly write BDD-style specs using RSpec's clear and concise DSL.
32
+
33
+ * Run just a subset of your entire suite easily using the `rspec` command, or from within TextMate.
34
+
35
+ * Run specs from the command-line using a provided Rake task, or with the `rspec` command.
36
+
37
+ **Cons**
38
+
39
+ * There is no way to run the tests under iOS, let alone test against specific iOS SDKs.
40
+
41
+ * MacRuby and RSpec must run in a garbage-collected environment -- memory leaks will not show up in tests.
42
+
43
+ * You cannot use XCode's debugger when running your tests.
44
+
45
+ * MacRuby provides a very convenient syntax for calling Objective-C code from Ruby, but handling C-level constructs
46
+ can be cumbersome.
47
+
48
+ Some of these may be addressed in future releases, or by other tools.
49
+
50
+ ### Running Specs
51
+
52
+ Running your specs is easy from the command line:
53
+
54
+ $ macrake
55
+
56
+ And that's it. By default all your specs will be run. You should try this soon after you initialize your project to make
57
+ sure MacRuby and RSpec are working before you write your specs.
58
+
59
+ If you want to run specific specs, or customize the run at all, you should use the `rspec` command provided by RSpec:
60
+
61
+ $ rspec --format html path/to/file_spec.rb
62
+
63
+ You can also run the specs with little or no work from any editor or IDE that supports RSpec, such as TextMate. The
64
+ RSpec TextMate bundle works great, and provides a way to run focused tests quickly.
65
+
66
+ ### Configuring Your Project to Allow Testing with RSpec
67
+
68
+ Now that you can run specs, you'd like to move on and actually write specs for your own code. In order to test your code
69
+ using MacRuby+RSpec, the code you want to test must be added to an Objective-C framework that MacRuby can load
70
+ dynamically. If you are writing an app for iPhone or iPad, this means you can't test any iOS-specific behavior.
71
+
72
+ In practice though, there's often a lot of model-related code in iOS projects that can be extracted and tested
73
+ independently within MacRuby. This also enforces a clean separation between model and view code, as well as ensuring
74
+ that this code is cross-platform.
75
+
76
+ 1. Create a 'Cocoa Framework' target and add whatever code you'd like to test to it. Make sure header files are public
77
+ or private, so they will be included in the framework and a Bridge Support file can be created (see #3 below).
78
+
79
+ 2. Update the framework target's build settings so that garbage collection is supported.
80
+
81
+ 3. Append a 'Run Script' build phase to the target, with the following script:
82
+
83
+ rake rxcode:generate_bridgesupport_file
84
+
85
+ This rake task will generate a BridgeSupport file from the framework, which MacRuby uses to understand method
86
+ signatures and return values. Without this step, any method that returns a BOOL, for example, would be seen by
87
+ MacRuby as a plain integer.
88
+
89
+ 4. Build the framework target, and ensure that no build errors occur.
90
+
91
+ 5. Open the spec/spec_helper.rb file and require the framework like so:
92
+
93
+ RXCode.framework('YourFrameworkName')
94
+
95
+ This will cause MacRuby to load the framework and make it available to your specs. The `spec_helper.rb` contains
96
+ inline comments describing in detail how to load different types of frameworks.
97
+
98
+ 6. Run the specs again, ensuring that your framework is loaded and RSpec completes without error.
99
+
100
+ ### Writing Specs
101
+
102
+ Now that you're able to load your Objective-C framework into MacRuby and run RSpec, it's time to write some specs.
103
+ RXCode's rake tasks will automatically discover any specs you place in a location matching this file glob:
104
+ `./**/Specs/**/*_spec.rb`. Since XCode 4 creates a separate directory for each target, the expected project layout looks
105
+ like this:
106
+
107
+ > MyProject
108
+ > MyFramework
109
+ - Info.plist
110
+ - MyFrameworkClass.h
111
+ - MyFrameworkClass.m
112
+ > Specs
113
+ - MyFrameworkClass_spec.rb
114
+ - MyProject.xcodeproj
115
+ > spec
116
+ - spec_helper.rb
117
+ > support
118
+
119
+ ## Ruby Versions & Bundler
120
+
121
+ RXCode has been designed to run under Ruby 1.8.7, 1.9.2, as well as MacRuby. This allows you to write Rake tasks that
122
+ can be integrated into a Run Script build phase in XCode, as well as a scheme's pre- and post- actions. However, only
123
+ MacRuby is capable of testing your Objective-C code.
124
+
125
+ Because you will be running RXCode under multiple rubies, using Bundler can really help manage installing all required
126
+ gems.
127
+
128
+ **NOTE**: Bundler versions prior to 1.0.15 had an issue that caused the `exec` and `open` commands fail under MacRuby.
129
+ Make sure that you have the latest bundler installed.
4
130
 
5
131
  ## Copyright
6
132
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
@@ -1,20 +1,28 @@
1
- require 'rspec/core/rake_task'
2
1
  require 'rxcode/spec/rake_ext'
3
2
 
4
- module RXCode
5
- module Spec
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+ rescue LoadError => e
6
+ end
7
+
8
+ if defined?(::RSpec::Core::RakeTask)
9
+
10
+ module RXCode
11
+ module Spec
6
12
 
7
- class RakeTask < ::RSpec::Core::RakeTask
13
+ class RakeTask < ::RSpec::Core::RakeTask
8
14
 
9
- def initialize(*args)
10
- super do |t|
11
- t.pattern = "./**/Specs/**/*_spec.rb"
15
+ def initialize(*args)
16
+ super do |t|
17
+ t.pattern = "./**/Specs/**/*_spec.rb"
12
18
 
13
- yield t if block_given?
19
+ yield t if block_given?
20
+ end
14
21
  end
22
+
15
23
  end
16
24
 
17
25
  end
26
+ end
18
27
 
19
- end
20
28
  end
@@ -1,3 +1,24 @@
1
1
  require 'rxcode/spec/rake_task'
2
2
 
3
- RXCode::Spec::RakeTask.new("rxcode:spec")
3
+ desc %{Run specs using MacRuby and RSpec}
4
+ if defined?(MACRUBY_VERSION)
5
+
6
+ if defined?(RXCode::Spec::RakeTask)
7
+
8
+ RXCode::Spec::RakeTask.new("rxcode:spec")
9
+
10
+ else
11
+
12
+ task 'rxcode:spec' do
13
+ raise "RSpec could not be found. Please install it to run specs"
14
+ end
15
+
16
+ end
17
+
18
+ else
19
+
20
+ task 'rxcode:spec' do
21
+ raise "Testing with RSpec requires MacRuby."
22
+ end
23
+
24
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rxcode
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.5
5
+ version: 0.0.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Christian Niles
@@ -163,7 +163,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
- hash: -765993797625968619
166
+ hash: 1093595179750362956
167
167
  segments:
168
168
  - 0
169
169
  version: "0"