kata 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,41 +1,61 @@
1
1
  ## Kata ##
2
2
 
3
+ A kata is defined as an exercise in programming which helps hone your skills
4
+ through practice and repetition. Authoring katas is done in blogs with no
5
+ real way of testing yourself for improvement. This gem provides a DSL to
6
+ author the kata and administer it as a test providing feedback for evaluation.
7
+
8
+ ### Writing a Kata ###
9
+
10
+ It is as simple as installing this gem and creating a ruby file much like
11
+ an RSpec test as illustrated below:
12
+
3
13
  require 'kata'
4
14
 
5
- kata "String Calculator Kata" do
6
- requirement "Create a simple string calculator with a method add that takes a string" do
7
- example %q{The string can contain 0, 1 or 2 numbers for example "", "1", "1,2"}
8
- example "The method will return the sum of the digits"
9
- example "Then empty string will return 0"
15
+ kata "My First Kata" do
16
+ requirement "Create an add method that will accept two digits as arguments" do
17
+ example "invoking with 1 and 2 returns 3"
18
+ example "invoking with 5 only returns 5"
19
+ example "invoking with no arguments returns 0"
10
20
  end
11
-
12
- requirement "Allow the string to contain an unknown amount of numbers" do
13
- example %q{"1,2,3" sums to 6}
14
- example %q{"1,2,5,8" sums to 16}
21
+ requirement "Modify the add method to access multple digits as arguments" do
22
+ example "invoking with 1 and 2 and 3 returns 6"
23
+ example "invoking with 1 and 2 and 3 and 4 and 5 returns 15"
15
24
  end
25
+ end
16
26
 
17
- requirement "Allow the add method to handle new lines between numbers (instead of commas)" do
18
- example %q{"1\n2\n3" sums to 6}
19
- example %q{"2,3\n4" sums to 9}
20
- example %q{Consecutive use of delimeters ("1,\n2") should raise an exception}
21
- end
27
+ ### Taking a Kata ###
22
28
 
23
- requirement %q{Calling add with a negative number will throw an exception "negatives not allowed"} do
24
- example "The exception will list the negative number that was in the string"
25
- example "The exception should list all negatives if there is more than one"
26
- end
29
+ Running the kata from the command line yields:
27
30
 
