bobbyno-shubox 0.8 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,13 @@
1
+ == 0.8.1 2009-09-26
2
+
3
+ * 2 minor enhancements:
4
+ * script/filter_test_unit can be called from within a test file in TextMate
5
+ using "Text -> Filter Through Command" and Document as Input; alternately
6
+ create a TextMate command with the contents of the script.
7
+ * Comments and whitespace are now mostly preserved in test cases; comments
8
+ appear after the test case in which they appear.
9
+
10
+
1
11
  == 0.8 2009-09-22
2
12
 
3
13
  * 1 major enhancement:
@@ -26,6 +26,7 @@ bin/shubox
26
26
  cleaner_generators/test_unit_cleaner/USAGE
27
27
  cleaner_generators/test_unit_cleaner/lib/test_unit_cleaner.rb
28
28
  cleaner_generators/test_unit_cleaner/templates/clean_test_unit
29
+ cleaner_generators/test_unit_cleaner/templates/filter_test_unit
29
30
  cleaner_generators/test_unit_cleaner/test_unit_cleaner_generator.rb
30
31
  lib/languages.rb
31
32
  lib/shubox.rb
@@ -33,9 +34,9 @@ lib/shubox_app_generator.rb
33
34
  script/console
34
35
  script/destroy
35
36
  script/generate
37
+ test/cleaners/test_test_unit_cleaner.rb
38
+ test/generators/test_java_generator.rb
39
+ test/generators/test_ruby_generator.rb
40
+ test/lib/test_languages.rb
36
41
  test/test_generator_helper.rb
37
42
  test/test_helper.rb
38
- test/test_java_generator.rb
39
- test/test_languages.rb
40
- test/test_ruby_generator.rb
41
- test/test_test_unit_cleaner.rb
@@ -14,6 +14,20 @@ shubox currently creates environments for Ruby and Java, but can easily be exten
14
14
  lends itself to unit testing. shubox is built on newgem, so extending the framework is as simple as creating
15
15
  new generator scripts.
16
16
 
17
+ After installing shubox and generating a testing environment, you'll start off with some passing tests that exercise
18
+ parts of the language's API. Write new learning tests, naming each method with the intent of the lesson, then write
19
+ the code that makes a test pass.
20
+
21
+ Can you complete the lesson again from memory? If not, you may need to study the concept more closely
22
+ and implement the tests again. According to {a paper by Karpicke and Roediger}[http://psych.wustl.edu/memory/Roddy%20article%20PDF's/Karpicke_Roediger_2008_Science.pdf],
23
+ "repeated retrieval practice led to greater than 150% improvements in long-term retention than studying alone.
24
+ ...Although educators and psychologists often consider testing a neutral process that merely assesses the
25
+ contents of memory, practicing retrieval during tests clearly produces more learning than additional
26
+ encoding or study once an item has been recalled."
27
+
28
+ shubox makes repeated testing easy by providing built-in test cleaners that delete your test implementations,
29
+ while keeping comments and test names to express the intent of the test.
30
+
17
31
  == INSTALL
18
32
 
19
33
  The <code>shubox</code> application is distributed as a RubyGem and is available immediately after installation.
@@ -34,17 +48,15 @@ Ruby is the default language option in shubox:
34
48
 
35
49
  <code>$ rake</code>
36
50
 
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.
51
+ To clean all tests in your project:
43
52
 
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.
53
+ <code>$ script/clean_test_unit .</code>
46
54
 
47
- This is repetition with a retrieval step, which leads to long-term retention.
55
+ If you're using TextMate, you can quickly reset a test file from within the editor using
56
+ "Text -> Filter Through Command". Select "/tmp/learn_ruby/script/filter_test_unit"
57
+ as the command, select "Document" as input, and select "Replace Document" as output. Alternately,
58
+ save the contents of the filter script to a custom TextMate command to easily run it with a
59
+ keyboard shortcut.
48
60
 
49
61
  == JAVA USAGE
50
62
 
@@ -69,7 +81,8 @@ app_generators are where we define the basic environment for one of our supporte
69
81
 
70
82
  cleaner_generators hold the test framework cleaning implementations to reset tests.
71
83
  In the future, these can be mixed and matched to support polyglots like JRuby by installing both
72
- JUnit and Test::Unit cleaners.
84
+ JUnit and Test::Unit cleaners. Run script/generate in a generated shubox to see the list of
85
+ available cleaners and generators that can be installed.
73
86
 
74
87
  cleaner/lib folders hold the implementations of the cleaners referenced in the clean_xxx files
75
88
  copied to the generated application. This makes it easy to upgrade existing shuboxes.
data/Rakefile CHANGED
@@ -33,7 +33,7 @@ Dir['tasks/**/*.rake'].each { |t| load t }
33
33
  # task :default => [:spec, :features]
34
34
 
35
35
  desc "Create the gem and install it"
36
- task :dev => [:clean, :manifest, :clean_manifest, :gemspec, :package, :install_gem]
36
+ task :dev => [:clean, :manifest, :clean_manifest, :gemspec, :package, :install_gem, :uat]
37
37
 
38
38
  desc "Strip out the entries in the .git folder for ppl who haven't updated .hoerc"
39
39
  task :clean_manifest do
@@ -48,5 +48,10 @@ task :clean do
48
48
  end
49
49
 
50
50
  task :uninstall do
51
+ rm_rf("/tmp/tester")
51
52
  sh "sudo gem uninstall shubox"
53
+ end
54
+
55
+ task :uat do
56
+ sh "shubox /tmp/tester"
52
57
  end
@@ -6,9 +6,9 @@ require File.dirname(__FILE__) + '/test_helper'
6
6
  # Exploring the methods of the IO class: http://www.ruby-doc.org/core/classes/IO.html
7
7
  class TestIO < Test::Unit::TestCase
8
8
 
9
- def test_readlines
9
+ # See String Match for =~ syntax: http://www.ruby-doc.org/core/classes/String.html#M000792
10
+ def test_readlines_reads_files_as_array
10
11
  contents = IO.readlines(File.join(Constants::TEST_DATA_DIR, "file.txt"))
11
- # See String Match for =~ syntax: http://www.ruby-doc.org/core/classes/String.html#M000792
12
12
  assert(contents[0] =~ /Salam/)
13
13
  end
14
14
 
@@ -2,35 +2,22 @@ module Shubox
2
2
  class TestUnitCleaner
3
3
 
4
4
  def run(args)
5
- if (%w(-h --help).include?(args.first) || args.empty?)
6
- puts usage
7
- return 0
8
- end
9
-
10
5
  target = args.first
6
+ return usage if empty_or_help?(target)
11
7
 
12
- if (/.rb$/ =~ target)
13
- clean(target)
8
+ if File.file?(target)
9
+ clean_file(target)
14
10
  else
15
11
  clean_directory(target)
16
12
  end
17
13
  end
18
14
 
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)
15
+ def clean_class(lines)
29
16
  output = []
