kata 1.1.0 → 1.3.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/bin/kata CHANGED
@@ -34,6 +34,7 @@ end
34
34
  options = OpenStruct.new(
35
35
  {
36
36
  :repo => true,
37
+ :language => 'ruby',
37
38
  }
38
39
  )
39
40
 
@@ -43,6 +44,10 @@ OptionParser.new do |opts|
43
44
  opts.on('-n', '--no-repo', 'Do not create a new repository') do
44
45
  options.repo = false
45
46
  end
47
+
48
+ opts.on('-l[OPTIONAL]', '--language[=OPTIONAL]', 'Setup the kata file tree using the specified language') do |lang|
49
+ options.language = lang
50
+ end
46
51
  end.parse!
47
52
 
48
53
  options.action = ARGV.shift.downcase.to_sym
@@ -61,8 +66,8 @@ case options.action
61
66
  end
62
67
  end
63
68
 
64
- setup = Kata::Setup.new name
65
- setup.build_tree
69
+ setup = Kata::Setup::Base.new(name)
70
+ setup.build_tree(options.language)
66
71
  setup.create_repo(options) rescue Exception
67
72
  when :take
68
73
  load options.file
data/lib/kata.rb CHANGED
@@ -1,3 +1,4 @@
1
- require 'kata/setup'
1
+ require 'kata/setup/base'
2
+ require 'kata/setup/ruby'
2
3
  require 'kata/base'
3
4
  require 'kata/version'
data/lib/kata/base.rb CHANGED
@@ -1,5 +1,9 @@
1
+ require 'command_line_reporter'
2
+
1
3
  module Kata
2
4
  module Base
5
+ include CommandLineReporter
6
+
3
7
  @@times = []
4
8
 
5
9
  def kata(txt, lib = nil)
@@ -25,6 +29,8 @@ module Kata
25
29
 
26
30
  puts
27
31
 
32
+ system %Q{git add . && git commit -m '#{txt}' > /dev/null} rescue Exception
33
+
28
34
  elapsed = Time.now - start
29
35
  @@times << {:title => txt, :time => elapsed}
30
36
 
@@ -55,14 +61,27 @@ module Kata
55
61
  [use/3600, use/60 % 60, use % 60].map {|v| v.to_s.rjust(2,'0')}.join(':')
56
62
  end
57
63
 
58
- File.open('results.txt', 'w') do |file|
59
- file.puts "\n\n#{title}"
60
- file.puts @@times.inject('') {|s,p| s << "- #{p[:title][0,70].ljust(70, ' ')} #{formatter.call(p[:time]).rjust(10,' ')}\n"}
61
- file.puts '-' * 70 + ' ' * 5 + '-' * 8
62
- file.puts "Total Time taking #{@kata_name} kata: ".ljust(70, ' ') + ' ' * 5 + formatter.call(@@times.inject(0) {|s,h| s += h[:time]})
64
+ suppress_output
65
+
66
+ table :border => true do
67
+ row :header => true do
68
+ column 'Requirement', :color => 'red', :width => 80
69
+ column 'Time', :color => 'red', :width => 8
70
+ end
71
+
72
+ @@times.each do |t|
73
+ row do
74
+ column t[:title]
75
+ column formatter.call(t[:time])
76
+ end
77
+ end
63
78
  end
64
79
 
65
- File.open('results.txt', 'r').each { |line| puts line}
80
+ report = capture_output
81
+
82
+ File.open('report.txt', 'w').write( report )
83
+
84
+ puts report
66
85
  end
67
86
 
68
87
  exit 1 unless status
