avh4-rbiphonetest 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/History.txt +24 -0
  2. data/Manifest.txt +51 -0
  3. data/PostInstall.txt +21 -0
  4. data/README.rdoc +90 -0
  5. data/Rakefile +24 -0
  6. data/app_generators/rbiphonetest/USAGE +5 -0
  7. data/app_generators/rbiphonetest/rbiphonetest_generator.rb +79 -0
  8. data/app_generators/rbiphonetest/templates/Rakefile +55 -0
  9. data/app_generators/rbiphonetest/templates/dot_autotest +18 -0
  10. data/bin/iphoneruby +10 -0
  11. data/bin/rbiphonetest +18 -0
  12. data/lib/rbiphonetest.rb +6 -0
  13. data/lib/rbiphonetest/version.rb +9 -0
  14. data/rbiphonetest_generators/install_rspec/USAGE +5 -0
  15. data/rbiphonetest_generators/install_rspec/install_rspec_generator.rb +52 -0
  16. data/rbiphonetest_generators/install_rspec/templates/spec/spec_helper.rb +7 -0
  17. data/rbiphonetest_generators/install_rspec/templates/tasks/rspec.rake +9 -0
  18. data/rbiphonetest_generators/install_test_unit/USAGE +5 -0
  19. data/rbiphonetest_generators/install_test_unit/install_test_unit_generator.rb +53 -0
  20. data/rbiphonetest_generators/install_test_unit/templates/tasks/test_unit.rake +11 -0
  21. data/rbiphonetest_generators/install_test_unit/templates/test/test_helper.rb +8 -0
  22. data/rbiphonetest_generators/model/USAGE +5 -0
  23. data/rbiphonetest_generators/model/model_generator.rb +85 -0
  24. data/rbiphonetest_generators/model/templates/model.h +15 -0
  25. data/rbiphonetest_generators/model/templates/model.m +22 -0
  26. data/rbiphonetest_generators/model_rspec/model_rspec_generator.rb +51 -0
  27. data/rbiphonetest_generators/model_rspec/templates/spec.rb +9 -0
  28. data/rbiphonetest_generators/model_test_unit/model_test_unit_generator.rb +51 -0
  29. data/rbiphonetest_generators/model_test_unit/templates/test.rb +7 -0
  30. data/rbiphonetest_generators/story/USAGE +5 -0
  31. data/rbiphonetest_generators/story/story_generator.rb +55 -0
  32. data/rbiphonetest_generators/story/templates/steps.rb +8 -0
  33. data/rbiphonetest_generators/story/templates/story +13 -0
  34. data/rbiphonetest_generators/story/templates/story.rb +5 -0
  35. data/rbiphonetest_generators/story/templates/story_helper.rb +15 -0
  36. data/script/console +10 -0
  37. data/script/destroy +14 -0
  38. data/script/generate +14 -0
  39. data/script/txt2html +82 -0
  40. data/setup.rb +1585 -0
  41. data/test/test_generator_helper.rb +29 -0
  42. data/test/test_helper.rb +2 -0
  43. data/test/test_install_rspec_generator.rb +46 -0
  44. data/test/test_install_test_unit_generator.rb +46 -0
  45. data/test/test_model_generator.rb +70 -0
  46. data/test/test_rbiphonetest.rb +11 -0
  47. data/test/test_rbiphonetest_generator.rb +56 -0
  48. data/test/test_story_generator.rb +49 -0
  49. metadata +150 -0
