Permalink
Browse files

Support for test/unit AND rspec test frameworks (via install_test_uni…

…t and install_rspec generators)
  • Loading branch information...
1 parent a9aab9a commit 07008f1261852d267df2ee178812430bc0e56ae5 @drnic committed Jul 5, 2008
Showing with 329 additions and 51 deletions.
  1. +6 −0 History.txt
  2. +16 −8 Manifest.txt
  3. +16 −7 app_generators/rbiphonetest/rbiphonetest_generator.rb
  4. +0 −8 app_generators/rbiphonetest/templates/test/test_helper.rb
  5. +3 −2 bin/rbiphonetest
  6. +1 −1 lib/rbiphonetest/version.rb
  7. 0 rbiphonetest_generators/{rspec_model → install_rspec}/USAGE
  8. +51 −0 rbiphonetest_generators/install_rspec/install_rspec_generator.rb
  9. 0 rbiphonetest_generators/{rspec_model/templates → install_rspec/templates/spec}/spec_helper.rb
  10. 0 rbiphonetest_generators/{rspec_model → install_rspec}/templates/tasks/rspec.rake
  11. +5 −0 rbiphonetest_generators/install_test_unit/USAGE
  12. +52 −0 rbiphonetest_generators/install_test_unit/install_test_unit_generator.rb
  13. 0 rbiphonetest_generators/{model → install_test_unit}/templates/tasks/test_unit.rake
  14. +4 −0 rbiphonetest_generators/install_test_unit/templates/test/test_helper.rb
  15. +33 −5 rbiphonetest_generators/model/model_generator.rb
  16. +3 −6 ...honetest_generators/{rspec_model/rspec_model_generator.rb → model_rspec/model_rspec_generator.rb}
  17. 0 rbiphonetest_generators/{rspec_model → model_rspec}/templates/spec.rb
  18. +51 −0 rbiphonetest_generators/model_test_unit/model_test_unit_generator.rb
  19. 0 rbiphonetest_generators/{model → model_test_unit}/templates/test.rb
  20. +6 −6 test/{test_rspec_model_generator.rb → test_install_rspec_generator.rb}
  21. +46 −0 test/test_install_test_unit_generator.rb
  22. +23 −3 test/test_model_generator.rb
  23. +13 −5 test/test_rbiphonetest_generator.rb
View
6 History.txt
@@ -1,3 +1,9 @@
+== 0.3.0 2008-07-05 NOT RELEASED YET
+
+* Support for test/unit AND rspec test frameworks (via install_test_unit and install_rspec generators)
+* model generator: creates test/test_model.rb or spec/model_spec.rb as required
+* story generator added for rspec developers
+
== 0.2.0 2008-07-03
* Renamed project from 'iphoneruby' to 'rbiphonetest'
View
24 Manifest.txt
@@ -1,3 +1,4 @@
+.inputrc
@drnic
Owner
drnic added a line comment Jul 5, 2008

