kata 0.1.1

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.
@@ -0,0 +1,41 @@
1
+ ## Kata ##
2
+
3
+ require 'kata'
4
+
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"
10
+ 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}
15
+ end
16
+
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
22
+
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
27
+
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
34
+
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
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'autospec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rspec-core', 'autospec')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'autotest' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('ZenTest', 'autotest')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'htmldiff' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('diff-lcs', 'htmldiff')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'ldiff' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('diff-lcs', 'ldiff')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'minitar' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('archive-tar-minitar', 'minitar')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'multigem' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('ZenTest', 'multigem')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'multiruby' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('ZenTest', 'multiruby')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'multiruby_setup' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('ZenTest', 'multiruby_setup')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rdebug' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('ruby-debug19', 'rdebug')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rspec-core', 'rspec')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'unit_diff' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('ZenTest', 'unit_diff')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'zentest' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('ZenTest', 'zentest')
@@ -0,0 +1,69 @@
1
+ module Kata
2
+ # Allow rspec access
3
+ class << Kata
4
+ @@input = $stdin
5
+ @@output = $stdout
6
+ @@times = []
7
+ end
8
+
9
+ def kata txt
10
+ @@output.puts txt
11
+ yield if block_given?
12
+ complete
13
+ end
14
+
15
+ def requirement txt
16
+ @@output.puts indent + txt
17
+
18
+ start = Time.now
19
+
20
+ yield if block_given?
21
+
22
+ rsp = ask "\ncontinue (Y|n): ", 'y'
23
+
24
+ @@output.puts
25
+
26
+ elapsed = Time.now - start
27
+ @@times << {:title => txt, :time => elapsed}
28
+
29
+ complete false if rsp.downcase == 'n'
30
+ end
31
+
32
+ def example txt
33
+ @@output.puts indent + '- ' + txt
34
+ end
35
+
36
+ private
37
+
38
+ def ask prompt, default
39
+ @@output.print prompt
40
+ @@input.gets.chomp || default
41
+ end
42
+
43
+ def complete status = true
44
+ if @@times.size > 0
45
+ title = status ? 'Congratulations!' : 'You completed the following:'
46
+
47
+ formatter = lambda do |sec|
48
+ use = sec.round
49
+ [use/3600, use/60 % 60, use % 60].map {|v| v.to_s.rjust(2,'0')}.join(':')
50
+ end
51
+
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"}
54
+ end
55
+
56
+ exit 1 unless status
57
+ end
58
+
59
+ def ancestry
60
+ caller.grep(/#{Regexp.escape(__FILE__)}/).map {|v| v.match(/^[^`]*`([^']*)'/)[1]}
61
+ end
62
+
63
+ def indent
64
+ nesting = ancestry.size - 2
65
+ ' ' * (3 * nesting)
66
+ end
67
+ end
68
+
69
+ include Kata
@@ -0,0 +1,141 @@
1
+ require 'spec_helper'
2
+ require 'kata'
3
+
4
+ include Kata
5
+
6
+ describe "Kata DSL" do
7
+ before :each do
8
+ @summary = 'sample summary'
9
+ end
10
+
11
+ context "kata" do
12
+ it "is defined" do
13
+ capture_stdout do
14
+ lambda {
15
+ kata @summary
16
+ }.should_not raise_exception
17
+ end
18
+ end
19
+
20
+ it "accepts block" do
21
+ capture_stdout do
22
+ lambda {
23
+ kata @summary do
24
+ end
25
+ }.should_not raise_exception
26
+ end
27
+ end
28
+
29
+ it "displays the summary" do
30
+ output = capture_stdout do
31
+ lambda {
32
+ kata @summary
33
+ }.should_not raise_exception
34
+ end
35
+
36
+ output.should have_summary @summary
37
+ end
38
+
39
+ it "displays the summary with block" do
40
+ output = capture_stdout do
41
+ lambda {
42
+ kata @summary do
43
+ end
44
+ }.should_not raise_exception
45
+ end
46
+
47
+ output.should have_summary @summary
48
+ end
49
+ end
50
+
51
+ context "requirement" do
52
+ before :each do
53
+ @requirement = "Create a simple string calculator with a method add that takes a string argument"
54
+ end
55
+
56
+ it "is defined" do
57
+ capture_stdout do
58
+ lambda {
59
+ kata @summary do
60
+ requirement @requirement
61
+ end
62
+ }.should_not raise_exception
63
+ end
64
+ end
65
+
66
+ it "accepts block" do
67
+ capture_stdout do
68
+ lambda {
69
+ kata @summary do
70
+ requirement @requirement do
71
+ end
72
+ end
73
+ }.should_not raise_exception
74
+ end
75
+ end
76
+
77
+ it "displays the summary" do
78
+ output = capture_stdout do
79
+ lambda {
80
+ kata @summary do
81
+ requirement @requirement
82
+ end
83
+ }.should_not raise_exception
84
+ end
85
+
86
+ output.should have_requirement @summary, @requirement
87
+ end
88
+
89
+ it "displays the summary with block" do
90
+ output = capture_stdout do
91
+ lambda {
92
+ kata @summary do
93
+ requirement @requirement do
94
+ end
95
+ end
96
+ }.should_not raise_exception
97
+ end
98
+
99
+ output.should have_requirement @summary, @requirement
100
+ end
101
+ end
102
+
103
+ context "example" do
104
+ before :each do
105
+ @requirement = "Create a simple string calculator with a method add that takes a string argument"
106
+ @examples = [
107
+ %q{The string can contain 0, 1, 2 numbers for example "", "1", "1,2"},
108
+ "The method will return the sum of the digits",
109
+ "Then empty string will return 0",
110
+ ]
111
+ end
112
+
113
+ it "are displayed" do
114
+ capture_stdout do
115
+ lambda {
116
+ kata @summary do
117
+ requirement @requirement do
118
+ Kata::example @examples[0]
119
+ end
120
+ end
121
+ }.should_not raise_exception
122
+ end
123
+ end
124
+
125
+ it "are displayed with prompt" do
126
+ output = capture_stdout do
127
+ lambda {
128
+ kata @summary do
129
+ requirement @requirement do
130
+ Kata::example @examples[0]
131
+ Kata::example @examples[1]
132
+ Kata::example @examples[2]
133
+ end
134
+ end
135
+ }.should_not raise_exception
136
+ end
137
+
138
+ output.should have_examples @summary, @requirement, @examples
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,6 @@
1
+ $: << '.' << File.join(File.dirname(__FILE__), '..', 'lib')
2
+
3
+ require 'rspec'
4
+
5
+ Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
6
+
@@ -0,0 +1,11 @@
1
+ require 'stringio'
2
+
3
+ def capture_stdout
4
+ @@output = StringIO.new
5
+ @@input = StringIO.new("y\n")
6
+ yield
7
+ @@output.string.strip
8
+ ensure
9
+ @@output = $stdout
10
+ @@input = $stdin
11
+ end
@@ -0,0 +1,18 @@
1
+ RSpec::Matchers.define :have_summary do |expected|
2
+ match do |string|
3
+ string == expected
4
+ end
5
+ end
6
+
7
+ RSpec::Matchers.define :have_requirement do |summary, requirement|
8
+ match do |string|
9
+ string.split(/\n\n/)[0] == "#{summary}\n #{requirement}"
10
+ end
11
+ end
12
+
13
+ RSpec::Matchers.define :have_examples do |summary, requirement, examples|
14
+ example_str = examples.unshift('').join("\n - ")
15
+ match do |string|
16
+ string.split(/continue \(Y|n\)/)[0].strip == "#{summary}\n #{requirement}#{example_str}"
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kata
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
10
+ platform: ruby
11
+ authors:
12
+ - Wes
13
+ - Bailey
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-12-15 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: bundler
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ segments:
30
+ - 1
31
+ - 0
32
+ - 0
33
+ version: 1.0.0
34
+ type: :development
35
+ version_requirements: *id001
36
+ description: extended description
37
+ email: wes.bailey@insiderpages.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - Rakefile
46
+ - bin/autospec
47
+ - bin/autotest
48
+ - bin/htmldiff
49
+ - bin/ldiff
50
+ - bin/minitar
51
+ - bin/multigem
52
+ - bin/multiruby
53
+ - bin/multiruby_setup
54
+ - bin/rdebug
55
+ - bin/rspec
56
+ - bin/unit_diff
57
+ - bin/zentest
58
+ - lib/kata.rb
59
+ - spec/kata_spec.rb
60
+ - spec/spec_helper.rb
61
+ - spec/support/helpers/stdout_helper.rb
62
+ - spec/support/matchers/kata.rb
63
+ - README.md
64
+ has_rdoc: true
65
+ homepage: http://github.com/wbailey/kata
66
+ licenses: []
67
+
68
+ post_install_message:
69
+ rdoc_options: []
70
+
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ requirements: []
90
+
91
+ rubyforge_project:
92
+ rubygems_version: 1.3.7
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: A code kata DSL
96
+ test_files: []
97
+