bobbyno-shubox 0.6 → 0.8

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,7 +1,16 @@
1
+ == 0.8 2009-09-22
2
+
3
+ * 1 major enhancement:
4
+ * clean script now included in generated shubox to reset tests in ruby.
5
+ * Thanks to bendyworks for the original concept in his patch.
6
+ * cleaners organized as generators to simplify new cleaner creation.
7
+ * cleaners can operate on directories or individual files.
8
+
9
+
1
10
  == 0.7 2009-08-26
2
11
 
3
12
  * Project rename:
4
- * tbox -> shubox: Shubox helps you move more quickly from Shu to Ha and Ri.
13
+ * tbox -> shubox: Shubox helps you move more quickly from Shu to Ha and Ri.
5
14
  * Thanks to Alistair Cockburn @ Agile 2009 for this one.
6
15
 
7
16
 
data/Manifest.txt CHANGED
@@ -23,15 +23,19 @@ app_generators/ruby/templates/test_helper.rb
23
23
  app_generators/ruby/templates/test_io.rb
24
24
  app_generators/ruby/templates/test_right_triangle.rb
25
25
  bin/shubox
26
+ cleaner_generators/test_unit_cleaner/USAGE
27
+ cleaner_generators/test_unit_cleaner/lib/test_unit_cleaner.rb
28
+ cleaner_generators/test_unit_cleaner/templates/clean_test_unit
29
+ cleaner_generators/test_unit_cleaner/test_unit_cleaner_generator.rb
26
30
  lib/languages.rb
27
31
  lib/shubox.rb
28
32
  lib/shubox_app_generator.rb
29
33
  script/console
30
34
  script/destroy
31
35
  script/generate
32
- tbox.gemspec
33
36
  test/test_generator_helper.rb
34
37
  test/test_helper.rb
35
38
  test/test_java_generator.rb
36
39
  test/test_languages.rb
37
40
  test/test_ruby_generator.rb
41
+ test/test_test_unit_cleaner.rb
data/README.rdoc CHANGED
@@ -3,14 +3,18 @@
3
3
  http://github.com/bobbyno/shubox/tree/master
4
4
 
5
5
  More on Test-Driven Learning: http://www.bobbynorton.com/?p=36
6
-
7
- == DESCRIPTION:
8
6
 
9
- Test-driven learning is a way to master a programming language by writing unit tests around its API's.
10
- shubox lowers the barrier to entry for test-driven learning by providing a basic infrastructure in which
11
- to start coding: A directory structure, some classes and unit tests to get started, and a build script.
7
+ == DESCRIPTION
12
8
 
13
- == INSTALL:
9
+ Test-driven learning is a way to master a programming language by writing unit tests around its API's.
10
+ shubox lowers the barrier to entry for test-driven learning by providing a basic infrastructure in which
11
+ to start coding: A directory structure, some classes and unit tests to get started, and a build script.
12
+
13
+ shubox currently creates environments for Ruby and Java, but can easily be extended to any language that
14
+ lends itself to unit testing. shubox is built on newgem, so extending the framework is as simple as creating
15
+ new generator scripts.
16
+
17
+ == INSTALL
14
18
 
15
19
  The <code>shubox</code> application is distributed as a RubyGem and is available immediately after installation.
16
20
 
@@ -20,42 +24,75 @@ The <code>shubox</code> application is distributed as a RubyGem and is available
20
24
 
21
25
  Alternately, download the gem and install manually from github.
22
26
 
23
- == BASIC USAGE:
27
+ == RUBY USAGE
24
28
 
25
- Go to the folder where you want to create your new test sandbox, and run the <code>shubox</code> command
26
- to generate your test scaffolding.
29
+ Ruby is the default language option in shubox:
27
30
 
28
- The default is Ruby:
31
+ <code>$ shubox /tmp/learn_ruby</code>
29
32
 
30
- <code>$ cd ~/ruby_projects</code>
31
-
32
- <code>$ shubox learning_ruby</code>
33
+ <code>$ cd /tmp/learn_ruby</code>
33
34
 
34
35
  <code>$ rake</code>