@@ -0,0 +1,76 @@
1
+ require 'fileutils'
2
+ require 'ostruct'
3
+
4
+ module Kata
5
+ module Setup
6
+ class Base
7
+ attr_accessor :kata_name
8
+ attr_reader :repo_name
9
+
10
+ def initialize(kata_name = 'kata')
11
+ self.kata_name = kata_name
12
+ self.repo_name = kata_name
13
+ end
14
+
15
+ def create_repo options
16
+ # Setup from github configuration
17
+ raise Exception, 'Git not installed' unless system 'which git > /dev/null'
18
+
19
+ github = OpenStruct.new :url => 'http://github.com/api/v2/json/'
20
+
21
+ github_user, shell_user = %x{git config --get github.user}.chomp, ENV['USER']
22
+
23
+ github.user = github_user.empty? ? shell_user : github_user
24
+
25
+ raise Exception, 'Unable to determine github user' if github.user.empty?
26
+
27
+ github.token = %x{git config --get github.token}.chomp
28
+
29
+ raise Exception, 'Unable to determine github api token' if github.token.empty?
30
+
31
+ user_string = "-u '#{github.user}/token:#{github.token}'"
32
+ repo_params = "-d 'name=#{repo_name}' -d 'description=code+kata+repo'"
33
+
34
+ # Create the repo on github
35
+ if options.repo
36
+ print 'Creating github repo...'
37
+ raise SystemCallError, 'unable to use curl to create repo on github' unless system <<-EOF
38
+ curl -s #{user_string} #{repo_params} #{github.url}repos/create 2>&1 > /dev/null;
39
+ EOF
40
+ puts 'complete'
41
+ end
42
+
43
+ # publish to github
44
+
45
+ print 'creating files for repo and initializing...'
46
+
47
+ cmd = "cd #{repo_name};"
48
+ if options.repo
49
+ cmd << "git init 2>&1 > /dev/null;"
50
+ cmd << "git add README .rspec lib/ spec/ 2>&1 > /dev/null;"
51
+ else
52
+ cmd << "git add #{ENV['PWD']}/#{repo_name};"
53
+ end
54
+ cmd << "git commit -m 'starting kata' 2>&1 > /dev/null;"
55
+ cmd << "git remote add origin git@github.com:#{github.user}/#{repo_name}.git 2>&1 > /dev/null;" if options.repo
56
+ cmd << 'git push origin master 2> /dev/null'
57
+
58
+ raise SystemCallError, 'unable to add files to github repo' unless system(cmd)
59
+
60
+ puts 'done'
61
+ puts "You can now change directories to #{repo_name} and take your kata"
62
+ end
63
+
64
+ def repo_name=(kata_name)
65
+ @repo_name = "#{kata_name.gsub(/( |-)\1?/, '_')}-#{Time.now.strftime('%Y-%m-%d-%H%M%S')}".downcase
66
+ end
67
+
68
+ def build_tree(type = 'ruby')
69
+ case type
70
+ when 'ruby'
71
+ Kata::Setup::Ruby.new(kata_name).build_tree
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,62 @@
1
+ require 'kata/setup/base'
2
+
3
+ module Kata
4
+ module Setup
5
+ class Ruby < Kata::Setup::Base
6
+ def build_tree
7
+ %W{#{repo_name}/lib #{repo_name}/spec/support/helpers #{repo_name}/spec/support/matchers}.each {|path| FileUtils.mkdir_p path}
8
+
9
+ use_kata_name = kata_name.gsub(/( |-)\1?/, '_').downcase
10
+ class_name = kata_name.split(/ |-|_/).map(&:capitalize).join
11
+
12
+ # create the README file so github is happy
13
+ File.open(File.join(repo_name, 'README'), 'w') {|f| f.write <<EOF}
14
+ Leveling up my ruby awesomeness!
15
+ EOF
16
+
17
+ # create the base class file
18
+ File.open(File.join(repo_name, 'lib', "#{use_kata_name}.rb"), 'w') {|f| f.write <<EOF}
19
+ class #{class_name}
20
+ end
21
+ EOF
22
+ # create the .rspec file
23
+ File.open(File.join(repo_name, '.rspec'), 'w') {|f| f.write <<EOF}
24
+ --color --format d
25
+ EOF
26
+
27
+ # create the spec_helper.rb file
28
+ File.open(File.join(repo_name, 'spec', 'spec_helper.rb'), 'w') {|f| f.write <<EOF}
29
+ $: << '.' << File.join(File.dirname(__FILE__), '..', 'lib')
30
+
31
+ require 'rspec'
32
+
33
+ Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
34
+ EOF
35
+
36
+ # create a working spec file for the kata
37
+ File.open(File.join(repo_name, 'spec', "#{use_kata_name}_spec.rb"), 'w') {|f| f.write <<EOF}
38
+ require 'spec_helper'
39
+ require '#{use_kata_name}'
40
+
41
+ describe #{class_name} do
42
+ describe "new" do
43
+ it "should instantiate" do
44
+ expect {
45
+ #{class_name}.new
46
+ }.should_not raise_exception
47
+ end
48
+ end
49
+ end
50
+ EOF
51
+ # stub out a custom matchers file
52
+ File.open(File.join(repo_name, 'spec', 'support', 'matchers', "#{use_kata_name}.rb"), 'w') {|f| f.write <<EOF}
53
+ RSpec::Matchers.define :your_method do |expected|
54
+ match do |your_match|
55
+ #your_match.method_on_object_to_execute == expected
56
+ end
57
+ end
58
+ EOF
59
+ end
60
+ end
61
+ end
62
+ end
data/lib/kata/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kata
2
- VERSION = '1.1.0'
2
+ VERSION = '1.3.0'
3
3
  end
data/spec/kata_spec.rb CHANGED
@@ -2,10 +2,10 @@ require 'spec_helper'
2
2
  require 'kata/version'
3
3
 
4
4
  describe 'kata shell' do
5
- #it "should exit with status 1" do
6
- #system "ruby -I lib bin/kata 1> /dev/null"
7
- #$?.exitstatus.should == 1
8
- #end
5
+ it "should exit with status 1" do
6
+ system "ruby -I lib bin/kata 1> /dev/null"
7
+ $?.exitstatus.should == 1
8
+ end
9
9
 
10
10
  it "should display the version" do
11
11
  %x{ruby -I lib bin/kata version}.chomp.should == "kata #{Kata::VERSION}"
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+ require 'kata/setup/base'
3
+ require 'kata/setup/ruby'
4
+ require 'fileutils'
5
+
6
+ module Kata
7
+ module Setup
8
+ describe Base do
9
+ #subject {Kata::Setup::Base.new}
10
+
11
+ describe "new" do
12
+ it "define a repo name" do
13
+ subject.repo_name.should match /kata-#{Time.now.strftime('%Y-%m-%d')}-\d{6}/
14
+ end
15
+
16
+ it "defines the kata name" do
17
+ s = Kata::Setup::Base.new 'my-kata'
18
+ s.kata_name.should == 'my-kata'
19
+ end
20
+ end
21
+
22
+ describe "build_tree" do
23
+ it "creates files" do
24
+ expect {
25
+ subject.build_tree
26
+ }.should_not raise_exception
27
+
28
+ Dir[File.join(subject.repo_name, '**', '*.rb')].size.should == 4
29
+ Dir[File.join(subject.repo_name, 'README')].size.should == 1
30
+ Dir[File.join(subject.repo_name, '.rspec')].size.should == 1
31
+
32
+ FileUtils.remove_entry_secure subject.repo_name
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kata
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-05-03 00:00:00.000000000 Z
13
+ date: 2012-05-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
17
- requirement: !ruby/object:Gem::Requirement
17
+ requirement: &2168560200 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,12 +22,18 @@ dependencies:
22
22
  version: 1.0.0
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
25
+ version_requirements: *2168560200
26
+ - !ruby/object:Gem::Dependency
27
+ name: command_line_reporter
28
+ requirement: &2168559680 !ruby/object:Gem::Requirement
26
29
  none: false
27
30
  requirements:
28
31
  - - ! '>='
29
32
  - !ruby/object:Gem::Version
30
- version: 1.0.0
33
+ version: 3.2.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *2168559680
31
37
  description: This DSL provides an easy way for you to write a code kata for pairing
32
38
  exercises or individual testing
33
39
  email: baywes@gmail.com
@@ -37,13 +43,14 @@ extensions: []
37
43
  extra_rdoc_files: []
38
44
  files:
39
45
  - lib/kata/base.rb
40
- - lib/kata/setup.rb
46
+ - lib/kata/setup/base.rb
47
+ - lib/kata/setup/ruby.rb
41
48
  - lib/kata/version.rb
42
49
  - lib/kata.rb
43
50
  - README.md
44
51
  - spec/kata_base_spec.rb
45
- - spec/kata_setup_spec.rb
46
52
  - spec/kata_spec.rb
53
+ - spec/setup/base_spec.rb
47
54
  - spec/spec_helper.rb
48
55
  - spec/support/helpers/stdout_helper.rb
49
56
  - spec/support/matchers/kata.rb
@@ -61,6 +68,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
61
68
  - - ! '>='
62
69
  - !ruby/object:Gem::Version
63
70
  version: '0'
71
+ segments:
72
+ - 0
73
+ hash: -448375996502687545
64
74
  required_rubygems_version: !ruby/object:Gem::Requirement
65
75
  none: false
66
76
  requirements:
@@ -69,14 +79,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
79
  version: '0'
70
80
  requirements: []
71
81
  rubyforge_project:
72
- rubygems_version: 1.8.22
82
+ rubygems_version: 1.8.15
73
83
  signing_key:
74
84
  specification_version: 3
75
85
  summary: A code kata DSL
76
86
  test_files:
77
87
  - spec/kata_base_spec.rb
78
- - spec/kata_setup_spec.rb
79
88
  - spec/kata_spec.rb
89
+ - spec/setup/base_spec.rb
80
90
  - spec/spec_helper.rb
81
91
  - spec/support/helpers/stdout_helper.rb
82
92
  - spec/support/matchers/kata.rb
data/lib/kata/setup.rb DELETED
@@ -1,122 +0,0 @@
1
- require 'fileutils'
2
- require 'ostruct'
3
-
4
- module Kata
5
- class Setup
6
- attr_accessor :kata_name
7
- attr_reader :repo_name
8
-
9
- def initialize(kata_name = 'kata')
10
- self.kata_name = kata_name
11
- self.repo_name = kata_name
12
- end
13
-
14
- def create_repo options
15
- # Setup from github configuration
16
- raise Exception, 'Git not installed' unless system 'which git > /dev/null'
17
-
18
- github = OpenStruct.new :url => 'http://github.com/api/v2/json/'
19
-
20
- github_user, shell_user = %x{git config --get github.user}.chomp, ENV['USER']
21
-
22
- github.user = github_user.empty? ? shell_user : github_user
23
-
24
- raise Exception, 'Unable to determine github user' if github.user.empty?
25
-
26
- github.token = %x{git config --get github.token}.chomp
27
-
28
- raise Exception, 'Unable to determine github api token' if github.token.empty?
29
-
30
- user_string = "-u '#{github.user}/token:#{github.token}'"
31
- repo_params = "-d 'name=#{repo_name}' -d 'description=code+kata+repo'"
32
-
33
- # Create the repo on github
34
- if options.repo
35
- print 'Creating github repo...'
36
- raise SystemCallError, 'unable to use curl to create repo on github' unless system <<-EOF
37
- curl -s #{user_string} #{repo_params} #{github.url}repos/create 2>&1 > /dev/null;
38
- EOF
39
- puts 'complete'
40
- end
41
-
42
- # publish to github
43
-
44
- print 'creating files for repo and initializing...'
45
-
46
- cmd = "cd #{repo_name};"
47
- if options.repo
48
- cmd << "git init 2>&1 > /dev/null;"
49
- cmd << "git add README .rspec lib/ spec/ 2>&1 > /dev/null;"
50
- else
51
- cmd << "git add #{ENV['PWD']}/#{repo_name};"
52
- end
53
- cmd << "git commit -m 'starting kata' 2>&1 > /dev/null;"
54
- cmd << "git remote add origin git@github.com:#{github.user}/#{repo_name}.git 2>&1 > /dev/null;" if options.repo
55
- cmd << 'git push origin master 2> /dev/null'
56
-
57
- raise SystemCallError, 'unable to add files to github repo' unless system(cmd)
58
-
59
- puts 'done'
60
- puts "You can now change directories to #{repo_name} and take your kata"
61
- end
62
-
63
- def repo_name=(kata_name)
64
- @repo_name = "#{kata_name.gsub(/( |-)\1?/, '_')}-#{Time.now.strftime('%Y-%m-%d-%H%M%S')}".downcase
65
- end
66
-
67
- def build_tree
68
- %W{#{repo_name}/lib #{repo_name}/spec/support/helpers #{repo_name}/spec/support/matchers}.each {|path| FileUtils.mkdir_p path}
69
-
70
- use_kata_name = kata_name.gsub(/( |-)\1?/, '_').downcase
71
- class_name = kata_name.split(/ |-|_/).map(&:capitalize).join
72
-
73
- # create the README file so github is happy
74
- File.open(File.join(repo_name, 'README'), 'w') {|f| f.write <<EOF}
75
- Leveling up my ruby awesomeness!
76
- EOF
77
-
78
- # create the base class file
79
- File.open(File.join(repo_name, 'lib', "#{use_kata_name}.rb"), 'w') {|f| f.write <<EOF}
80
- class #{class_name}
81
- end
82
- EOF
83
- # create the .rspec file
84
- File.open(File.join(repo_name, '.rspec'), 'w') {|f| f.write <<EOF}
85
- --color --format d
86
- EOF
87
-
88
- # create the spec_helper.rb file
89
- File.open(File.join(repo_name, 'spec', 'spec_helper.rb'), 'w') {|f| f.write <<EOF}
90
- $: << '.' << File.join(File.dirname(__FILE__), '..', 'lib')
91
-
92
- require 'rspec'
93
-
94
- Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
95
- EOF
96
-
97
- # create a working spec file for the kata
98
- File.open(File.join(repo_name, 'spec', "#{use_kata_name}_spec.rb"), 'w') {|f| f.write <<EOF}
99
- require 'spec_helper'
100
- require '#{use_kata_name}'
101
-
102
- describe #{class_name} do
103
- describe "new" do
104
- it "should instantiate" do
105
- expect {
106
- #{class_name}.new
107
- }.should_not raise_exception
108
- end
109
- end
110
- end
111
- EOF
112
- # stub out a custom matchers file
113
- File.open(File.join(repo_name, 'spec', 'support', 'matchers', "#{use_kata_name}.rb"), 'w') {|f| f.write <<EOF}
114
- RSpec::Matchers.define :your_method do |expected|
115
- match do |your_match|
116
- #your_match.method_on_object_to_execute == expected
117
- end
118
- end
119
- EOF
120
- end
121
- end
122
- end
@@ -1,34 +0,0 @@
1
- require 'spec_helper'
2
- require 'kata/setup'
3
- require 'fileutils'
4
-
5
- module Kata
6
- describe Setup do
7
- subject {Kata::Setup.new}
8
-
9
- describe "new" do
10
- it "define a repo name" do
11
- subject.repo_name.should match /kata-#{Time.now.strftime('%Y-%m-%d')}-\d{6}/
12
- end
13
-
14
- it "defines the kata name" do
15
- s = Kata::Setup.new 'my-kata'
16
- s.kata_name.should == 'my-kata'
17
- end
18
- end
19
-
20
- describe "build_tree" do
21
- it "creates files" do
22
- lambda {
23
- subject.build_tree
24
- }.should_not raise_exception
25
-
26
- Dir[File.join(subject.repo_name, '**', '*.rb')].size.should == 4
27
- Dir[File.join(subject.repo_name, 'README')].size.should == 1
28
- Dir[File.join(subject.repo_name, '.rspec')].size.should == 1
29
-
30
- FileUtils.remove_entry_secure subject.repo_name
31
- end
32
- end
33
- end
34
- end