28
- requirement "Allow the add method to handle a different delimiter" do
29
- example %q{To change a delimiter, the beginning of the string will contain a separate line "//[delimeter]\n...}
30
- example "This line is optional and all previous tests should pass"
31
- example %q{"//[;]\n1;2" sums to 3}
32
- example %q{"1;2" should raise an exception}
33
- end
31
+ wesbailey@feynman:~/kata> ruby sample.rb
32
+ My First Kata
33
+ Create an add method that will accept two digits as arguments
34
+ - invoking with 1 and 2 returns 3
35
+ - invoking with 1 returns 1
36
+ - invoking with no arguments returns 0
34
37
 
35
- requirement "Allow the add method to handle multiple different delimeters" do
36
- example %q{multiple delimeters can be specified in the separate line "//[delimeter][delimeter]...[delimeter]\n...}
37
- example %q{"//[*][;]\n1*2;3" sums to 6}
38
- example %q{"//[*][;][#]\n1*2;3#4" sums to 10}
39
- example %q{"//[#][;][*]\n1*2#3;4,5\n6" sums to 21}
40
- end
41
- end
38
+ continue (Y|n):
39
+
40
+ Modify the add method to access multple digits as arguments
41
+ - invoking with 1 and 2 and 3 returns 6
42
+ - invoking with 1 and 2 and 3 and 4 and 5 returns 15
43
+
44
+ continue (Y|n):
45
+
46
+
47
+ ### Completing the Kata ###
48
+
49
+ After completing the requirements of the kata continue and the report is
50
+ displayed:
51
+
52
+ Congratulations!
53
+ - Create an add method that will accept two digits as arguments 00:02:02
54
+ - Modify the add method to access multple digits as arguments 00:00:45
55
+
56
+ ### Installing Kata ###
57
+
58
+ It is up on rubygems.org so add it to your bundle or do it the old fashioned
59
+ way with:
60
+
61
+ gem install kata
@@ -1,19 +1,14 @@
1
1
  module Kata
2
- # Allow rspec access
3
- class << Kata
4
- @@input = $stdin
5
- @@output = $stdout
6
- @@times = []
7
- end
2
+ @@times = []
8
3
 
9
- def kata txt
10
- @@output.puts txt
4
+ def kata txt, lib = nil
5
+ puts txt
11
6
  yield if block_given?
12
7
  complete
13
8
  end
14
9
 
15
10
  def requirement txt
16
- @@output.puts indent + txt
11
+ puts indent + txt
17
12
 
18
13
  start = Time.now
19
14
 
@@ -21,7 +16,7 @@ module Kata
21
16
 
22
17
  rsp = ask "\ncontinue (Y|n): ", 'y'
23
18
 
24
- @@output.puts
19
+ puts
25
20
 
26
21
  elapsed = Time.now - start
27
22
  @@times << {:title => txt, :time => elapsed}
@@ -30,14 +25,14 @@ module Kata
30
25
  end
31
26
 
32
27
  def example txt
33
- @@output.puts indent + '- ' + txt
28
+ puts indent + '- ' + txt
34
29
  end
35
30
 
36
31
  private
37
32
 
38
33
  def ask prompt, default
39
- @@output.print prompt
40
- @@input.gets.chomp || default
34
+ print prompt
35
+ $stdin.gets.chomp || default
41
36
  end
42
37
 
43
38
  def complete status = true
@@ -49,8 +44,10 @@ module Kata
49
44
  [use/3600, use/60 % 60, use % 60].map {|v| v.to_s.rjust(2,'0')}.join(':')
50
45
  end
51
46
 
52
- @@output.puts "\n\n#{title}"
53
- @@output.puts @@times.inject('') {|s,p| s << "- #{p[:title][0,70].ljust(70, ' ')} #{formatter.call(p[:time]).rjust(10,' ')}\n"}
47
+ puts "\n\n#{title}"
48
+ puts @@times.inject('') {|s,p| s << "- #{p[:title][0,70].ljust(70, ' ')} #{formatter.call(p[:time]).rjust(10,' ')}\n"}
49
+ puts '-' * 70 + ' ' * 5 + '-' * 8
50
+ puts 'Total Time taking Kata'.ljust(70, ' ') + ' ' * 5 + formatter.call(@@times.inject(0) {|s,h| s += h[:time]})
54
51
  end
55
52
 
56
53
  exit 1 unless status
@@ -1,8 +1,6 @@
1
1
  require 'spec_helper'
2
2
  require 'kata'
3
3
 
4
- include Kata
5
-
6
4
  describe "Kata DSL" do
7
5
  before :each do
8
6
  @summary = 'sample summary'
@@ -1,11 +1,11 @@
1
1
  require 'stringio'
2
2
 
3
3
  def capture_stdout
4
- @@output = StringIO.new
5
- @@input = StringIO.new("y\n")
4
+ $stdout = StringIO.new
5
+ $stdin = StringIO.new("y\n")
6
6
  yield
7
- @@output.string.strip
7
+ $stdout.string.strip
8
8
  ensure
9
- @@output = $stdout
10
- @@input = $stdin
9
+ $stdout = STDOUT
10
+ $stdin = STDIN
11
11
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- - 1
9
- version: 0.1.1
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Wes
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-15 00:00:00 -08:00
18
+ date: 2010-12-18 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -33,8 +33,8 @@ dependencies:
33
33
  version: 1.0.0
34
34
  type: :development
35
35
  version_requirements: *id001
36
- description: extended description
37
- email: wes.bailey@insiderpages.com
36
+ description: This DSL provides an easy way for you to write a code kata or pairing exercise
37
+ email: baywes@gmail.com
38
38
  executables: []
39
39
 
40
40
  extensions: []