diff --git a/Gemfile.lock b/Gemfile.lock index 46c3894..f56b8a1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,7 +9,12 @@ GEM columnize (0.3.2) define_exception (0.0.3) diff-lcs (1.1.2) - highline (1.6.1) + github (0.4.5) + highline (~> 1.5.1) + json (>= 1.2.0) + text-format (>= 1.0.0) + highline (1.5.2) + json (1.4.6) linecache19 (0.5.11) ruby_core_source (>= 0.1.4) rspec (2.2.0) @@ -30,6 +35,9 @@ GEM ruby-debug-base19 (>= 0.11.19) ruby_core_source (0.1.4) archive-tar-minitar (>= 0.5.2) + text-format (1.0.0) + text-hyphen (~> 1.0.0) + text-hyphen (1.0.0) PLATFORMS ruby @@ -38,6 +46,6 @@ DEPENDENCIES autotest autotest-growl define_exception - highline + github rspec (>= 2) ruby-debug19 diff --git a/Rakefile b/Rakefile index 14cfe0b..4e81160 100644 --- a/Rakefile +++ b/Rakefile @@ -1,2 +1,6 @@ require 'bundler' Bundler::GemHelper.install_tasks + +task :push do + system "gem push pkg/kata-0.2.0.gem" +end diff --git a/bin/edit_json.rb b/bin/edit_json.rb new file mode 100755 index 0000000..cd55a1c --- /dev/null +++ b/bin/edit_json.rb @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby +# +# This file was generated by Bundler. +# +# The application 'edit_json.rb' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +require 'rubygems' +require 'bundler/setup' + +load Gem.bin_path('json', 'edit_json.rb') diff --git a/bin/gh b/bin/gh new file mode 100755 index 0000000..263ab50 --- /dev/null +++ b/bin/gh @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby +# +# This file was generated by Bundler. +# +# The application 'gh' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +require 'rubygems' +require 'bundler/setup' + +load Gem.bin_path('github', 'gh') diff --git a/bin/github b/bin/github new file mode 100755 index 0000000..7b3820c --- /dev/null +++ b/bin/github @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby +# +# This file was generated by Bundler. +# +# The application 'github' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +require 'rubygems' +require 'bundler/setup' + +load Gem.bin_path('github', 'github') diff --git a/bin/prettify_json.rb b/bin/prettify_json.rb new file mode 100755 index 0000000..b4bfe28 --- /dev/null +++ b/bin/prettify_json.rb @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby +# +# This file was generated by Bundler. +# +# The application 'prettify_json.rb' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +require 'rubygems' +require 'bundler/setup' + +load Gem.bin_path('json', 'prettify_json.rb') diff --git a/kata.gemspec b/kata.gemspec index 8f8e184..9fa9182 100644 --- a/kata.gemspec +++ b/kata.gemspec @@ -2,7 +2,7 @@ require 'date' Gem::Specification.new do |gem| gem.name = 'kata' - gem.version = '0.2.0' + gem.version = '0.3.0' gem.date = Date.today.to_s gem.summary = 'A code kata DSL' diff --git a/lib/kata.rb b/lib/kata.rb index e11c255..d4db2a8 100644 --- a/lib/kata.rb +++ b/lib/kata.rb @@ -1,66 +1,3 @@ -module Kata - @@times = [] +require 'kata/base' - def kata txt, lib = nil - puts txt - yield if block_given? - complete - end - - def requirement txt - puts indent + txt - - start = Time.now - - yield if block_given? - - rsp = ask "\ncontinue (Y|n): ", 'y' - - puts - - elapsed = Time.now - start - @@times << {:title => txt, :time => elapsed} - - complete false if rsp.downcase == 'n' - end - - def example txt - puts indent + '- ' + txt - end - - private - - def ask prompt, default - print prompt - $stdin.gets.chomp || default - end - - def complete status = true - if @@times.size > 0 - title = status ? 'Congratulations!' : 'You completed the following:' - - formatter = lambda do |sec| - use = sec.round - [use/3600, use/60 % 60, use % 60].map {|v| v.to_s.rjust(2,'0')}.join(':') - end - - puts "\n\n#{title}" - puts @@times.inject('') {|s,p| s << "- #{p[:title][0,70].ljust(70, ' ')} #{formatter.call(p[:time]).rjust(10,' ')}\n"} - puts '-' * 70 + ' ' * 5 + '-' * 8 - puts 'Total Time taking Kata'.ljust(70, ' ') + ' ' * 5 + formatter.call(@@times.inject(0) {|s,h| s += h[:time]}) - end - - exit 1 unless status - end - - def ancestry - caller.grep(/#{Regexp.escape(__FILE__)}/).map {|v| v.match(/^[^`]*`([^']*)'/)[1]} - end - - def indent - nesting = ancestry.size - 2 - ' ' * (3 * nesting) - end -end - -include Kata +include Kata::Base diff --git a/lib/kata/base.rb b/lib/kata/base.rb new file mode 100644 index 0000000..55ae39e --- /dev/null +++ b/lib/kata/base.rb @@ -0,0 +1,78 @@ +module Kata + module Base + @@times = [] + + def kata txt, lib = nil + @kata_name = txt + puts "#{@kata_name} Kata" + yield if block_given? + complete + end + + def context txt + puts indent + txt + yield if block_given? + end + + def requirement txt + puts indent + txt + + start = Time.now + + yield if block_given? + + rsp = ask "\ncompleted (Y|n): ", 'y' + + puts + + elapsed = Time.now - start + @@times << {:title => txt, :time => elapsed} + + complete false if rsp.downcase == 'n' + end + + def example txt + puts indent + '- ' + txt + end + + def detail txt + puts indent + '- ' + txt + end + + private + + def ask prompt, default + print prompt + $stdin.gets.chomp || default + end + + def complete status = true + if @@times.size > 0 + title = status ? 'Congratulations!' : 'You completed the following:' + + formatter = lambda do |sec| + use = sec.round + [use/3600, use/60 % 60, use % 60].map {|v| v.to_s.rjust(2,'0')}.join(':') + end + + puts "\n\n#{title}" + puts @@times.inject('') {|s,p| s << "- #{p[:title][0,70].ljust(70, ' ')} #{formatter.call(p[:time]).rjust(10,' ')}\n"} + puts '-' * 70 + ' ' * 5 + '-' * 8 + puts "Total Time taking #{@kata_name} kata: ".ljust(70, ' ') + ' ' * 5 + formatter.call(@@times.inject(0) {|s,h| s += h[:time]}) + end + + exit 1 unless status + end + + def ancestry + caller.grep(/#{Regexp.escape(__FILE__)}/).map {|v| v.match(/^[^`]*`([^']*)'/)[1]} + end + + def indent + nesting = ancestry.size - 2 + ' ' * (3 * nesting) + end + end +end + +include Kata::Base diff --git a/lib/kata/setup.rb b/lib/kata/setup.rb new file mode 100644 index 0000000..4cb0a2c --- /dev/null +++ b/lib/kata/setup.rb @@ -0,0 +1,17 @@ +module Kata + module Setup + def build_repo(kata_name) + build_tree(kata_name) + end + + def build_tree(kata_name) + repo = 'kata-' + Time.now.strftime('%Y-%m-%d-%H:%M') + %W{#{repo}/lib #{repo}/spec/support/helpers #{repo}/spec/support/matchers}.each {|path| mkdir_p path} + end + + # FileUtils really depends on rmagick? grrr + def mkdir_p(path) + %x{mkdir -p #{path}} + end + end +end diff --git a/pkg/kata-0.2.0.gem b/pkg/kata-0.2.0.gem index 49e805d..5ab7553 100644 Binary files a/pkg/kata-0.2.0.gem and b/pkg/kata-0.2.0.gem differ diff --git a/spec/kata_spec.rb b/spec/kata_spec.rb index f101d8e..7f0cfca 100644 --- a/spec/kata_spec.rb +++ b/spec/kata_spec.rb @@ -4,6 +4,7 @@ describe "Kata DSL" do before :each do @summary = 'sample summary' + @display_summary = "#{@summary} Kata" end context "kata" do @@ -31,7 +32,7 @@ }.should_not raise_exception end - output.should have_summary @summary + output.should have_summary @display_summary end it "displays the summary with block" do @@ -42,7 +43,7 @@ }.should_not raise_exception end - output.should have_summary @summary + output.should have_summary @display_summary end end @@ -81,7 +82,7 @@ }.should_not raise_exception end - output.should have_requirement @summary, @requirement + output.should have_requirement @display_summary, @requirement end it "displays the summary with block" do @@ -94,7 +95,7 @@ }.should_not raise_exception end - output.should have_requirement @summary, @requirement + output.should have_requirement @display_summary, @requirement end end @@ -133,7 +134,7 @@ }.should_not raise_exception end - output.should have_examples @summary, @requirement, @examples + output.should have_examples @display_summary, @requirement, @examples end end end diff --git a/spec/support/matchers/kata.rb b/spec/support/matchers/kata.rb index 4d1de3c..c7d4a2f 100644 --- a/spec/support/matchers/kata.rb +++ b/spec/support/matchers/kata.rb @@ -13,6 +13,6 @@ RSpec::Matchers.define :have_examples do |summary, requirement, examples| example_str = examples.unshift('').join("\n - ") match do |string| - string.split(/continue \(Y|n\)/)[0].strip == "#{summary}\n #{requirement}#{example_str}" + string.split(/completed \(Y|n\)/)[0].strip == "#{summary}\n #{requirement}#{example_str}" end end