30
17
  outside_class = true
31
18
 
32
19
  lines.each do |line|
33
- if (outside_class)
20
+ if (outside_class || comment?(line))
34
21
  output << line
35
22
  elsif (/^\s*def test_/ =~ line)
36
23
  output << line
@@ -42,15 +29,37 @@ module Shubox
42
29
  end
43
30
  end
44
31
  output << 'end'
45
-
46
- open(filename, 'w') do |f|
47
- f.puts output.join
48
- end
32
+ output.join
33
+ end
34
+
35
+ def comment?(line)
36
+ (line =~ /^\s*#/ || line =~ /^\s*$/)
37
+ end
38
+
39
+ def empty_or_help?(input)
40
+ return (input.nil? || input.empty? || %w(-h --help).include?(input))
49
41
  end
50
42
 
51
43
  def usage
52
44
  usage_file = File.dirname(__FILE__) + "/../USAGE"
53
45
  return File.readlines(usage_file)
54
46
  end
47
+
48
+ private
49
+ def clean_directory(dir)
50
+ files = Dir["#{dir}/test/**/test_*.rb"].each { |file| clean_file(file) }
51
+ end
52
+
53
+ def clean_file(filename)
54
+ return if /test_helper.rb/ =~ filename
55
+ puts "cleaning: #{filename}"
56
+
57
+ lines = File.readlines(filename)
58
+ output = clean_class(lines)
59
+
60
+ open(filename, 'w') do |f|
61
+ f.puts output
62
+ end
63
+ end
55
64
  end
56
65
  end
@@ -9,4 +9,4 @@ end
9
9
 
10
10
  require 'test_unit_cleaner/lib/test_unit_cleaner'
11
11
 
12
- Shubox::TestUnitCleaner.new.run(ARGV)
12
+ puts Shubox::TestUnitCleaner.new.run(ARGV)
@@ -0,0 +1,13 @@
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
+ doc = ARGF.readlines
13
+ puts Shubox::TestUnitCleaner.new.clean_class(doc)
@@ -10,7 +10,8 @@ class TestUnitCleanerGenerator < RubiGen::Base
10
10
 
11
11
  record do |m|
12
12
  m.directory 'script'
13
- m.template "clean_test_unit", "script/clean_test_unit", script_options
13
+ m.file "clean_test_unit", "script/clean_test_unit", script_options
14
+ m.file "filter_test_unit", "script/filter_test_unit", script_options
14
15
  end
15
16
  end
16
17
 
@@ -5,7 +5,7 @@ $:.unshift(File.dirname(__FILE__) + '/../cleaner_generators') unless
5
5
  $:.include?(File.dirname(__FILE__) + '/../cleaner_generators') || $:.include?(File.expand_path(File.dirname(__FILE__) + '../cleaner_generators'))
6
6
 
7
7
  module Shubox
8
- VERSION = '0.8'
8
+ VERSION = '0.8.1'
9
9
  end
10
10
 
11
11
  require 'test_unit_cleaner/lib/test_unit_cleaner'
@@ -1,5 +1,5 @@
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')
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
3
  require 'fileutils'
4
4
  require 'languages'
5
5
 
@@ -15,21 +15,25 @@ class TestTestUnitCleaner < Test::Unit::TestCase
15
15
  bare_teardown
16
16
  end
17
17
 
18
- def test_display_usage_with_no_args
19
- no_args = Shubox::TestUnitCleaner.new.run([])
20
- assert_equal(0, no_args)
18
+ def test_display_usage_with_no_args_or_help
19
+ cleaner = Shubox::TestUnitCleaner.new
20
+ no_args = cleaner.run([""])
21
+ assert_equal(cleaner.usage, no_args)
22
+
23
+ help = cleaner.run(["--help"])
24
+ assert_equal(cleaner.usage, help)
21
25
  end
22
26
 
23
- def test_display_usage_with_help
24
- help = Shubox::TestUnitCleaner.new.run(["--help"])
25
- assert_equal(0, help)
27
+ def test_detect_comments
28
+ line = " # Comment here"
29
+ cleaner = Shubox::TestUnitCleaner.new
30
+ assert(cleaner.comment?(line))
31
+ assert(!cleaner.comment?("hello"))
26
32
  end
27
33
 
28
34
  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
35
+ dir_to_clean = File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp', 'myproject'))
31
36
  clean_file = File.join(dir_to_clean, 'test', 'test_io.rb')
32
- puts clean_file
33
37
  Shubox::TestUnitCleaner.new.run([dir_to_clean, "ignored extra parameter"])
34
38
  assert_equal <<-EOF, File.read(clean_file)
35
39
  require File.dirname(__FILE__) + '/test_helper'
@@ -39,33 +43,41 @@ require File.dirname(__FILE__) + '/test_helper'
39
43
 
40
44
  # Exploring the methods of the IO class: http://www.ruby-doc.org/core/classes/IO.html
41
45
  class TestIO < Test::Unit::TestCase
42
- def test_readlines
46
+
47
+ # See String Match for =~ syntax: http://www.ruby-doc.org/core/classes/String.html#M000792
48
+ def test_readlines_reads_files_as_array
43
49
  end
50
+
44
51
  end
45
52
  EOF
46
53
  end
47
54
 
48
55
  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)
