Skip to content

Commit

Permalink
getting ready for github integration
Browse files Browse the repository at this point in the history
  • Loading branch information
wbailey committed Dec 22, 2010
1 parent 6f60c9a commit afc472f
Show file tree
Hide file tree
Showing 13 changed files with 183 additions and 74 deletions.
12 changes: 10 additions & 2 deletions Gemfile.lock
Expand Up @@ -9,7 +9,12 @@ GEM
columnize (0.3.2) columnize (0.3.2)
define_exception (0.0.3) define_exception (0.0.3)
diff-lcs (1.1.2) 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) linecache19 (0.5.11)
ruby_core_source (>= 0.1.4) ruby_core_source (>= 0.1.4)
rspec (2.2.0) rspec (2.2.0)
Expand All @@ -30,6 +35,9 @@ GEM
ruby-debug-base19 (>= 0.11.19) ruby-debug-base19 (>= 0.11.19)
ruby_core_source (0.1.4) ruby_core_source (0.1.4)
archive-tar-minitar (>= 0.5.2) archive-tar-minitar (>= 0.5.2)
text-format (1.0.0)
text-hyphen (~> 1.0.0)
text-hyphen (1.0.0)


PLATFORMS PLATFORMS
ruby ruby
Expand All @@ -38,6 +46,6 @@ DEPENDENCIES
autotest autotest
autotest-growl autotest-growl
define_exception define_exception
highline github
rspec (>= 2) rspec (>= 2)
ruby-debug19 ruby-debug19
4 changes: 4 additions & 0 deletions Rakefile
@@ -1,2 +1,6 @@
require 'bundler' require 'bundler'
Bundler::GemHelper.install_tasks Bundler::GemHelper.install_tasks

task :push do
system "gem push pkg/kata-0.2.0.gem"
end
16 changes: 16 additions & 0 deletions 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')
16 changes: 16 additions & 0 deletions 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')
16 changes: 16 additions & 0 deletions 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')
16 changes: 16 additions & 0 deletions 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')
2 changes: 1 addition & 1 deletion kata.gemspec
Expand Up @@ -2,7 +2,7 @@ require 'date'


Gem::Specification.new do |gem| Gem::Specification.new do |gem|
gem.name = 'kata' gem.name = 'kata'
gem.version = '0.2.0' gem.version = '0.3.0'
gem.date = Date.today.to_s gem.date = Date.today.to_s


gem.summary = 'A code kata DSL' gem.summary = 'A code kata DSL'
Expand Down
67 changes: 2 additions & 65 deletions lib/kata.rb
@@ -1,66 +1,3 @@
module Kata require 'kata/base'
@@times = []


def kata txt, lib = nil include Kata::Base
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
78 changes: 78 additions & 0 deletions 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
17 changes: 17 additions & 0 deletions 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
Binary file modified pkg/kata-0.2.0.gem
Binary file not shown.
11 changes: 6 additions & 5 deletions spec/kata_spec.rb
Expand Up @@ -4,6 +4,7 @@
describe "Kata DSL" do describe "Kata DSL" do
before :each do before :each do
@summary = 'sample summary' @summary = 'sample summary'
@display_summary = "#{@summary} Kata"
end end


context "kata" do context "kata" do
Expand Down Expand Up @@ -31,7 +32,7 @@
}.should_not raise_exception }.should_not raise_exception
end end


output.should have_summary @summary output.should have_summary @display_summary
end end


it "displays the summary with block" do it "displays the summary with block" do
Expand All @@ -42,7 +43,7 @@
}.should_not raise_exception }.should_not raise_exception
end end


output.should have_summary @summary output.should have_summary @display_summary
end end
end end


Expand Down Expand Up @@ -81,7 +82,7 @@
}.should_not raise_exception }.should_not raise_exception
end end


output.should have_requirement @summary, @requirement output.should have_requirement @display_summary, @requirement
end end


it "displays the summary with block" do it "displays the summary with block" do
Expand All @@ -94,7 +95,7 @@
}.should_not raise_exception }.should_not raise_exception
end end


output.should have_requirement @summary, @requirement output.should have_requirement @display_summary, @requirement
end end
end end


Expand Down Expand Up @@ -133,7 +134,7 @@
}.should_not raise_exception }.should_not raise_exception
end end


output.should have_examples @summary, @requirement, @examples output.should have_examples @display_summary, @requirement, @examples
end end
end end
end end
2 changes: 1 addition & 1 deletion spec/support/matchers/kata.rb
Expand Up @@ -13,6 +13,6 @@
RSpec::Matchers.define :have_examples do |summary, requirement, examples| RSpec::Matchers.define :have_examples do |summary, requirement, examples|
example_str = examples.unshift('').join("\n - ") example_str = examples.unshift('').join("\n - ")
match do |string| 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
end end

0 comments on commit afc472f

Please sign in to comment.