kata 1.0.10 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/bin/kata CHANGED
@@ -1,7 +1,10 @@
1
+ #!/bin/env ruby
1
2
  require 'kata'
3
+ require 'ostruct'
4
+ require 'optparse'
2
5
 
3
6
  def usage
4
- puts(<<EOF); exit 1
7
+ return <<EOF
5
8
  NAME
6
9
  kata - Ruby kata management
7
10
 
@@ -13,8 +16,9 @@ DESCRIPTION
13
16
  practice of writing code through repitition.
14
17
 
15
18
  PRIMARY COMMANDS
16
- kata setup file
17
- Setup a github repo for the kata development session
19
+ kata setup file [repository]
20
+ Setup a github repo for the kata development session. Use a repository
21
+ if it is provided and do not create a new one
18
22
 
19
23
  kata take file
20
24
  Start a kata development session
@@ -27,19 +31,30 @@ PRIMARY COMMANDS
27
31
  EOF
28
32
  end
29
33
 
30
- begin
31
- argument = ARGV[0].downcase.to_sym
32
- rescue
33
- usage
34
- end
34
+ options = OpenStruct.new(
35
+ {
36
+ :repo => true,
37
+ }
38
+ )
39
+
40
+ OptionParser.new do |opts|
41
+ opts.banner = usage
42
+
43
+ opts.on('-n', '--no-repo', 'Do not create a new repository') do
44
+ options.repo = false
45
+ end
46
+ end.parse!
47
+
48
+ options.action = ARGV.shift.downcase.to_sym
49
+ options.file = ARGV.shift
35
50
 
36
- case argument
51
+ case options.action
37
52
  when :setup
38
- raise ArgumentError unless ARGV[1] && File.exists?(ARGV[1])
53
+ raise ArgumentError unless options.file && File.exists?(options.file)
39
54
 
40
55
  name = nil
41
56
 
42
- File.open(ARGV[1]).each do |line|
57
+ File.open(options.file).each do |line|
43
58
  if line.match /^kata *\"([^\"]*)\" *do$/
44
59
  name = $1
45
60
  break
@@ -48,11 +63,11 @@ case argument
48
63
 
49
64
  setup = Kata::Setup.new name
50
65
  setup.build_tree
51
- setup.create_repo rescue Exception
66
+ setup.create_repo(options) rescue Exception
52
67
  when :take
53
- load ARGV[1]
68
+ load options.file
54
69
  when :version
55
70
  puts "kata #{Kata::VERSION}"
56
71
  else
57
- usage
72
+ puts usage
58
73
  end
@@ -11,7 +11,7 @@ module Kata
11
11
  self.repo_name = kata_name
12
12
  end
13
13
 
14
- def create_repo
14
+ def create_repo options
15
15
  # Setup from github configuration
16
16
  raise Exception, 'Git not installed' unless system 'which git > /dev/null'
17
17
 
@@ -31,24 +31,31 @@ module Kata
31
31
  repo_params = "-d 'name=#{repo_name}' -d 'description=code+kata+repo'"
32
32
 
33
33
  # Create the repo on github
34
- print 'Creating github repo...'
35
- raise SystemCallError, 'unable to use curl to create repo on github' unless system <<-EOF
36
- curl -s #{user_string} #{repo_params} #{github.url}repos/create 2>&1 > /dev/null;
37
- EOF
38
- puts 'complete'
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
39
41
 
40
42
  # publish to github
41
43
 
42
44
  print 'creating files for repo and initializing...'
43
- raise SystemCallError, 'unable to publish repo to github' unless system <<-EOF
44
- cd #{repo_name};
45
- touch results.txt
46
- git init 2>&1 > /dev/null;
47
- git add README .rspec results.txt lib/ spec/ 2>&1 > /dev/null;
48
- git commit -m 'starting kata' 2>&1 > /dev/null;
49
- git remote add origin git@github.com:#{github.user}/#{repo_name}.git 2>&1 > /dev/null;
50
- git push origin master 2> /dev/null
51
- EOF
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
+
52
59
  puts 'done'
53
60
  puts "You can now change directories to #{repo_name} and take your kata"
54
61
  end
@@ -95,7 +102,7 @@ require '#{use_kata_name}'
95
102
  describe #{class_name} do
96
103
  describe "new" do
97
104
  it "should instantiate" do
98
- lambda {
105
+ expect {
99
106
  #{class_name}.new
100
107
  }.should_not raise_exception
101
108
  end
@@ -1,3 +1,3 @@
1
1
  module Kata
2
- VERSION = '1.0.10'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -2,15 +2,15 @@ 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}"
12
12
  end
13
-
13
+
14
14
  it "should run the kata" do
15
15
  File.open('test_sample.rb', 'w') do |file|
16
16
  file.write <<-EOF
metadata CHANGED
@@ -1,39 +1,41 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: kata
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
4
5
  prerelease:
5
- version: 1.0.10
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Wes
9
9
  - Bailey
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
-
14
- date: 2011-10-05 00:00:00 -07:00
15
- default_executable:
16
- dependencies:
17
- - !ruby/object:Gem::Dependency
13
+ date: 2012-05-03 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
18
16
  name: bundler
19
- prerelease: false
20
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
21
18
  none: false
22
- requirements:
23
- - - ">="
24
- - !ruby/object:Gem::Version
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
25
22
  version: 1.0.0
26
23
  type: :development
27
- version_requirements: *id001
28
- description: This DSL provides an easy way for you to write a code kata for pairing exercises or individual testing
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: 1.0.0
31
+ description: This DSL provides an easy way for you to write a code kata for pairing
32
+ exercises or individual testing
29
33
  email: baywes@gmail.com
30
- executables:
34
+ executables:
31
35
  - kata
32
36
  extensions: []
33
-
34
37
  extra_rdoc_files: []
35
-
36
- files:
38
+ files:
37
39
  - lib/kata/base.rb
38
40
  - lib/kata/setup.rb
39
41
  - lib/kata/version.rb
@@ -45,36 +47,33 @@ files:
45
47
  - spec/spec_helper.rb
46
48
  - spec/support/helpers/stdout_helper.rb
47
49
  - spec/support/matchers/kata.rb
48
- - bin/kata
49
- has_rdoc: true
50
+ - !binary |-
51
+ YmluL2thdGE=
50
52
  homepage: http://github.com/wbailey/kata
51
53
  licenses: []
52
-
53
54
  post_install_message:
54
55
  rdoc_options: []
55
-
56
- require_paths:
56
+ require_paths:
57
57
  - lib
58
- required_ruby_version: !ruby/object:Gem::Requirement
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
59
  none: false
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: "0"
64
- required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  none: false
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: "0"
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
70
  requirements: []
71
-
72
71
  rubyforge_project:
73
- rubygems_version: 1.5.0
72
+ rubygems_version: 1.8.22
74
73
  signing_key:
75
74
  specification_version: 3
76
75
  summary: A code kata DSL
77
- test_files:
76
+ test_files:
78
77
  - spec/kata_base_spec.rb
79
78
  - spec/kata_setup_spec.rb
80
79
  - spec/kata_spec.rb