this is fixed in next commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
History.txt
License.txt
Manifest.txt
@@ -8,30 +9,34 @@ app_generators/rbiphonetest/USAGE
app_generators/rbiphonetest/rbiphonetest_generator.rb
app_generators/rbiphonetest/templates/Rakefile
app_generators/rbiphonetest/templates/dot_autotest
-app_generators/rbiphonetest/templates/test/test_helper.rb
bin/iphoneruby
bin/rbiphonetest
config/hoe.rb
config/requirements.rb
lib/rbiphonetest.rb
lib/rbiphonetest/version.rb
+rbiphonetest_generators/install_rspec/USAGE
+rbiphonetest_generators/install_rspec/install_rspec_generator.rb
+rbiphonetest_generators/install_rspec/templates/spec/spec_helper.rb
+rbiphonetest_generators/install_rspec/templates/tasks/rspec.rake
+rbiphonetest_generators/install_test_unit/USAGE
+rbiphonetest_generators/install_test_unit/install_test_unit_generator.rb
+rbiphonetest_generators/install_test_unit/templates/tasks/test_unit.rake
+rbiphonetest_generators/install_test_unit/templates/test/test_helper.rb
rbiphonetest_generators/model/USAGE
rbiphonetest_generators/model/model_generator.rb
rbiphonetest_generators/model/templates/model.h
rbiphonetest_generators/model/templates/model.m
-rbiphonetest_generators/model/templates/test.rb
-rbiphonetest_generators/rspec_model/USAGE
-rbiphonetest_generators/rspec_model/rspec_model_generator.rb
-rbiphonetest_generators/rspec_model/templates/spec.rb
-rbiphonetest_generators/rspec_model/templates/spec_helper.rb
-rbiphonetest_generators/rspec_model/templates/tasks/rspec.rake
+rbiphonetest_generators/model_rspec/model_rspec_generator.rb
+rbiphonetest_generators/model_rspec/templates/spec.rb
+rbiphonetest_generators/model_test_unit/model_test_unit_generator.rb
+rbiphonetest_generators/model_test_unit/templates/test.rb
rbiphonetest_generators/story/USAGE
rbiphonetest_generators/story/story_generator.rb
rbiphonetest_generators/story/templates/steps.rb
rbiphonetest_generators/story/templates/story
rbiphonetest_generators/story/templates/story.rb
rbiphonetest_generators/story/templates/story_helper.rb
-rbiphonetest_generators/model/templates/tasks/test_unit.rake
script/console
script/destroy
script/generate
@@ -42,6 +47,9 @@ tasks/environment.rake
tasks/website.rake
test/test_generator_helper.rb
test/test_helper.rb
+test/test_install_rspec_generator.rb
+test/test_install_test_unit_generator.rb
test/test_model_generator.rb
test/test_rbiphonetest.rb
test/test_rbiphonetest_generator.rb
+test/test_story_generator.rb
View
23 app_generators/rbiphonetest/rbiphonetest_generator.rb
@@ -3,9 +3,11 @@ class RbiphonetestGenerator < RubiGen::Base
DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
Config::CONFIG['ruby_install_name'])
- default_options :author => nil
+ default_options :author => nil,
+ :test_framework => 'test_unit'
attr_reader :name
+ attr_reader :test_framework
def initialize(runtime_args, runtime_options = {})
super
@@ -24,8 +26,15 @@ def manifest
# Create stubs
m.file_copy_each ["Rakefile"]
m.file "dot_autotest", ".autotest"
- m.file_copy_each ["test/test_helper.rb"]
-
+
+ # Selecting a test framework
+ case test_framework
+ when "test_unit"
+ m.dependency "install_test_unit", [name], :destination => destination_root, :collision => :force
+ when "rspec"
+ m.dependency "install_rspec", [name], :destination => destination_root, :collision => :force
+ end
+
m.dependency "install_rubigen_scripts", [destination_root, 'rbiphonetest'],
:shebang => options[:shebang], :collision => :force
end
@@ -46,9 +55,9 @@ def add_options!(opts)
opts.separator 'Options:'
# For each option below, place the default
# at the top of the file next to "default_options"
- # opts.on("-a", "--author=\"Your Name\"", String,
- # "Some comment about this option",
- # "Default: none") { |options[:author]| }
+ opts.on("-s", "--test-with=TEST_FRAMEWORK", String,
+ "Select your preferred testing framework.",
+ "Options: test_unit (default), rspec.") { |x| options[:test_framework] = x }
opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
end
@@ -57,13 +66,13 @@ def extract_options
# Templates can access these value via the attr_reader-generated methods, but not the
# raw instance variable value.
# @author = options[:author]
+ @test_framework = options[:test_framework] || "test_unit"
end
# Installation skeleton. Intermediate directories are automatically
# created so don't sweat their absence here.
BASEDIRS = %w(
Classes
- test
tasks
)
end
View
8 app_generators/rbiphonetest/templates/test/test_helper.rb
@@ -1,8 +0,0 @@
-require "test/unit"
-
-require "rubygems"
-require "Shoulda"
-
-require "osx/cocoa"
-
-$:.unshift File.dirname(__FILE__) + "/../build/bundles"
View
5 bin/rbiphonetest
@@ -10,8 +10,9 @@ if %w(-v --version).include? ARGV.first
end
require 'rubigen/scripts/generate'
-source = RubiGen::PathSource.new(:application,
- File.join(File.dirname(__FILE__), "../app_generators"))
RubiGen::Base.reset_sources
+source = RubiGen::PathSource.new(:application, File.join(File.dirname(__FILE__), "../app_generators"))
+RubiGen::Base.append_sources source
+source = RubiGen::PathSource.new(:application, File.join(File.dirname(__FILE__), "../rbiphonetest_generators"))
RubiGen::Base.append_sources source
RubiGen::Scripts::Generate.new.run(ARGV, :generator => 'rbiphonetest')
View
2 lib/rbiphonetest/version.rb
@@ -1,7 +1,7 @@
module RbIphoneTest
module VERSION #:nodoc:
MAJOR = 0
- MINOR = 2
+ MINOR = 3
TINY = 0
STRING = [MAJOR, MINOR, TINY].join('.')
View
0 rbiphonetest_generators/rspec_model/USAGE → rbiphonetest_generators/install_rspec/USAGE
File renamed without changes.
View
51 rbiphonetest_generators/install_rspec/install_rspec_generator.rb
@@ -0,0 +1,51 @@
+class InstallRspecGenerator < RubiGen::Base
+
+ default_options :author => nil
+
+ attr_reader :name
+
+ def initialize(runtime_args, runtime_options = {})
+ super
+ usage if args.empty?
+ @name = args.shift
+ extract_options
+ end
+
+ def manifest
+ record do |m|
+ # Ensure appropriate folder(s) exists
+ m.directory 'spec'
+ m.directory 'tasks'
+
+ m.file_copy_each ["spec/spec_helper.rb"]
+ m.file_copy_each ["tasks/rspec.rake"]
+ end
+ end
+
+ protected
+ def banner
+ <<-EOS
+Creates a ...
+
+USAGE: #{$0} #{spec.name} name
+EOS
+ end
+
+ def add_options!(opts)
+ # opts.separator ''
+ # opts.separator 'Options:'
+ # For each option below, place the default
+ # at the top of the file next to "default_options"
+ # opts.on("-a", "--author=\"Your Name\"", String,
+ # "Some comment about this option",
+ # "Default: none") { |options[:author]| }
+ # opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
+ end
+
+ def extract_options
+ # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
+ # Templates can access these value via the attr_reader-generated methods, but not the
+ # raw instance variable value.
+ # @author = options[:author]
+ end
+end
View
0 ...tors/rspec_model/templates/spec_helper.rb → ...stall_rspec/templates/spec/spec_helper.rb
File renamed without changes.
View
0 ...rs/rspec_model/templates/tasks/rspec.rake → .../install_rspec/templates/tasks/rspec.rake
File renamed without changes.
View
5 rbiphonetest_generators/install_test_unit/USAGE
@@ -0,0 +1,5 @@
+Description:
+
+
+Usage:
+
View
52 rbiphonetest_generators/install_test_unit/install_test_unit_generator.rb
@@ -0,0 +1,52 @@
+class InstallTestUnitGenerator < RubiGen::Base
+
+ default_options :author => nil
+
+ attr_reader :name
+
+ def initialize(runtime_args, runtime_options = {})
+ super
+ usage if args.empty?
+ @name = args.shift
+ extract_options
+ end
+
+ def manifest
+ record do |m|
+ # Ensure appropriate folder(s) exists
+ m.directory 'test'
+ m.directory 'tasks'
+
+ m.file_copy_each ["test/test_helper.rb"]
+ m.file_copy_each ["tasks/test_unit.rake"]
+
+ end
+ end
+
+ protected
+ def banner
+ <<-EOS
+Creates a ...
+
+USAGE: #{$0} #{spec.name} name
+EOS
+ end
+
+ def add_options!(opts)
+ # opts.separator ''
+ # opts.separator 'Options:'
+ # For each option below, place the default
+ # at the top of the file next to "default_options"
+ # opts.on("-a", "--author=\"Your Name\"", String,
+ # "Some comment about this option",
+ # "Default: none") { |options[:author]| }
+ # opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
+ end
+
+ def extract_options
+ # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
+ # Templates can access these value via the attr_reader-generated methods, but not the
+ # raw instance variable value.
+ # @author = options[:author]
+ end
+end
View
0 ...tors/model/templates/tasks/test_unit.rake → ..._test_unit/templates/tasks/test_unit.rake
File renamed without changes.
View
4 rbiphonetest_generators/install_test_unit/templates/test/test_helper.rb
@@ -0,0 +1,4 @@
+require "test/unit"
+require "osx/cocoa"
+
+$:.unshift File.dirname(__FILE__) + "/../build/bundles"
View
38 rbiphonetest_generators/model/model_generator.rb
@@ -3,35 +3,43 @@ class ModelGenerator < RubiGen::Base
default_options :author => nil
attr_reader :name, :class_name
+ attr_reader :installed_frameworks
def initialize(runtime_args, runtime_options = {})
super
usage if args.empty?
@name = args.shift.underscore
@class_name = @name.camelcase
extract_options
+ extract_test_frameworks
end
def manifest
record do |m|
# Ensure appropriate folder(s) exists
m.directory 'Classes'
- m.directory 'test'
- m.directory 'tasks'
# Create stubs
m.template "model.h", "Classes/#{class_name}.h"
m.template "model.m", "Classes/#{class_name}.m"
- m.template "test.rb", "test/test_#{name}.rb"
- m.file_copy_each ["tasks/test_unit.rake"]
+ # It is possible for 2+ test frameworks to be installed.
+ # Current behaviour is to generate test stubs for all of them
+ # and let the developer delete files they don't want
+ if installed_frameworks.include? "test_unit"
+ m.dependency "model_test_unit", [name], :destination => destination_root, :collision => :force
+ end
+ if installed_frameworks.include? "rspec"
+ m.dependency "model_rspec", [name], :destination => destination_root, :collision => :force
+ end
end
end
protected
def banner
<<-EOS
-Creates a ...
+Creates an NSObject model (header and implementation files)
+plus a Ruby test file (either test/unit or rspec).
USAGE: #{$0} #{spec.name} name
EOS
@@ -54,4 +62,24 @@ def extract_options
# raw instance variable value.
# @author = options[:author]
end
+
+ # Attempts to determine which test framework is being used
+ # Else prompts user
+ def extract_test_frameworks
+ @installed_frameworks = []
+ @installed_frameworks << "test_unit" if Dir[File.join(destination_root, "test")].length > 0
+ @installed_frameworks << "rspec" if Dir[File.join(destination_root, "spec")].length > 0
+
+ if @installed_frameworks.length == 0
+ # no test-related files created
+ puts <<-EOS
+WARNING: you do not have a test-framework installed.
+Run either:
+ script/generate install_test_unit
+ script/generate install_rspec
+
+and then rerun this generator.
+ EOS
+ end
+ end
end
View
9 ...tors/rspec_model/rspec_model_generator.rb → ...tors/model_rspec/model_rspec_generator.rb
@@ -1,4 +1,4 @@
-class RspecModelGenerator < RubiGen::Base
+class ModelRspecGenerator < RubiGen::Base
default_options :author => nil
@@ -16,19 +16,16 @@ def manifest
record do |m|
# Ensure appropriate folder(s) exists
m.directory 'spec'
- m.directory 'tasks'
- # Create stubs
- m.file "spec_helper.rb", "spec/spec_helper.rb"
m.template "spec.rb", "spec/#{name}_spec.rb"
- m.file_copy_each ["tasks/rspec.rake"]
end
end
protected
def banner
<<-EOS
-Creates a ...
+Creates an RSpec-based spec file for a model.
+NOTE: this generator is typically called via the 'model' generator.
USAGE: #{$0} #{spec.name} name
EOS
View
0 ..._generators/rspec_model/templates/spec.rb → ..._generators/model_rspec/templates/spec.rb
File renamed without changes.
View
51 rbiphonetest_generators/model_test_unit/model_test_unit_generator.rb
@@ -0,0 +1,51 @@
+class ModelTestUnitGenerator < RubiGen::Base
+
+ default_options :author => nil
+
+ attr_reader :name, :class_name
+
+ def initialize(runtime_args, runtime_options = {})
+ super
+ usage if args.empty?
+ @name = args.shift.underscore
+ @class_name = @name.camelcase
+ extract_options
+ end
+
+ def manifest
+ record do |m|
+ # Ensure appropriate folder(s) exists
+ m.directory 'test'
+
+ m.template "test.rb", "test/test_#{name}.rb"
+ end
+ end
+
+ protected
+ def banner
+ <<-EOS
+Creates an Test/Unit-based test file for a model.
+NOTE: this generator is typically called via the 'model' generator.
+
+USAGE: #{$0} #{spec.name} name
+EOS
+ end
+
+ def add_options!(opts)
+ # opts.separator ''
+ # opts.separator 'Options:'
+ # For each option below, place the default
+ # at the top of the file next to "default_options"
+ # opts.on("-a", "--author=\"Your Name\"", String,
+ # "Some comment about this option",
+ # "Default: none") { |options[:author]| }
+ # opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
+ end
+
+ def extract_options
+ # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
+ # Templates can access these value via the attr_reader-generated methods, but not the
+ # raw instance variable value.
+ # @author = options[:author]
+ end
+end
View
0 ...netest_generators/model/templates/test.rb → ...erators/model_test_unit/templates/test.rb
File renamed without changes.
View
12 test/test_rspec_model_generator.rb → test/test_install_rspec_generator.rb
@@ -1,7 +1,7 @@
require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
-class TestRspecModelGenerator < Test::Unit::TestCase
+class TestInstallRspecGenerator < Test::Unit::TestCase
include RubiGen::GeneratorTestHelper
def setup
@@ -27,11 +27,11 @@ def teardown
# bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
def test_generator_without_options
- name = "model"
- run_generator("rspec_model", [name], sources)
- assert_generated_file "spec/spec_helper.rb"
- assert_generated_file "spec/#{name}_spec.rb"
- assert_generated_file "tasks/rspec.rake"
+ name = "myapp"
+ run_generator('install_rspec', [name], sources)
+ assert_directory_exists "spec"
+ assert_generated_file "spec/spec_helper.rb"
+ assert_generated_file "tasks/rspec.rake"
end
private
View
46 test/test_install_test_unit_generator.rb
@@ -0,0 +1,46 @@
+require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
+
+
+class TestInstallTestUnitGenerator < Test::Unit::TestCase
+ include RubiGen::GeneratorTestHelper
+
+ def setup
+ bare_setup
+ end
+
+ def teardown
+ bare_teardown
+ end
+
+ # Some generator-related assertions:
+ # assert_generated_file(name, &block) # block passed the file contents
+ # assert_directory_exists(name)
+ # assert_generated_class(name, &block)
+ # assert_generated_module(name, &block)
+ # assert_generated_test_for(name, &block)
+ # The assert_generated_(class|module|test_for) &block is passed the body of the class/module within the file
+ # assert_has_method(body, *methods) # check that the body has a list of methods (methods with parentheses not supported yet)
+ #
+ # Other helper methods are:
+ # app_root_files - put this in teardown to show files generated by the test method (e.g. p app_root_files)
+ # bare_setup - place this in setup method to create the APP_ROOT folder for each test
+ # bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
+
+ def test_generator_without_options
+ name = "myapp"
+ run_generator('install_test_unit', [name], sources)
+ assert_directory_exists "test"
+ assert_generated_file "test/test_helper.rb"
+ assert_generated_file "tasks/test_unit.rake"
+ end
+
+ private
+ def sources
+ [RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", generator_path))
+ ]
+ end
+
+ def generator_path
+ "rbiphonetest_generators"
+ end
+end
View
26 test/test_model_generator.rb
@@ -26,16 +26,36 @@ def teardown
# bare_setup - place this in setup method to create the APP_ROOT folder for each test
# bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
- def test_generator_without_options
+ def test_generator_for_test_unit
name = "my_model"
+ FileUtils.mkdir_p File.join(APP_ROOT, "test")
run_generator('model', [name], sources)
assert_directory_exists "Classes"
assert_directory_exists "test"
- assert_directory_exists "tasks"
assert_generated_file "Classes/MyModel.h"
assert_generated_file "Classes/MyModel.m"
assert_generated_file "test/test_my_model.rb"
- assert_generated_file "tasks/test_unit.rake"
+ end
+
+ def test_generator_for_rspec
+ name = "my_model"
+ FileUtils.mkdir_p File.join(APP_ROOT, "spec")
+ run_generator("model", [name], sources)
+ assert_directory_exists "Classes"
+ assert_directory_exists "spec"
+ assert_generated_file "Classes/MyModel.h"
+ assert_generated_file "Classes/MyModel.m"
+ assert_generated_file "spec/my_model_spec.rb"
+ end
+
+ def test_generator_without_test_framework_installed
+ name = "my_model"
+ run_generator("model", [name], sources)
+ assert_directory_exists "Classes"
+ assert_generated_file "Classes/MyModel.h"
+ assert_generated_file "Classes/MyModel.m"
+ # and nothing else is created
+ assert_equal(["./test/tmp/myproject/Classes"], Dir[File.join(APP_ROOT, '*')])
end
private
View
18 test/test_rbiphonetest_generator.rb
@@ -36,13 +36,21 @@ def test_generator_without_options
assert_generated_file "script/generate"
end
+ def test_generator_with_rspec
+ run_generator('rbiphonetest', [APP_ROOT], sources, {:test_framework => 'rspec'})
+ assert_directory_exists "Classes"
+ assert_directory_exists "test"
+ assert_directory_exists "tasks"
+ assert_generated_file ".autotest"
+ assert_generated_file "Rakefile"
+ assert_generated_file "spec/spec_helper.rb"
+ assert_generated_file "script/generate"
+ end
+
private
def sources
- [RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", generator_path))
+ [RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", "app_generators")),
+ RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", "rbiphonetest_generators"))
]
end
-
- def generator_path
- "app_generators"
- end
end

1 comment on commit 07008f1

@drnic
Owner

test

Please sign in to comment.