Permalink
Browse files

`script/generate component_generator story rbiphonetest`

  • Loading branch information...
1 parent eddc5fd commit aae3d66ccbf71dfb7b2b0e4b5116a5824323271f @avh4 avh4 committed Jul 4, 2008
@@ -0,0 +1,5 @@
+Description:
+
+
+Usage:
+
@@ -0,0 +1,53 @@
+class StoryGenerator < 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 'some_folder'
+
+ # Create stubs
+ # m.template "template.rb", "some_file_after_erb.rb"
+ # m.template_copy_each ["template.rb", "template2.rb"]
+ # m.file "file", "some_file_copied"
+ # m.file_copy_each ["path/to/file", "path/to/file2"]
+ 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
@@ -0,0 +1,44 @@
+require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
+
+
+class TestStoryGenerator < 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('story', [name], sources)
+ assert_generated_file("some_file")
+ end
+
+ private
+ def sources
+ [RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", generator_path))
+ ]
+ end
+
+ def generator_path
+ "rbiphonetest_generators"
+ end
+end

0 comments on commit aae3d66

Please sign in to comment.