35
36
 
36
- shubox also supports Java:
37
+ If all goes well, you should start off with some passing tests. Write new learning tests,
38
+ naming each method with the intent of the lesson. Write the code that makes a test pass.
39
+
40
+ Now run script/clean. Cleaners will reset test files by deleting the method bodies.
41
+ Can you complete the lesson from memory? If so, can you do so faster than before?
42
+ If not, you may need to study the concept more closely.
43
+
44
+ Repeat a test-driven lesson until you can easily rewrite it from scratch. Once you can do so,
45
+ you may move on to another lesson.
37
46
 
38
- <code>$ cd ~/java_projects</code>
47
+ This is repetition with a retrieval step, which leads to long-term retention.
39
48
 
40
- <code>$ shubox -j LearnJava</code>
49
+ == JAVA USAGE
50
+
51
+ shubox supports Java:
52
+
53
+ <code>$ shubox -l=java /tmp/LearnJava</code>
54
+
55
+ <code>$ cd /tmp/LearnJava</code>
41
56
 
42
57
  <code>$ ant -f build/build.xml</code>
43
58
 
44
59
  The Java command will also generate a <project name>.ipr file to allow the project to easily be
45
- opened in IntelliJ 8.
60
+ opened in IntelliJ 8.
46
61
 
47
- == SYNOPSIS:
62
+ shubox does not currently include a JUnit cleaner script. Patches welcome. ;-)
48
63
 
49
- shubox currently creates environments for Ruby and Java, but can easily be extended to any language that
50
- lends itself to unit testing. shubox is built on newgem, so extending the framework is as simple as creating
51
- new generator scripts.
64
+ == APPLICATION ARCHITECTURE
65
+
66
+ shubox is organized as a set of generators, as in newgem and RubiGen.
52
67
 
53
- == REQUIREMENTS:
68
+ app_generators are where we define the basic environment for one of our supported languages.
69
+
70
+ cleaner_generators hold the test framework cleaning implementations to reset tests.
71
+ In the future, these can be mixed and matched to support polyglots like JRuby by installing both
72
+ JUnit and Test::Unit cleaners.
73
+
74
+ cleaner/lib folders hold the implementations of the cleaners referenced in the clean_xxx files
75
+ copied to the generated application. This makes it easy to upgrade existing shuboxes.
76
+
77
+ == REQUIREMENTS
54
78
 
55
79
  * newgem
56
80
 