56
+ file_to_clean = File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp', 'myproject', 'test', 'samples', 'test_right_triangle.rb'))
57
+ contents = File.read(file_to_clean)
58
+
59
+ cleaner = Shubox::TestUnitCleaner.new
60
+ cleaner.run([file_to_clean])
61
+ cleaned_file = File.read(file_to_clean)
62
+
63
+ assert_equal <<-EOF, cleaned_file
52
64
  require File.dirname(__FILE__) + '/../test_helper'
53
65
  require 'samples/right_triangle'
54
66
 
55
67
  # An example of testing a class in the lib folder.
56
68
  class TestRightTriangle < Test::Unit::TestCase
69
+
70
+
57
71
  def test_hypotenuse
58
72
  end
73
+
59
74
  def test_area
60
75
  end
76
+
61
77
  end
62
78
  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
- ]
79
+
80
+ cleaned_contents = cleaner.clean_class(contents)
81
+ assert_equal(cleaned_contents, cleaned_file.strip)
70
82
  end
71
83
  end
@@ -1,4 +1,5 @@
1
- require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
1
+ require File.join(File.dirname(__FILE__), "..", "test_generator_helper.rb")
2
+ require 'languages'
2
3
 
3
4
  class TestJavaGenerator < Test::Unit::TestCase
4
5
  include RubiGen::GeneratorTestHelper
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
1
+ require File.join(File.dirname(__FILE__), "..", "test_generator_helper.rb")
2
2
  require 'fileutils'
3
3
  require 'languages'
4
4
 
@@ -27,15 +27,8 @@ class TestRubyGenerator < Test::Unit::TestCase
27
27
  assert_generated_file "test/test_io.rb"
