Permalink
Browse files

Refactored to use newgem

  • Loading branch information...
1 parent e855fab commit 6e2e6658ae2e3126d6382627ed33325461a8152f @bobbyno committed Jun 16, 2009
View
@@ -0,0 +1,4 @@
+== 0.5.0 2009-06-15
+
+* 1 major enhancement:
+ * Refactored to use newgem / rubigen file generation.
View
@@ -0,0 +1,25 @@
+History.txt
+MIT-LICENSE
+Manifest.txt
+PostInstall.txt
+README.rdoc
+Rakefile
+app_generators/tbox/USAGE
+app_generators/tbox/tbox_generator.rb
+app_generators/tbox/templates/README
+app_generators/tbox/templates/file.txt
+app_generators/tbox/templates/rakefile.rb
+app_generators/tbox/templates/right_triangle.rb
+app_generators/tbox/templates/tbox.rb
+app_generators/tbox/templates/test_helper.rb
+app_generators/tbox/templates/test_io.rb
+app_generators/tbox/templates/test_right_triangle.rb
+bin/tbox
+lib/tbox.rb
+script/console
+script/destroy
+script/generate
+tbox.gemspec
+test/test_generator_helper.rb
+test/test_helper.rb
+test/test_tbox_generator.rb
View
@@ -0,0 +1,6 @@
+
+For more information on tbox, see http://github.com/bobbyno/tbox/tree/master
+
+
+
+
View
@@ -0,0 +1,47 @@
+= tbox - A test-driven learning sandbox creation tool
+
+Project Home: http://github.com/bobbyno/tbox/tree/master
+More on Test-Driven Learning: http://www.bobbynorton.com/?p=36
+
+== DESCRIPTION:
+
+tbox lowers the barrier to entry for test-driven learning* by providing a basic infrastructure in which
+to start coding: A directory structure, some classes and unit tests to get started, and a Rakefile to run
+all tests. For now, tbox is geared toward Ruby, though the technique is applicable to any language that
+lends itself to TDD.
+
+== BASIC USAGE:
+
+Go to the folder where you want to create your new test sandbox, and run the <code>tbox</code> command to generate your test scaffolding.
+
+ <code>
+ $ cd ~/ruby_projects
+ $ tbox learning_ruby
+ $ rake
+ </code>
+
+== SYNOPSIS:
+
+tbox is built using newgem. Although tbox was initially designed with Ruby and Test::Unit in mind, new generator
+scripts can easily be added to support other testing techniques in multiple languages. tbox can therefore become
+a starting point for test-driven learning in any language with any dependencies.
+
+== REQUIREMENTS:
+
+* newgem
+
+== INSTALL:
+
+The <code>tbox</code> application is distributed as a RubyGem and is available immediately after installation.
+
+ <code>
+ $ gem sources -a http://gems.github.com (you only have to do this once)
+ $ sudo gem install bobbyno-tbox
+ </code>
+
+Alternately, download the gem and install manually from github.
+
+== CREDITS:
+
+Bobby Norton, DRW Trading Group
+Dr. Nic Williams for newgem and rubigen: http://rubyconf2007.confreaks.com/d3t1p1_rubigen.html
View
@@ -0,0 +1,31 @@
+require 'rubygems' unless ENV['NO_RUBYGEMS']
+%w[rake rake/clean fileutils newgem rubigen].each { |f| require f }
+require File.dirname(__FILE__) + '/lib/tbox'
+
+# Generate all the Rake tasks
+# Run 'rake -T' to see list of generated tasks (from gem root directory)
+$hoe = Hoe.new('tbox', Tbox::VERSION) do |p|
+ p.developer('Bobby Norton', 'codeculturist@gmail.com')
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
+ p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
+ p.rubyforge_name = p.name # TODO this is default value
+ # p.extra_deps = [
+ # ['activesupport','>= 2.0.2'],
+ # ]
+ p.extra_dev_deps = [
+ ['newgem', ">= #{::Newgem::VERSION}"]
+ ]
+
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
+ p.rsync_args = '-av --delete --ignore-errors'
+end
+
+require 'newgem/tasks' # load /tasks/*.rake
+Dir['tasks/**/*.rake'].each { |t| load t }
+
+# TODO - want other tests/tasks run by default? Add them to the list
+# task :default => [:spec, :features]
+
+task :package => [:gemspec]
View
@@ -0,0 +1,12 @@
+Description:
+
+tbox lowers the barrier to entry for test-driven learning by providing a basic infrastructure in which
+to start coding: A directory structure, some classes and unit tests to get started, and a Rakefile to run
+all tests. For now, tbox is geared toward Ruby, though the technique is applicable to any language that
+lends itself to TDD.
+
+Usage:
+
+$ cd ~/ruby_projects
+$ tbox learning_ruby
+$ rake
@@ -0,0 +1,84 @@
+class TboxGenerator < RubiGen::Base
+
+ DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
+ Config::CONFIG['ruby_install_name'])
+
+ default_options :author => nil
+
+ attr_reader :name
+
+ def initialize(runtime_args, runtime_options = {})
+ super
+ usage if args.empty?
+ @destination_root = File.expand_path(args.shift)
+ @name = base_name
+ extract_options
+ end
+
+ def manifest
+ record do |m|
+ # Ensure appropriate folder(s) exists
+ m.directory ''
+ BASEDIRS.each { |path| m.directory path }
+
+ m.file "rakefile.rb", "rakefile.rb"
+ m.file "README", "README"
+ m.file "../../../MIT-LICENSE", "MIT-LICENSE"
+ # 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"]
+ m.directory "lib/samples"
+ m.file "right_triangle.rb", "lib/samples/right_triangle.rb"
+ m.file "tbox.rb", "lib/tbox.rb"
+ m.directory "test/samples"
+ m.directory "test/data"
+ m.file "test_right_triangle.rb", "test/samples/test_right_triangle.rb"
+ m.file "test_io.rb", "test/test_io.rb"
+ m.file "file.txt", "test/data/file.txt"
+ m.file "test_helper.rb", "test/test_helper.rb"
+
+ m.dependency "install_rubigen_scripts", [destination_root, 'tbox'],
+ :shebang => options[:shebang], :collision => :force
+ end
+ end
+
+ protected
+ def banner
+ <<-EOS
+Creates a test-driven learning environment: A directory structure, some sample classes and unit tests,
+and a Rakefile to run all tests.
+
+USAGE: #{spec.name} dir_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") { |o| options[:author] = o }
+ 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
+
+ # Installation skeleton. Intermediate directories are automatically
+ # created so don't sweat their absence here.
+ BASEDIRS = %w(
+ lib
+ log
+ script
+ test
+ tmp
+ )
+end
@@ -0,0 +1,45 @@
+= tbox - A test-driven learning sandbox creation tool
+
+* See http://www.bobbynorton.com/?p=36 for more on tbox and test-driven learning.
+
+== Description:
+
+tbox lowers the barrier to entry for test-driven learning by providing a basic infrastructure in which
+to start coding: A directory structure, some classes and unit tests to get started, and a Rakefile to run
+all tests. For now, tbox is geared toward Ruby, though the technique is applicable to any language that
+lends itself to TDD.
+
+== Learning Ruby by Testing:
+
+If you're completely new to Ruby, you should start with "Ruby in Twenty Minutes" -
+http://www.ruby-lang.org/en/documentation/quickstart/. This will help you get Ruby installed and will
+explain the basics of Ruby programming.
+
+If you already have Ruby and rake (http://rake.rubyforge.org/files/README.html) installed and you're
+ready to start, then fire up a command prompt and run the starter tests that ship with tbox:
+
+ $ cd ~/ruby_projects
+ $ tbox learning_ruby
+ $ rake
+
+This uses the rake TestTask to run all the unit tests in your test folder. If everything goes as planned,
+running this command should produce something like:
+
+ Loaded suite /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake/rake_test_loader
+ Started
+ ...
+ Finished in 0.000706 seconds.
+
+ 3 tests, 4 assertions, 0 failures, 0 errors
+
+Open up the test cases in your favorite editor and have a look at what's going on. Change the tests. Add
+some new cases. Run them again every time you want to experiment with something new. Make sure you run
+all the tests in your suite before you check in at the end of your session.
+
+If you don't yet have a copy of Pickaxe, get one (http://www.pragprog.com/titles/ruby/programming-ruby).
+Add to your tbox repository as you read through the book to code up examples of what you're reading.
+
+== Credits:
+
+Bobby Norton, DRW Trading Group
+Dr. Nic Williams for newgem and rubigen: http://rubyconf2007.confreaks.com/d3t1p1_rubigen.html
@@ -0,0 +1,3 @@
+Salam, azizam!
+
+Welcome to Expo.
@@ -0,0 +1,9 @@
+require 'rake/testtask'
+
+task :default => :test
+
+Rake::TestTask.new do |t|
+ t.libs << "test"
+ t.test_files = FileList['test/**/test*.rb']
+ t.verbose = true
+end
@@ -0,0 +1,24 @@
+# Encapsulates the geometry of a 3-sided polygon with a right angle.
+# http://mathworld.wolfram.com/RightTriangle.html
+class RightTriangle
+
+ def initialize(base, height)
+ @a, @b = base, height
+ @c = hypotenuse
+ end
+
+ def hypotenuse
+ Math.sqrt((@a**2) + (@b**2))
+ end
+
+ def area
+ 0.5 * @a * @b
+ end
+
+private
+
+ def s
+ semiperimeter
+ end
+
+end
@@ -0,0 +1,6 @@
+$:.unshift(File.dirname(__FILE__)) unless
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
+
+module Tbox
+
+end
@@ -0,0 +1,9 @@
+require 'stringio'
+require 'test/unit'
+require File.dirname(__FILE__) + '/../lib/tbox'
+
+module Constants
+
+ TEST_DATA_DIR = File.join(File.expand_path(File.dirname(__FILE__)), "data")
+
+end
@@ -0,0 +1,15 @@
+require File.dirname(__FILE__) + '/test_helper'
+
+# Expo usage note: Keeping an inline bookmark to the rdocs for the class under study
+# makes it easy to continue your learning later.
+
+# Exploring the methods of the IO class: http://www.ruby-doc.org/core/classes/IO.html
+class TestIO < Test::Unit::TestCase
+
+ def test_readlines
+ contents = IO.readlines(File.join(Constants::TEST_DATA_DIR, "file.txt"))
+ # See String Match for =~ syntax: http://www.ruby-doc.org/core/classes/String.html#M000792
+ assert(contents[0] =~ /Salam/)
+ end
+
+end
@@ -0,0 +1,21 @@
+require File.dirname(__FILE__) + '/../test_helper'
+require 'samples/right_triangle'
+
+# An example of testing a class in the lib folder.
+class TestRightTriangle < Test::Unit::TestCase
+
+ def setup
+ @small = RightTriangle.new(3, 4)
+ @big = RightTriangle.new(120, 160)
+ end
+
+ def test_hypotenuse
+ assert_equal(5, @small.hypotenuse)
+ assert_equal(200, @big.hypotenuse)
+ end
+
+ def test_area
+ assert_equal(6, @small.area)
+ end
+
+end
View
@@ -0,0 +1,17 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'rubigen'
+
+if %w(-v --version).include? ARGV.first
+ require File.dirname(__FILE__) + "/../lib/tbox"
+ puts "#{File.basename($0)} #{Tbox::VERSION}"
+ exit(0)
+end
+
+require 'rubigen/scripts/generate'
+source = RubiGen::PathSource.new(:application,
+ File.join(File.dirname(__FILE__), "../app_generators"))
+RubiGen::Base.reset_sources
+RubiGen::Base.append_sources source
+RubiGen::Scripts::Generate.new.run(ARGV, :generator => 'tbox')
View
@@ -0,0 +1,6 @@
+$:.unshift(File.dirname(__FILE__)) unless
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
+
+module Tbox
+ VERSION = '0.5.0'
+end
Oops, something went wrong.

0 comments on commit 6e2e665

Please sign in to comment.