57
- == CREDITS:
81
+ == CONTRIBUTORS
82
+
83
+ Initial concept - Bobby Norton
84
+
85
+ bendyworks for {Test::Unit cleaner patch}[http://github.com/bendyworks/shubox]
86
+
87
+ == THANKS!
58
88
 
59
- Bobby Norton, DRW Trading Group
89
+ {DRW Trading Group}[http://www.drwtrading.com] for time and feedback
90
+
91
+ Test-Driven Learning Attendees at {SCNA 2009}[http://scna.softwarecraftsmanship.org/schedule#bobby_norton]
60
92
 
61
93
  Dr. Nic Williams for newgem and rubigen: {RubyConf 2007 Presentation}[http://rubyconf2007.confreaks.com/d3t1p1_rubigen.html]
94
+
95
+ Jim Weirich and EdgeCase for {ruby_koans}[http://github.com/edgecase/ruby_koans]
96
+
97
+
98
+
data/Rakefile CHANGED
@@ -17,13 +17,13 @@ $hoe = Hoe.spec 'shubox' do |p|
17
17
  p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
18
18
  p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
19
19
  p.rubyforge_name = p.name # TODO this is default value
20
- p.extra_deps = [
21
- ['newgem', ">= #{::Newgem::VERSION}"]
22
- ]
20
+ p.extra_deps = [['newgem', "= #{::Newgem::VERSION}"]]
23
21
  p.clean_globs |= %w[**/.DS_Store tmp *.log]
24
22
  path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
25
23
  p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
26
24
  p.rsync_args = '-av --delete --ignore-errors'
25
+ p.readme_file = 'README.rdoc'
26
+ p.extra_rdoc_files = ['README.rdoc']
27
27
  end
28
28
 
29
29
  require 'newgem/tasks' # load /tasks/*.rake
@@ -35,8 +35,8 @@ Dir['tasks/**/*.rake'].each { |t| load t }
35
35
  desc "Create the gem and install it"
36
36
  task :dev => [:clean, :manifest, :clean_manifest, :gemspec, :package, :install_gem]
37
37
 
38
- desc "Strip out the entries in the .git folder for ppl who haven't updated .hoerc"
39
- task :clean_manifest do
38
+ desc "Strip out the entries in the .git folder for ppl who haven't updated .hoerc"
39
+ task :clean_manifest do
40
40
  manifest = IO.readlines("Manifest.txt")
41
41
  clean = manifest.reject {|item| item =~ /.git/ }
42
42
  File.open("Manifest.txt", mode_string="w" ) {|file| file.puts(clean)}
@@ -44,4 +44,9 @@ end
44
44
 
45
45
  task :clean do
46
46
  rm_f("shubox.gemspec")
47
+ rm_rf("pkg")
48
+ end
49
+
50
+ task :uninstall do
51
+ sh "sudo gem uninstall shubox"
47
52
  end
@@ -1,14 +1,14 @@
1
1
  Description:
2
2
 
3
- shubox lowers the barrier to entry for test-driven learning by providing a basic infrastructure in which
3
+ shubox lowers the barrier to entry for test-driven learning by providing a basic infrastructure in which
4
4
  to start coding: A directory structure, some classes and unit tests to get started, and a build script
5
- to run all tests.
6
-
5
+ to run all tests.
6
+
7
7
  Usage:
8
-
9
- $ cd ~/your_projects
10
- $ shubox --java LearnJava
11
- $ ant -f build/build.xml
8
+
9
+ $ cd ~/your_projects
10
+ $ shubox --java LearnJava
11
+ $ ant -f build/build.xml
12
12
 
13
13
  If you have IntelliJ, open the IPR file to get started with adding your learning tests. If you have
14
14
  a different IDE, follow the instructions to import your application as existing source.
@@ -11,24 +11,24 @@ class JavaGenerator < ShuboxAppGenerator
11
11
  # root
12
12
  m.template("project.ipr", "#{@name}.ipr")
13
13
  m.file("project.iml", "#{@name}.iml")
14
-
14
+
15
15
  # build
16
16
  m.template("build.xml", "build/build.xml")
17
17
 
18
18
  # lib
19
19
  m.file_copy_each %w(hamcrest-core.jar junit.jar), "lib"
20
-
20
+
21
21
  # src
22
22
  m.directory "src/com/samples"
23
23
  m.file("Greeting.java", "src/com/samples/Greeting.java")
24
-
24
+
25
25
  # test
26
26
  m.directory "test/com/samples"
27
27
  m.file("GreetingTest.java", "test/com/samples/GreetingTest.java")
28
28
  end
29
29
  end
30
30
 
31
- protected
31
+ protected
32
32
  # Installation skeleton.
33
33
  BASEDIRS = %w(
34
34
  build
@@ -1,11 +1,11 @@
1
1
  Description:
2
2
 
3
- shubox lowers the barrier to entry for test-driven learning by providing a basic infrastructure in which
3
+ shubox lowers the barrier to entry for test-driven learning by providing a basic infrastructure in which
4
4
  to start coding: A directory structure, some classes and unit tests to get started, and a Rakefile to run
5
- all tests.
6
-
5
+ all tests.
6
+
7
7
  Usage:
8
-
9
- $ cd ~/ruby_projects
10
- $ shubox learning_ruby
11
- $ rake
8
+
9
+ $ cd ~/ruby_projects
10
+ $ shubox learning_ruby
11
+ $ rake
@@ -1,8 +1,9 @@
1
1
  require 'shubox_app_generator'
2
+ require 'shubox'
2
3
 
3
4
  class RubyGenerator < ShuboxAppGenerator
4
5
 
5
- def manifest
6
+ def manifest
6
7
  record do |m|
7
8
  # Ensure appropriate folder(s) exists
8
9
  m.directory ''
@@ -19,8 +20,10 @@ class RubyGenerator < ShuboxAppGenerator
19
20
  m.file "file.txt", "test/data/file.txt"
20
21
  m.file "test_helper.rb", "test/test_helper.rb"
21
22
 
22
- m.dependency "install_rubigen_scripts", [destination_root, 'shubox'],
23
+ m.dependency "install_rubigen_scripts", [destination_root, "rubygems", "cleaner"],
23
24
  :shebang => options[:shebang], :collision => :force
25
+
26
+ m.dependency "test_unit_cleaner", [], :destination => destination_root, :collision => :force
24
27
  end
25
28
  end
26
29
 
@@ -1,3 +1,3 @@
1
1
  Salam, azizam!
2
2
 
3
- Welcome to Expo.
3
+ Welcome to Shubox.
@@ -5,5 +5,5 @@ task :default => :test
5
5
  Rake::TestTask.new do |t|
6
6
  t.libs << "test"
7
7
  t.test_files = FileList['test/**/test*.rb']
8
- t.verbose = true
8
+ t.verbose = true
9
9
  end
@@ -1,16 +1,16 @@
1
1
  # Encapsulates the geometry of a 3-sided polygon with a right angle.
2
2
  # http://mathworld.wolfram.com/RightTriangle.html
3
3
  class RightTriangle
4
-
4
+
5
5
  def initialize(base, height)
6
6
  @a, @b = base, height
7
7
  @c = hypotenuse
8
8
  end
9
-
9
+
10
10
  def hypotenuse
11
11
  Math.sqrt((@a**2) + (@b**2))
12
12
  end
13
-
13
+
14
14
  def area
15
15
  0.5 * @a * @b
16
16
  end
@@ -2,7 +2,7 @@ require 'stringio'
2
2
  require 'test/unit'
3
3
  require File.dirname(__FILE__) + '/../lib/shubox'
4
4
 
5
- module Constants
5
+ module Constants
6
6
  if (!defined? TEST_DATA_DIR)
7
7
  TEST_DATA_DIR = File.join(File.expand_path(File.dirname(__FILE__)), "data")
8
8
  end
@@ -1,10 +1,10 @@
1
1
  require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
- # Expo usage note: Keeping an inline bookmark to the rdocs for the class under study
3
+ # Pro tip: Keeping an inline bookmark to the rdocs for the class under study
4
4
  # makes it easy to continue your learning later.
5
5
 
6
6
  # Exploring the methods of the IO class: http://www.ruby-doc.org/core/classes/IO.html
7
- class TestIO < Test::Unit::TestCase
7
+ class TestIO < Test::Unit::TestCase
8
8
 
9
9
  def test_readlines
10
10
  contents = IO.readlines(File.join(Constants::TEST_DATA_DIR, "file.txt"))
@@ -2,8 +2,8 @@ require File.dirname(__FILE__) + '/../test_helper'
2
2
  require 'samples/right_triangle'
3
3
 
4
4
  # An example of testing a class in the lib folder.
5
- class TestRightTriangle < Test::Unit::TestCase
6
-
5
+ class TestRightTriangle < Test::Unit::TestCase
6
+
7
7
  def setup
8
8
  @small = RightTriangle.new(3, 4)
9
9
  @big = RightTriangle.new(120, 160)
@@ -11,10 +11,10 @@ class TestRightTriangle < Test::Unit::TestCase
11
11
 
12
12
  def test_hypotenuse
13
13
  assert_equal(5, @small.hypotenuse)
14
- assert_equal(200, @big.hypotenuse)
14
+ assert_equal(200, @big.hypotenuse)
15
15
  end
16
16
 
17
- def test_area
17
+ def test_area
18
18
  assert_equal(6, @small.area)
19
19
  end
20
20
 
data/bin/shubox CHANGED
@@ -4,7 +4,7 @@ require 'rubygems'
4
4
  require 'rubigen'
5
5
  require File.dirname(__FILE__) + "/../lib/shubox"
6
6
  require File.dirname(__FILE__) + "/../lib/languages"
7
-
7
+
8
8
  if %w(-v --version).include? ARGV.first
9
9
  puts "#{File.basename($0)} #{Shubox::VERSION}"
10
10
  exit(0)
@@ -12,9 +12,13 @@ end
12
12
 
13
13
  require 'rubigen/scripts/generate'
14
14
 
15
- source = RubiGen::PathSource.new(:application,
16
- File.join(File.dirname(__FILE__), "../app_generators"))
17
- RubiGen::Base.reset_sources
18
- RubiGen::Base.append_sources source
15
+ # require "pp"
16
+ RubiGen::Base.use_application_sources! :rubygems
17
+ RubiGen::Base.prepend_sources(*[
18
+ RubiGen::PathSource.new(:shubox, File.join(File.dirname(__FILE__), "..", "app_generators")),
19
+ RubiGen::PathSource.new(:shubox, File.join(File.dirname(__FILE__), "..", "cleaner_generators"))
20
+ ])
21
+ # pp RubiGen::Base.sources
22
+
19
23
 
20
24
  RubiGen::Scripts::Generate.new.run(ARGV, :generator => Languages.parse(ARGV))
@@ -0,0 +1,7 @@
1
+ USAGE: test_unit_cleaner path/to/file
2
+
3
+ Give the test files a clean sweep to retest yourself.
4
+ Deletes the method bodies from all tests in the specified file,
5
+ a clean sweep to retest yourself. If file is a directory,
6
+ all tests in the directory matching the pattern
7
+ path/to/file/test/**/test_*.rb will be affected.
@@ -0,0 +1,56 @@
1
+ module Shubox
2
+ class TestUnitCleaner
3
+
4
+ def run(args)
5
+ if (%w(-h --help).include?(args.first) || args.empty?)
6
+ puts usage
7
+ return 0
8
+ end
9
+
10
+ target = args.first
11
+
12
+ if (/.rb$/ =~ target)
13
+ clean(target)
14
+ else
15
+ clean_directory(target)
16
+ end
17
+ end
18
+
19
+ private
20
+ def clean_directory(dir)
21
+ files = Dir["#{dir}/test/**/test_*.rb"].each { |file| clean(file) }
22
+ end
23
+
24
+ def clean(filename)
25
+ return if /test_helper.rb/ =~ filename
26
+ puts "cleaning: #{filename}"
27
+
28
+ lines = File.readlines(filename)
29
+ output = []
30
+ outside_class = true
31
+
32
+ lines.each do |line|
33
+ if (outside_class)
34
+ output << line
35
+ elsif (/^\s*def test_/ =~ line)
36
+ output << line
37
+ output << " end\n"
38
+ end
39
+
40
+ if (/class [a-zA-Z]\S* < Test::Unit::TestCase/ =~ line)
41
+ outside_class = false
42
+ end
43
+ end
44
+ output << 'end'
45
+
46
+ open(filename, 'w') do |f|
47
+ f.puts output.join
48
+ end
49
+ end
50
+
51
+ def usage
52
+ usage_file = File.dirname(__FILE__) + "/../USAGE"
53
+ return File.readlines(usage_file)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'shubox'
5
+ rescue LoadError
6
+ require 'rubygems'
7
+ require 'shubox'
8
+ end
9
+
10
+ require 'test_unit_cleaner/lib/test_unit_cleaner'
11
+
12
+ Shubox::TestUnitCleaner.new.run(ARGV)
@@ -0,0 +1,26 @@
1
+ class TestUnitCleanerGenerator < RubiGen::Base
2
+
3
+ def initialize(runtime_args, runtime_options = {})
4
+ super
5
+ @destination_root = File.expand_path(destination_root)
6
+ end
7
+
8
+ def manifest
9
+ script_options = { :chmod => 0755 }
10
+
11
+ record do |m|
12
+ m.directory 'script'
13
+ m.template "clean_test_unit", "script/clean_test_unit", script_options
14
+ end
15
+ end
16
+
17
+ protected
18
+ def banner
19
+ <<-EOS
20
+ Install a cleaner for Test::Unit tests.
21
+
22
+ Deletes all method bodies in the tests.
23
+
24
+ EOS
25
+ end
26
+ end
data/lib/languages.rb CHANGED
@@ -1,22 +1,20 @@
1
1
  class Languages
2
-
3
2
  def self.parse(args)
4
3
  lang = args.find {|arg| ((arg =~ /-l=/) or (arg =~ /--language=/)) }
5
- lang = "-l=ruby" if lang.nil?
4
+ lang ||= "-l=ruby"
6
5
  lang = lang.split('=')[1]
7
6
  raise "Supported languages: #{current.inspect}" if (!current.member?(lang))
8
7
  lang
9
8
  end
10
-
9
+
11
10
  def self.current
12
11
  langs = Dir.entries(File.join(File.dirname(__FILE__), "../app_generators"))
13
12
  langs.reject {|i| ((i == ".") or (i == ".."))}
14
13
  end
15
-
14
+
16
15
  def self.print
17
16
  list = ""
18
17
  current.each {|lang| list << lang << '|'}
19
18
  list.chomp('|')
20
19
  end
21
-
22
20
  end
data/lib/shubox.rb CHANGED
@@ -1,6 +1,11 @@
1
1
  $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
+ $:.unshift(File.dirname(__FILE__) + '/../cleaner_generators') unless
5
+ $:.include?(File.dirname(__FILE__) + '/../cleaner_generators') || $:.include?(File.expand_path(File.dirname(__FILE__) + '../cleaner_generators'))
6
+
4
7
  module Shubox
5
- VERSION = '0.7'
6
- end
8
+ VERSION = '0.8'
9
+ end
10
+
11
+ require 'test_unit_cleaner/lib/test_unit_cleaner'
@@ -1,5 +1,5 @@
1
1
  class ShuboxAppGenerator < RubiGen::Base
2
-
2
+
3
3
  DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
4
4
  Config::CONFIG['ruby_install_name'])
5
5
 
@@ -15,13 +15,13 @@ class ShuboxAppGenerator < RubiGen::Base
15
15
  @name = base_name
16
16
  extract_options
17
17
  end
18
-
18
+
19
19
  protected
20
-
20
+
21
21
  def banner
22
22
  "\n" << IO.readlines(File.join(File.dirname(__FILE__), "../README.rdoc"))[0]
23
23
  end
24
-
24
+
25
25
  def add_options!(opts)
26
26
  opts.separator ''
27
27
  opts.separator 'Options:'
@@ -37,5 +37,4 @@ class ShuboxAppGenerator < RubiGen::Base
37
37
  def extract_options
38
38
  @language = options[:language]
39
39
  end
40
-
41
40
  end
@@ -42,6 +42,14 @@ module RubiGen::GeneratorTestHelper
42
42
  end
43
43
  end
44
44
 
45
+ def run_generated_cleaner(cmd)
46
+ FileUtils::cd(APP_ROOT + '/script') do
47
+ puts "Running generated clean script in #{FileUtils::pwd} with #{cmd}"
48
+ `#{cmd}`
49
+ raise "Exit code #{$?} while running generated build script with #{cmd}" if ($?.to_s != "0")
50
+ end
51
+ end
52
+
45
53
  def sources
46
54
  [RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", generator_path))]
47
55
  end
@@ -20,18 +20,17 @@ class TestJavaGenerator < Test::Unit::TestCase
20
20
  assert_directory_exists "build"
21
21
  assert_generated_file "build/build.xml"
22
22
  assert_file_contains(PROJECT_NAME, "build/build.xml")
23
-
23
+
24
24
  assert_directory_exists "lib"
25
25
  assert_generated_file "lib/junit.jar"
26
- assert_generated_file "lib/hamcrest-core.jar"
27
-
26
+ assert_generated_file "lib/hamcrest-core.jar"
27
+
28
28
  assert_directory_exists "src"
29
29
  assert_generated_file "src/com/samples/Greeting.java"
30
-
31
- assert_directory_exists "test"
30
+
31
+ assert_directory_exists "test"
32
32
  assert_generated_file "test/com/samples/GreetingTest.java"
33
-
33
+
34
34
  run_generated_build_script("ant -f build/build.xml")
35
35
  end
36
-
37
36
  end
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
2
2
  require 'languages'
3
3
 
4
4
  class TestLanguages < Test::Unit::TestCase
5
-
5
+
6
6
  def test_list_current_languages
7
7
  langs = Languages.current
8
8
  assert(langs.length > 1)
@@ -10,20 +10,24 @@ class TestLanguages < Test::Unit::TestCase
10
10
  assert(!langs.include?(".."))
11
11
  end
12
12
 
13
+ def test_ruby_is_default_language
14
+ assert_equal("ruby", Languages.parse(""))
15
+ end
16
+
13
17
  def test_parse_command_for_valid_language
14
18
  args = %w{-l=java MyAppName}
15
19
  assert_equal("java", Languages.parse(args))
16
20
  args = %w{--language=ruby app_name}
17
21
  assert_equal("ruby", Languages.parse(args))
18
22
  end
19
-
23
+
20
24
  def test_reject_invalid_language
21
- args = %w{-l=non sense}
22
- assert_raise RuntimeError do
25
+ args = %w{-l=nonsense}
26
+ assert_raise RuntimeError do
23
27
  Languages.parse(args)
24
28
  end
25
29
  end
26
-
30
+
27
31
  def test_print_languages
28
32
  base = "java|ruby"
29
33
  print = Languages.print
@@ -1,5 +1,6 @@
1
1
  require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
2
2
  require 'fileutils'
3
+ require 'languages'
3
4
 
4
5
  class TestRubyGenerator < Test::Unit::TestCase
5
6
  include RubiGen::GeneratorTestHelper
@@ -14,7 +15,7 @@ class TestRubyGenerator < Test::Unit::TestCase
14
15
 
15
16
  def test_generator_without_options
16
17
  run_generator('ruby', [APP_ROOT], sources)
17
-
18
+
18
19
  assert_generated_file "rakefile.rb"
19
20
  assert_directory_exists "lib/samples"
20
21
  assert_generated_file "lib/samples/right_triangle.rb"
@@ -25,8 +26,16 @@ class TestRubyGenerator < Test::Unit::TestCase
25
26
  assert_generated_file "test/data/file.txt"
26
27
  assert_generated_file "test/test_io.rb"
27
28
  assert_generated_file "test/test_helper.rb"
28
-
29
+ assert_generated_file "script/clean_test_unit"
30
+
29
31
  run_generated_build_script("rake")
30
32
  end
31
33
 
34
+ private
35
+ def sources
36
+ [ RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", "app_generators")),
37
+ RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__), "..", "cleaner_generators"))
38
+ ]
39
+ end
40
+
32
41
  end
@@ -0,0 +1,71 @@
1
+ require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
2
+ require File.join(File.dirname(__FILE__), '..', 'cleaner_generators', 'test_unit_cleaner', 'lib', 'test_unit_cleaner')
3
+ require 'fileutils'
4
+ require 'languages'
5
+
6
+ class TestTestUnitCleaner < Test::Unit::TestCase
7
+ include RubiGen::GeneratorTestHelper
8
+
9
+ def setup
10
+ bare_setup
11
+ run_generator('ruby', [APP_ROOT], sources)
12
+ end
13
+
14
+ def teardown
15
+ bare_teardown
16
+ end
17
+
18
+ def test_display_usage_with_no_args
19
+ no_args = Shubox::TestUnitCleaner.new.run([])
20
+ assert_equal(0, no_args)
21
+ end
22
+
23
+ def test_display_usage_with_help
24
+ help = Shubox::TestUnitCleaner.new.run(["--help"])
25
+ assert_equal(0, help)
26
+ end
27
+
28
+ def test_run_cleaner_on_directory
29
+ dir_to_clean = File.expand_path(File.join(File.dirname(__FILE__), 'tmp', 'myproject'))
30
+ puts "\n" + dir_to_clean
31
+ clean_file = File.join(dir_to_clean, 'test', 'test_io.rb')
32
+ puts clean_file
33
+ Shubox::TestUnitCleaner.new.run([dir_to_clean, "ignored extra parameter"])
34
+ assert_equal <<-EOF, File.read(clean_file)
35
+ require File.dirname(__FILE__) + '/test_helper'
36
+
37
+ # Pro tip: Keeping an inline bookmark to the rdocs for the class under study
38
+ # makes it easy to continue your learning later.
39
+
40
+ # Exploring the methods of the IO class: http://www.ruby-doc.org/core/classes/IO.html
41
+ class TestIO < Test::Unit::TestCase
42
+ def test_readlines
43
+ end
44
+ end
45
+ EOF
46
+ end
47
+
48
+ def test_run_cleaner_on_single_file
49
+ file_to_clean = File.expand_path(File.join(File.dirname(__FILE__), 'tmp', 'myproject', 'test', 'samples', 'test_right_triangle.rb'))
50
+ Shubox::TestUnitCleaner.new.run([file_to_clean])
51
+ assert_equal <<-EOF, File.read(file_to_clean)
52
+ require File.dirname(__FILE__) + '/../test_helper'
53
+ require 'samples/right_triangle'
54
+
55
+ # An example of testing a class in the lib folder.
56
+ class TestRightTriangle < Test::Unit::TestCase
57
+ def test_hypotenuse
58
+ end
59
+ def test_area
60
+ end
61
+ end
62
+ EOF
63
+ end
64
+
65
+ private
66
+ def sources
67
+ [ RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", "app_generators")),
68
+ RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__), "..", "cleaner_generators"))
69
+ ]
70
+ end
71
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bobbyno-shubox
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.6"
4
+ version: "0.8"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bobby Norton
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-24 00:00:00 -07:00
12
+ date: 2009-09-22 00:00:00 -07:00
13
13
  default_executable: shubox
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -18,9 +18,9 @@ dependencies:
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
20
20
  requirements:
21
- - - ">="
21
+ - - "="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.4.1
23
+ version: 1.5.2
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hoe
@@ -30,9 +30,9 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.8.0
33
+ version: 2.3.3
34
34
  version:
35
- description: "Test-driven learning is a way to master a programming language by writing unit tests around its API's. shubox 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 build script."
35
+ description: "Test-driven learning is a way to master a programming language by writing unit tests around its API's. shubox 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 build script."
36
36
  email:
37
37
  - codeculturist@gmail.com
38
38
  executables:
@@ -43,8 +43,8 @@ extra_rdoc_files:
43
43
  - History.txt
44
44
  - Manifest.txt
45
45
  - PostInstall.txt
46
- - README.rdoc
47
46
  - app_generators/ruby/templates/file.txt
47
+ - README.rdoc
48
48
  files:
49
49
  - History.txt
50
50
  - MIT-LICENSE
@@ -71,6 +71,10 @@ files:
71
71
  - app_generators/ruby/templates/test_io.rb
72
72
  - app_generators/ruby/templates/test_right_triangle.rb
73
73
  - bin/shubox
74
+ - cleaner_generators/test_unit_cleaner/USAGE
75
+ - cleaner_generators/test_unit_cleaner/lib/test_unit_cleaner.rb
76
+ - cleaner_generators/test_unit_cleaner/templates/clean_test_unit
77
+ - cleaner_generators/test_unit_cleaner/test_unit_cleaner_generator.rb
74
78
  - lib/languages.rb
75
79
  - lib/shubox.rb
76
80
  - lib/shubox_app_generator.rb
@@ -82,6 +86,7 @@ files:
82
86
  - test/test_java_generator.rb
83
87
  - test/test_languages.rb
84
88
  - test/test_ruby_generator.rb
89
+ - test/test_test_unit_cleaner.rb
85
90
  has_rdoc: false
86
91
  homepage: http://github.com/bobbyno/shubox/tree/master
87
92
  licenses:
@@ -116,3 +121,4 @@ test_files:
116
121
  - test/test_java_generator.rb
117
122
  - test/test_languages.rb
118
123
  - test/test_ruby_generator.rb
124
+ - test/test_test_unit_cleaner.rb