28
28
  assert_generated_file "test/test_helper.rb"
29
29
  assert_generated_file "script/clean_test_unit"
30
+ assert_generated_file "script/filter_test_unit"
30
31
 
31
32
  run_generated_build_script("rake")
32
33
  end
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
-
41
34
  end
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
1
+ require File.join(File.dirname(__FILE__), "..", "test_generator_helper.rb")
2
2
  require 'languages'
3
3
 
4
4
  class TestLanguages < Test::Unit::TestCase
@@ -49,14 +49,12 @@ module RubiGen::GeneratorTestHelper
49
49
  raise "Exit code #{$?} while running generated build script with #{cmd}" if ($?.to_s != "0")
50
50
  end
51
51
  end
52
-
52
+
53
53
  def sources
54
- [RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", generator_path))]
54
+ [ RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__), "..", "app_generators")),
55
+ RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__), "..", "cleaner_generators"))]
55
56
  end
56
57
 
57
- def generator_path
58
- "app_generators"
59
- end
60
58
  # Some generator-related assertions:
61
59
  # assert_generated_file(name, &block) # block passed the file contents
62
60
  # assert_directory_exists(name)
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.8"
4
+ version: 0.8.1
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-09-22 00:00:00 -07:00
12
+ date: 2009-09-26 00:00:00 -07:00
13
13
  default_executable: shubox
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -32,7 +32,7 @@ dependencies:
32
32
  - !ruby/object:Gem::Version
33
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. shubox currently creates environments for Ruby and Java, but can easily be extended to any language that lends itself to unit testing. shubox is built on newgem, so extending the framework is as simple as creating new generator scripts. After installing shubox and generating a testing environment, you'll start off with some passing tests that exercise parts of the language's API. Write new learning tests, naming each method with the intent of the lesson, then write the code that makes a test pass. Can you complete the lesson again from memory? If not, you may need to study the concept more closely and implement the tests again. According to {a paper by Karpicke and Roediger}[http://psych.wustl.edu/memory/Roddy%20article%20PDF's/Karpicke_Roediger_2008_Science.pdf], \"repeated retrieval practice led to greater than 150% improvements in long-term retention than studying alone. ...Although educators and psychologists often consider testing a neutral process that merely assesses the contents of memory, practicing retrieval during tests clearly produces more learning than additional encoding or study once an item has been recalled.\" shubox makes repeated testing easy by providing built-in test cleaners that delete your test implementations, while keeping comments and test names to express the intent of the test."
36
36
  email:
37
37
  - codeculturist@gmail.com
38
38
  executables:
@@ -74,6 +74,7 @@ files:
74
74
  - cleaner_generators/test_unit_cleaner/USAGE
75
75
  - cleaner_generators/test_unit_cleaner/lib/test_unit_cleaner.rb
76
76
  - cleaner_generators/test_unit_cleaner/templates/clean_test_unit
77
+ - cleaner_generators/test_unit_cleaner/templates/filter_test_unit
77
78
  - cleaner_generators/test_unit_cleaner/test_unit_cleaner_generator.rb
78
79
  - lib/languages.rb
79
80
  - lib/shubox.rb
@@ -81,12 +82,12 @@ files:
81
82
  - script/console
82
83
  - script/destroy
83
84
  - script/generate
85
+ - test/cleaners/test_test_unit_cleaner.rb
86
+ - test/generators/test_java_generator.rb
87
+ - test/generators/test_ruby_generator.rb
88
+ - test/lib/test_languages.rb
84
89
  - test/test_generator_helper.rb
85
90
  - test/test_helper.rb
86
- - test/test_java_generator.rb
87
- - test/test_languages.rb
88
- - test/test_ruby_generator.rb
89
- - test/test_test_unit_cleaner.rb
90
91
  has_rdoc: false
91
92
  homepage: http://github.com/bobbyno/shubox/tree/master
92
93
  licenses:
@@ -116,9 +117,9 @@ signing_key:
116
117
  specification_version: 3
117
118
  summary: Test-driven learning is a way to master a programming language by writing unit tests around its API's
118
119
  test_files:
120
+ - test/cleaners/test_test_unit_cleaner.rb
121
+ - test/generators/test_java_generator.rb
122
+ - test/generators/test_ruby_generator.rb
123
+ - test/lib/test_languages.rb
119
124
  - test/test_generator_helper.rb
120
125
  - test/test_helper.rb
121
- - test/test_java_generator.rb
122
- - test/test_languages.rb
123
- - test/test_ruby_generator.rb
124
- - test/test_test_unit_cleaner.rb