@@ -0,0 +1,24 @@
1
+ == 0.4.0 2009-03-17 NOT RELEASED
2
+
3
+ * No more dependency issues between classes being tested: only one bundle created - all ObjC code being tested is compiled into one bundle
4
+ * Upgrade internals to use latest newgem (removed bunch of dev-only files)
5
+ * Behaviour of rbiphonetest covered by Cucumber scenarios
6
+
7
+ == 0.3.0 2008-07-05
8
+
9
+ * Support for test/unit AND rspec test frameworks (via install_test_unit and install_rspec generators)
10
+ * model generator: creates test/test_model.rb or spec/model_spec.rb as required
11
+ * story generator added for rspec developers
12
+ * app generator: adds selected test framework to script/generate
13
+
14
+ == 0.2.0 2008-07-03
15
+
16
+ * Renamed project from 'iphoneruby' to 'rbiphonetest'
17
+ * iphoneruby app: prints a deprecation message
18
+ * USE: "rbiphonetest ." to install test framework now
19
+
20
+ == 0.1.0 2008-06-28
21
+
22
+ * Initial release
23
+ * rbiphonetest cmd - adds test framework to your Xcode project
24
+ * script/generate model FooBar - creates Classes/FooBar.h+m and test/test_foo_bar.rb
@@ -0,0 +1,51 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ app_generators/rbiphonetest/USAGE
7
+ app_generators/rbiphonetest/rbiphonetest_generator.rb
8
+ app_generators/rbiphonetest/templates/Rakefile
9
+ app_generators/rbiphonetest/templates/dot_autotest
10
+ bin/iphoneruby
11
+ bin/rbiphonetest
12
+ features/development.feature
13
+ features/steps/common.rb
14
+ features/steps/env.rb
15
+ lib/rbiphonetest.rb
16
+ lib/rbiphonetest/version.rb
17
+ rbiphonetest_generators/install_rspec/USAGE
18
+ rbiphonetest_generators/install_rspec/install_rspec_generator.rb
19
+ rbiphonetest_generators/install_rspec/templates/spec/spec_helper.rb
20
+ rbiphonetest_generators/install_rspec/templates/tasks/rspec.rake
21
+ rbiphonetest_generators/install_test_unit/USAGE
22
+ rbiphonetest_generators/install_test_unit/install_test_unit_generator.rb
23
+ rbiphonetest_generators/install_test_unit/templates/tasks/test_unit.rake
24
+ rbiphonetest_generators/install_test_unit/templates/test/test_helper.rb
25
+ rbiphonetest_generators/model/USAGE
26
+ rbiphonetest_generators/model/model_generator.rb
27
+ rbiphonetest_generators/model/templates/model.h
28
+ rbiphonetest_generators/model/templates/model.m
29
+ rbiphonetest_generators/model_rspec/model_rspec_generator.rb
30
+ rbiphonetest_generators/model_rspec/templates/spec.rb
31
+ rbiphonetest_generators/model_test_unit/model_test_unit_generator.rb
32
+ rbiphonetest_generators/model_test_unit/templates/test.rb
33
+ rbiphonetest_generators/story/USAGE
34
+ rbiphonetest_generators/story/story_generator.rb
35
+ rbiphonetest_generators/story/templates/steps.rb
36
+ rbiphonetest_generators/story/templates/story
37
+ rbiphonetest_generators/story/templates/story.rb
38
+ rbiphonetest_generators/story/templates/story_helper.rb
39
+ script/console
40
+ script/destroy
41
+ script/generate
42
+ script/txt2html
43
+ setup.rb
44
+ test/test_generator_helper.rb
45
+ test/test_helper.rb
46
+ test/test_install_rspec_generator.rb
47
+ test/test_install_test_unit_generator.rb
48
+ test/test_model_generator.rb
49
+ test/test_rbiphonetest.rb
50
+ test/test_rbiphonetest_generator.rb
51
+ test/test_story_generator.rb
@@ -0,0 +1,21 @@
1
+
2
+ You can add Ruby-based unit tests to any iPhone/Xcode project by changing to the
3
+ project's folder in the terminal/console and running:
4
+
5
+ rbiphonetest .
6
+
7
+ This adds the test framework, a Rakefile, and an `autotest` config file.
8
+
9
+ You can now create testable Objective-C models/classes using the generator:
10
+
11
+ $ script/generate model WidgetMaker
12
+ create Classes/WidgetMaker.h
13
+ create Classes/WidgetMaker.m
14
+ create test/test_widget_maker.rb
15
+
16
+ To run tests you have several options:
17
+
18
+ 1. `rake` or `rake test`
19
+ 1. `autotest` (after installing the ZenTest gem)
20
+
21
+ Enjoy iPhone development with Ruby!
@@ -0,0 +1,90 @@
1
+ = rbiphonetest - Unit Test iPhone apps with Ruby
2
+
3
+ * http://rbiphonetest.rubyforge.org
4
+
5
+ == DESCRIPTION:
6
+
7
+ Want to write iPhone apps with unit tests? Want to write them in Ruby?
8
+
9
+ * Blog introduction: http://drnicwilliams.com/2008/07/04/unit-testing-iphone-apps-with-ruby-rbiphonetest/
10
+ * Video introduction: http://www.vimeo.com/1262916
11
+ * Google Group: http://groups.google.com/group/rbiphonetest
12
+ * Bugs/Features: http://drnic.lighthouseapp.com/projects/13763-rbiphonetest
13
+
14
+ == FEATURES/PROBLEMS:
15
+
16
+ * Installs a Ruby-based unit testing framework into an iPhone/Objective-C/Xcode project
17
+ * Provides generators to create Objective-C classes with associated Ruby tests
18
+ * Uses RubyCocoa to bridge between Ruby tests and Objective-C via Loadable Bundles
19
+
20
+ Known issues:
21
+
22
+ * Currently only test/unit tests created; rspec etc coming soon
23
+ * Currently only supports Foundation framework, since its common between OS X and iPhone
24
+ * The plan is to mock out all the UIKit.framework classes so they can exist in RubyCocoa land.
25
+ * MacRuby (instead of RubyCocoa) is not yet tested
26
+
27
+ == SYNOPSIS:
28
+
29
+ * Create a new iPhone project using Xcode templates
30
+ * Open the terminal
31
+ * Change to project folder
32
+ * `rbiphonetest .`
33
+
34
+ This adds the test framework, a Rakefile, and an `autotest` config file.
35
+
36
+ You can now create testable Objective-C models/classes using the generator:
37
+
38
+ $ script/generate model WidgetMaker
39
+ create Classes/WidgetMaker.h
40
+ create Classes/WidgetMaker.m
41
+ create test/test_widget_maker.rb
42
+
43
+ To run tests you have several options:
44
+
45
+ 1. `rake` or `rake test`
46
+ 1. `autotest` (after installing the ZenTest gem)
47
+
48
+ All options will re-build the Objective-C code (if necessary) before running the tests.
49
+
50
+ If using autotest, your tests will be re-run if the test files or the Objective-C files are modified.
51
+
52
+ == REQUIREMENTS:
53
+
54
+ * RubyCocoa (installed on OS X Leopard; latest version at http://rubycocoa.com)
55
+ * XCode 3.1 (containing the iPhone SDK)
56
+
57
+ == INSTALL:
58
+
59
+ sudo gem install rbiphonetest
60
+
61
+ From source:
62
+
63
+ git clone git://github.com/drnic/rbiphonetest.git
64
+ cd rbiphonetest
65
+ rake install_gem
66
+
67
+ == LICENSE:
68
+
69
+ (The MIT License)
70
+
71
+ Copyright (c) 2008-9 Dr Nic Williams
72
+
73
+ Permission is hereby granted, free of charge, to any person obtaining
74
+ a copy of this software and associated documentation files (the
75
+ 'Software'), to deal in the Software without restriction, including
76
+ without limitation the rights to use, copy, modify, merge, publish,
77
+ distribute, sublicense, and/or sell copies of the Software, and to
78
+ permit persons to whom the Software is furnished to do so, subject to
79
+ the following conditions:
80
+
81
+ The above copyright notice and this permission notice shall be
82
+ included in all copies or substantial portions of the Software.
83
+
84
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
85
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
86
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
87
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
88
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
89
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
90
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,24 @@
1
+ %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
2
+ require File.dirname(__FILE__) + '/lib/rbiphonetest'
3
+
4
+ # Generate all the Rake tasks
5
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
+ $hoe = Hoe.new('rbiphonetest', RbIphoneTest::VERSION) do |p|
7
+ p.developer('Dr Nic Williams', 'drnicwilliams@gmail.com')
8
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
9
+ p.post_install_message = 'PostInstall.txt'
10
+ p.extra_dev_deps = [
11
+ ['newgem', ">= #{::Newgem::VERSION}"]
12
+ ]
13
+
14
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
15
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
16
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
17
+ p.rsync_args = '-av --delete --ignore-errors'
18
+ end
19
+
20
+ require 'newgem/tasks' # load /tasks/*.rake
21
+ Dir['tasks/**/*.rake'].each { |t| load t }
22
+
23
+ # TODO - want other tests/tasks run by default? Add them to the list
24
+ task :default => [:features]
@@ -0,0 +1,5 @@
1
+ Description:
2
+
3
+
4
+ Usage:
5
+
@@ -0,0 +1,79 @@
1
+ class RbIphoneTestGenerator < RubiGen::Base
2
+
3
+ DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
4
+ Config::CONFIG['ruby_install_name'])
5
+
6
+ default_options :author => nil,
7
+ :test_framework => 'test_unit'
8
+
9
+ attr_reader :name, :module_name
10
+ attr_reader :test_framework
11
+
12
+ def initialize(runtime_args, runtime_options = {})
13
+ super
14
+ usage if args.empty?
15
+ @destination_root = File.expand_path(args.shift)
16
+ @name = base_name.gsub("-", "_")
17
+ @module_name = name.camelize
18
+ extract_options
19
+ end
20
+
21
+ def manifest
22
+ record do |m|
23
+ # Ensure appropriate folder(s) exists
24
+ m.directory ''
25
+ BASEDIRS.each { |path| m.directory path }
26
+
27
+ # Create stubs
28
+ m.template_copy_each ["Rakefile"]
29
+ m.file "dot_autotest", ".autotest"
30
+
31
+ # Selecting a test framework
32
+ case test_framework
33
+ when "test_unit"
34
+ m.dependency "install_test_unit", [name], :destination => destination_root, :collision => :force
35
+ when "rspec"
36
+ m.dependency "install_rspec", [name], :destination => destination_root, :collision => :force
37
+ end
38
+
39
+ m.dependency "install_rubigen_scripts", [destination_root, 'rbiphonetest', 'iphone', test_framework],
40
+ :shebang => options[:shebang], :collision => :force
41
+ end
42
+ end
43
+
44
+ protected
45
+ def banner
46
+ <<-EOS
47
+ Want to write iPhone unit tests? Want to write them in Ruby?
48
+ Run this generator in the root folder of your Xcode project for your iPhone app.
49
+
50
+ USAGE: #{spec.name} name
51
+ EOS
52
+ end
53
+
54
+ def add_options!(opts)
55
+ opts.separator ''
56
+ opts.separator 'Options:'
57
+ # For each option below, place the default
58
+ # at the top of the file next to "default_options"
59
+ opts.on("-s", "--test-with=TEST_FRAMEWORK", String,
60
+ "Select your preferred testing framework.",
61
+ "Options: test_unit (default), rspec.") { |x| options[:test_framework] = x }
62
+ opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
63
+ end
64
+
65
+ def extract_options
66
+ # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
67
+ # Templates can access these value via the attr_reader-generated methods, but not the
68
+ # raw instance variable value.
69
+ # @author = options[:author]
70
+ @test_framework = options[:test_framework] || "test_unit"
71
+ end
72
+
73
+ # Installation skeleton. Intermediate directories are automatically
74
+ # created so don't sweat their absence here.
75
+ BASEDIRS = %w(
76
+ Classes
77
+ tasks
78
+ )
79
+ end
@@ -0,0 +1,55 @@
1
+ require "rubygems"
2
+ require "rake"
3
+
4
+ bundle_name = '<%= module_name %>'
5
+ src_paths = %w[Classes] # any included projects, add folders here
6
+ src_files = FileList['Classes/**/*.m'] # any included projects, add files here
7
+ req_frameworks = %w[Foundation] # use only frameworks available to both Cocoa + iPhone SDKs
8
+ req_libraries = %w[] # e.g. add sqlite3 for libsqlite3 to be used by linking step
9
+
10
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
11
+
12
+ namespace :objc do
13
+ desc "Compiles all Objective-C bundles for testing"
14
+ task :compile
15
+ end
16
+
17
+ task :compile => "objc:compile"
18
+
19
+ # Converts ('-I', ['foo', 'bar'])
20
+ # Into: -Ifoo -Ibar
21
+ def make_options(flag, items)
22
+ items.map { |item| "#{flag}#{item}" }.join(" ")
23
+ end
24
+
25
+ src_files.each do |file|
26
+ FileUtils.mkdir_p "build"
27
+ base = file.gsub(/\.m$/,'')
28
+ dot_o = "build/#{File.basename base}.o"
29
+ file dot_o => ["#{base}.m", "#{base}.h"] do
30
+ sh "gcc -c #{base}.m -o #{dot_o} #{make_options '-I', src_paths}"
31
+ end
32
+ end
33
+
34
+ dot_o_files = src_files.map { |file| "build/" + File.basename(file).gsub(/\.m$/,'') + ".o" }
35
+
36
+ namespace :objc do
37
+ task :compile => "build/bundles/#{bundle_name}.bundle" do
38
+ if Dir.glob("**/#{bundle_name}.bundle").length == 0
39
+ STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
40
+ STDERR.puts "Bundle actually failed to build."
41
+ STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
42
+ exit(1)
43
+ end
44
+ end
45
+
46
+ file "build/bundles/#{bundle_name}.bundle" => dot_o_files do |t|
47
+ FileUtils.mkdir_p "build/bundles"
48
+ FileUtils.rm Dir["build/bundles/#{bundle_name}.bundle"]
49
+ sh "gcc -o build/bundles/#{bundle_name}.bundle #{dot_o_files.join(" ")} -bundle " +
50
+ "#{make_options '-framework ', req_frameworks} " +
51
+ "#{make_options '-l', req_libraries} " +
52
+ "#{make_options '-I', src_paths}"
53
+ end
54
+ end
55
+
@@ -0,0 +1,18 @@
1
+ class String
2
+ def underscore
3
+ gsub(/::/, '/').
4
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
5
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
6
+ downcase
7
+ end
8
+ end
9
+
10
+ Autotest.add_hook :initialize do |at|
11
+ at.add_mapping(/Classes\/(.*)\.[mh]/) do |_, m|
12
+ ["spec/#{m[1].underscore}_spec.rb", "test/test_#{m[1].underscore}.rb"]
13
+ end
14
+ end
15
+
16
+ Autotest.add_hook :run_command do |at|
17
+ system "rake compile"
18
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ puts <<-EOS
4
+ DEPRECATION: this project has been renamed to 'rbiphonetest'
5
+
6
+ Please use the new executable:
7
+
8
+ rbiphonetest .
9
+
10
+ EOS
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'rubigen'
5
+
6
+ if %w(-v --version).include? ARGV.first
7
+ require 'rbiphonetest/version'
8
+ puts "#{File.basename($0)} #{Iphoneruby::VERSION::STRING}"
9
+ exit(0)
10
+ end
11
+
12
+ require 'rubigen/scripts/generate'
13
+ RubiGen::Base.reset_sources
14
+ source = RubiGen::PathSource.new(:application, File.join(File.dirname(__FILE__), "../app_generators"))
15
+ RubiGen::Base.append_sources source
16
+ source = RubiGen::PathSource.new(:application, File.join(File.dirname(__FILE__), "../rbiphonetest_generators"))
17
+ RubiGen::Base.append_sources source
18
+ RubiGen::Scripts::Generate.new.run(ARGV, :generator => 'rbiphonetest')
@@ -0,0 +1,6 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module RbIphoneTest
5
+ VERSION = '0.4.0'
6
+ end
@@ -0,0 +1,9 @@
1
+ module RbIphoneTest
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 4
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ Description:
2
+
3
+
4
+ Usage:
5
+
@@ -0,0 +1,52 @@
1
+ class InstallRspecGenerator < RubiGen::Base
2
+
3
+ default_options :author => nil
4
+
5
+ attr_reader :name, :module_name
6
+
7
+ def initialize(runtime_args, runtime_options = {})
8
+ super
9
+ usage if args.empty?
10
+ @name = args.shift
11
+ @module_name = File.basename(destination_root).gsub("-", "_").camelize
12
+ extract_options
13
+ end
14
+
15
+ def manifest
16
+ record do |m|
17
+ # Ensure appropriate folder(s) exists
18
+ m.directory 'spec'
19
+ m.directory 'tasks'
20
+
21
+ m.template_copy_each ["spec/spec_helper.rb"]
22
+ m.file_copy_each ["tasks/rspec.rake"]
23
+ end
24
+ end
25
+
26
+ protected
27
+ def banner
28
+ <<-EOS
29
+ Creates a ...
30
+
31
+ USAGE: #{$0} #{spec.name} name
32
+ EOS
33
+ end
34
+
35
+ def add_options!(opts)
36
+ # opts.separator ''
37
+ # opts.separator 'Options:'
38
+ # For each option below, place the default
39
+ # at the top of the file next to "default_options"
40
+ # opts.on("-a", "--author=\"Your Name\"", String,
41
+ # "Some comment about this option",
42
+ # "Default: none") { |options[:author]| }
43
+ # opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
44
+ end
45
+
46
+ def extract_options
47
+ # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
48
+ # Templates can access these value via the attr_reader-generated methods, but not the
49
+ # raw instance variable value.
50
+ # @author = options[:author]
51
+ end
52
+ end