kata 1.3.3 → 1.4.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/README.md CHANGED
@@ -1,16 +1,22 @@
1
- ## Kata
1
+ ## Kata [![Build Status](https://travis-ci.org/wbailey/kata.png?branch=master)](https://travis-ci.org/wbailey/kata) [![Code Climate](https://codeclimate.com/github/wbailey/kata.png)](https://codeclimate.com/github/wbailey/kata) [![Gem Version](https://badge.fury.io/rb/kata.png)](http://badge.fury.io/rb/kata)
2
2
 
3
3
  A kata is defined as an exercise in programming which helps hone your skills through practice and
4
- repetition. Authoring katas is done in blogs but you can't really test yourself.
5
- [coderdojo](http://www.coderdojo.com) is a fine website and provides a great way to get involved
6
- with katas. The purpose of this gem is to provide a work environment based way of interacting.
7
- It provides several facilities for authoring and taking katas that allow you to work in your own
8
- environment. The inspiration for this gem came from my friend [Nick
9
- Hengeveld](https://github.com/nickh) who first introduced me to the concept of a kata several years
10
- ago.
4
+ repetition. Authoring katas is done in blogs but you can't really test yourself. Dave Thomas
5
+ [@pragdave](https://twitter.com/pragdave), started this movement for programming. He recently
6
+ created [codekata.com](http://www.codekata.com), which is a comprehensive archives of all of the
7
+ katas he has written. Another fine site is [coderdojo](http://www.coderdojo.com). It provides a
8
+ great way to get involved with katas.
9
+
10
+ The purpose of this gem is to provide a work environment based way of interacting. It provides
11
+ several facilities for authoring and taking katas that allow you to work in your own environment.
12
+ The inspiration for this gem came from my friend [Nick Hengeveld](https://github.com/nickh) who
13
+ first introduced me to the concept of a kata several years ago and provided feedback during it's
14
+ development.
11
15
 
12
16
  ### Installation
13
17
 
18
+ NOTE: Requires version 1.9.3 and higher
19
+
14
20
  It is up on rubygems.org so add it to your project bundle:
15
21
 
16
22
  gem kata
@@ -59,6 +65,8 @@ The [Wiki](https://github.com/wbailey/kata/wiki) has all of the documentation ne
59
65
  * requirement(string, &block)
60
66
  * detail(string)
61
67
  * example(string)
68
+ * questions(&block)
69
+ * question(string)
62
70
 
63
71
  ### Contributors
64
72
 
@@ -45,6 +45,17 @@ module Kata
45
45
  puts indent + '- ' + "detail: #{txt}"
46
46
  end
47
47
 
48
+ def questions
49
+ if block_given?
50
+ puts "\nQuestions:"
51
+ yield
52
+ end
53
+ end
54
+
55
+ def question(txt)
56
+ puts indent + "- #{txt.sub(/\?$/, '')}?"
57
+ end
58
+
48
59
  private
49
60
 
50
61
  def ask(prompt, default)
@@ -4,27 +4,62 @@ module Kata
4
4
  module Setup
5
5
  class Ruby < Kata::Setup::Base
6
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}
7
+ %w{lib spec helpers matchers}.each { |path| tree(path) }
8
+ readme
9
+ base_class
10
+ dot_rspec
11
+ spec_helper
12
+ kata_spec
13
+ spec_matcher
14
+ end
15
+
16
+ private
17
+
18
+ def use_kata_name
19
+ kata_name.gsub(/( |-)\1?/, '_').downcase
20
+ end
8
21
 
9
- use_kata_name = kata_name.gsub(/( |-)\1?/, '_').downcase
10
- class_name = kata_name.split(/ |-|_/).map(&:capitalize).join
22
+ def class_name
23
+ kata_name.split(/ |-|_/).map(&:capitalize).join
24
+ end
25
+
26
+ def tree(path)
27
+ full_path = case path
28
+ when "lib"
29
+ File.join(repo_name, 'lib')
30
+ when "spec"
31
+ File.join(repo_name, "spec")
32
+ when "matchers"
33
+ File.join(repo_name, "spec", "support", "matchers")
34
+ when "helpers"
35
+ File.join(repo_name, "spec", "support", "helpers")
36
+ end
37
+
38
+ FileUtils.mkdir_p(full_path)
39
+ end
11
40
 
12
- # create the README file so github is happy
13
- File.open(File.join(repo_name, 'README'), 'w') {|f| f.write <<EOF}
41
+ # Using here docs for a cheap templating system
42
+ def readme
43
+ File.open(File.join(repo_name, 'README'), 'w') { |f| f.write(<<EOF) }
14
44
  Leveling up my ruby awesomeness!
15
45
  EOF
46
+ end
16
47
 
48
+ def base_class
17
49
  # create the base class file
18
50
  File.open(File.join(repo_name, 'lib', "#{use_kata_name}.rb"), 'w') {|f| f.write <<EOF}
19
51
  class #{class_name}
20
52
  end
21
53
  EOF
22
- # create the .rspec file
54
+ end
55
+
56
+ def dot_rspec
23
57
  File.open(File.join(repo_name, '.rspec'), 'w') {|f| f.write <<EOF}
24
58
  --color --format d
25
59
  EOF
60
+ end
26
61
 
27
- # create the spec_helper.rb file
62
+ def spec_helper
28
63
  File.open(File.join(repo_name, 'spec', 'spec_helper.rb'), 'w') {|f| f.write <<EOF}
29
64
  $: << '.' << File.join(File.dirname(__FILE__), '..', 'lib')
30
65
 
@@ -32,8 +67,9 @@ require 'rspec'
32
67
 
33
68
  Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
34
69
  EOF
70
+ end
35
71
 
36
- # create a working spec file for the kata
72
+ def kata_spec
37
73
  File.open(File.join(repo_name, 'spec', "#{use_kata_name}_spec.rb"), 'w') {|f| f.write <<EOF}
38
74
  require 'spec_helper'
39
75
  require '#{use_kata_name}'
@@ -48,7 +84,9 @@ describe #{class_name} do
48
84
  end
49
85
  end
50
86
  EOF
51
- # stub out a custom matchers file
87
+ end
88
+
89
+ def spec_matcher
52
90
  File.open(File.join(repo_name, 'spec', 'support', 'matchers', "#{use_kata_name}.rb"), 'w') {|f| f.write <<EOF}
53
91
  RSpec::Matchers.define :your_method do |expected|
54
92
  match do |your_match|
@@ -1,3 +1,3 @@
1
1
  module Kata
2
- VERSION = '1.3.3'
2
+ VERSION = '1.4.0'
3
3
  end
@@ -14,9 +14,39 @@ module Kata
14
14
 
15
15
  let(:system_call) {"git add . && git commit -m 'test req' > /dev/null"}
16
16
 
17
+ describe "#questions" do
18
+ it "individually displays question" do
19
+ expect(subject).to receive(:puts).with("\nQuestions:")
20
+ expect(subject).to receive(:puts).with(" - test question 1?")
21
+ expect(subject).to receive(:puts).with(" - test question 2?")
22
+
23
+ subject.questions do
24
+ subject.question "test question 1"
25
+ subject.question "test question 2"
26
+ end
27
+ end
28
+
29
+ it "ignores trailing question mark" do
30
+ expect(subject).to receive(:puts).with("\nQuestions:")
31
+ expect(subject).to receive(:puts).with(" - test question 1?")
32
+ expect(subject).to receive(:puts).with(" - test question 2?")
33
+
34
+ subject.questions do
35
+ subject.question "test question 1?"
36
+ subject.question "test question 2?"
37
+ end
38
+ end
39
+
40
+ it "ignores questions when none provided" do
41
+ expect(subject).to_not receive(:puts)
42
+
43
+ subject.questions
44
+ end
45
+ end
46
+
17
47
  describe "#kata" do
18
48
  it 'displays summary' do
19
- subject.should_receive(:puts).with('test Kata')
49
+ expect(subject).to receive(:puts).with('test Kata')
20
50
 
21
51
  subject.kata 'test'
22
52
  end
@@ -24,8 +54,8 @@ module Kata
24
54
 
25
55
  describe '#context' do
26
56
  it 'displays' do
27
- subject.should_receive(:puts).with('test Kata')
28
- subject.should_receive(:puts).with(' test context')
57
+ expect(subject).to receive(:puts).with('test Kata')
58
+ expect(subject).to receive(:puts).with(' test context')
29
59
 
30
60
  subject.kata 'test' do
31
61
  subject.context 'test context'
@@ -33,13 +63,13 @@ module Kata
33
63
  end
34
64
 
35
65
  it 'accepts requirement' do
36
- subject.should_receive(:puts).with(' test context')
37
- subject.should_receive(:puts).with(' test req')
38
- subject.should_receive(:print)
39
- $stdin.should_receive(:gets).and_return('y')
40
- subject.should_receive(:puts).exactly(2).times
41
- subject.should_receive(:system).with(system_call).and_return(0)
42
- subject.should_receive(:puts)
66
+ expect(subject).to receive(:puts).with(' test context')
67
+ expect(subject).to receive(:puts).with(' test req')
68
+ expect(subject).to receive(:print)
69
+ expect($stdin).to receive(:gets).and_return('y')
70
+ expect(subject).to receive(:puts).exactly(2).times
71
+ expect(subject).to receive(:system).with(system_call).and_return(0)
72
+ expect(subject).to receive(:puts)
43
73
 
44
74
  subject.kata 'test' do
45
75
  subject.context 'test context' do
@@ -51,12 +81,12 @@ module Kata
51
81
 
52
82
  describe '#requirement' do
53
83
  it 'displays' do
54
- subject.should_receive(:puts).with(' test req')
55
- subject.should_receive(:print)
56
- $stdin.should_receive(:gets).and_return('y')
57
- subject.should_receive(:puts).exactly(2).times
58
- subject.should_receive(:system).with(system_call).and_return(0)
59
- subject.should_receive(:puts)
84
+ expect(subject).to receive(:puts).with(' test req')
85
+ expect(subject).to receive(:print)
86
+ expect($stdin).to receive(:gets).and_return('y')
87
+ expect(subject).to receive(:puts).exactly(2).times
88
+ expect(subject).to receive(:system).with(system_call).and_return(0)
89
+ expect(subject).to receive(:puts)
60
90
 
61
91
  subject.kata 'test' do
62
92
  subject.requirement 'test req'
@@ -64,13 +94,13 @@ module Kata
64
94
  end
65
95
 
66
96
  it 'accepts example' do
67
- subject.should_receive(:puts).with(' test req')
68
- subject.should_receive(:print)
69
- $stdin.should_receive(:gets).and_return('y')
70
- subject.should_receive(:puts).exactly(2).times
71
- subject.should_receive(:system).with(system_call).and_return(0)
72
- subject.should_receive(:puts).exactly(3).times
73
- subject.should_receive(:puts)
97
+ expect(subject).to receive(:puts).with(' test req')
98
+ expect(subject).to receive(:print)
99
+ expect($stdin).to receive(:gets).and_return('y')
100
+ expect(subject).to receive(:puts).exactly(2).times
101
+ expect(subject).to receive(:system).with(system_call).and_return(0)
102
+ expect(subject).to receive(:puts).exactly(3).times
103
+ expect(subject).to receive(:puts)
74
104
 
75
105
  subject.kata 'test' do
76
106
  subject.requirement 'test req' do
@@ -82,13 +112,13 @@ module Kata
82
112
  end
83
113
 
84
114
  it 'accepts detail' do
85
- subject.should_receive(:puts).with(' test req')
86
- subject.should_receive(:print)
87
- $stdin.should_receive(:gets).and_return('y')
88
- subject.should_receive(:puts).exactly(2).times
89
- subject.should_receive(:system).with(system_call).and_return(0)
90
- subject.should_receive(:puts).exactly(3).times
91
- subject.should_receive(:puts)
115
+ expect(subject).to receive(:puts).with(' test req')
116
+ expect(subject).to receive(:print)
117
+ expect($stdin).to receive(:gets).and_return('y')
118
+ expect(subject).to receive(:puts).exactly(2).times
119
+ expect(subject).to receive(:system).with(system_call).and_return(0)
120
+ expect(subject).to receive(:puts).exactly(3).times
121
+ expect(subject).to receive(:puts)
92
122
 
93
123
  subject.kata 'test' do
94
124
  subject.requirement 'test req' do
@@ -4,11 +4,11 @@ require 'kata/version'
4
4
  describe 'kata shell' do
5
5
  it "should exit with status 1" do
6
6
  system "ruby -I lib bin/kata 1> /dev/null"
7
- $?.exitstatus.should == 1
7
+ expect($?.exitstatus).to eq(1)
8
8
  end
9
9
 
10
10
  it "should display the version" do
11
- %x{ruby -I lib bin/kata version}.chomp.should == "kata #{Kata::VERSION}"
11
+ expect(%x{ruby -I lib bin/kata version}.chomp).to eq("kata #{Kata::VERSION}")
12
12
  end
13
13
 
14
14
  it "should run the kata" do
@@ -19,12 +19,12 @@ describe 'kata shell' do
19
19
  EOF
20
20
  end
21
21
 
22
- %x{ruby -I lib bin/kata take test_sample.rb}.chomp.should == 'My Test Kata'
22
+ expect(%x{ruby -I lib bin/kata take test_sample.rb}.chomp).to eq('My Test Kata')
23
23
 
24
24
  File.unlink 'test_sample.rb'
25
25
  end
26
26
 
27
27
  it "should display the usage message" do
28
- %x{ruby -I lib bin/kata help}.should =~ /NAME\n.*kata - Ruby kata management/
28
+ expect(%x{ruby -I lib bin/kata help}).to match(/NAME\n.*kata - Ruby kata management/)
29
29
  end
30
30
  end
@@ -1,35 +1,17 @@
1
1
  require 'spec_helper'
2
2
  require 'kata/setup/base'
3
- require 'kata/setup/ruby'
4
- require 'fileutils'
5
3
 
6
4
  module Kata
7
5
  module Setup
8
6
  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}/
7
+ describe "#new" do
8
+ it "defines a repo name" do
9
+ expect(subject.repo_name).to match(/kata-#{Time.now.strftime('%Y-%m-%d')}-\d{6}/)
14
10
  end
15
11
 
16
12
  it "defines the kata name" do
17
13
  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
- }.to_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
14
+ expect(s.kata_name).to eq('my-kata')
33
15
  end
34
16
  end
35
17
  end
@@ -0,0 +1,58 @@
1
+ require "spec_helper"
2
+ require "kata/setup/ruby"
3
+ require "fakefs/spec_helpers"
4
+
5
+ module Kata
6
+ module Setup
7
+ describe Ruby do
8
+ describe "#build_tree" do
9
+ include FakeFS::SpecHelpers
10
+
11
+ before :each do
12
+ subject.build_tree
13
+ @use_dir = File.join("/", subject.repo_name)
14
+ end
15
+
16
+ it "creates lib dir" do
17
+ expect(File.directory?(File.join(@use_dir, "lib"))).to be true
18
+ end
19
+
20
+ it "creates spect dir" do
21
+ expect(File.directory?(File.join(@use_dir, "spec"))).to be true
22
+ end
23
+
24
+ it "creates matchers dir" do
25
+ expect(File.directory?(File.join(@use_dir, "spec", "support", "matchers"))).to be true
26
+ end
27
+
28
+ it "creates helpers dir" do
29
+ expect(File.directory?(File.join(@use_dir, "spec", "support", "helpers"))).to be true
30
+ end
31
+
32
+ it "creates README file" do
33
+ expect(File.exists?(File.join(@use_dir, "README"))).to be true
34
+ end
35
+
36
+ it "create base class file" do
37
+ expect(File.exists?(File.join(@use_dir, "lib", "#{subject.kata_name}.rb"))).to be true
38
+ end
39
+
40
+ it "creates dot rspec file" do
41
+ expect(File.exists?(File.join(@use_dir, ".rspec"))).to be true
42
+ end
43
+
44
+ it "creates spec helper file" do
45
+ expect(File.exists?(File.join(@use_dir, "spec", "spec_helper.rb"))).to be true
46
+ end
47
+
48
+ it "creates base spec file" do
49
+ expect(File.exists?(File.join(@use_dir, "spec", "#{subject.kata_name}_spec.rb"))).to be true
50
+ end
51
+
52
+ it "creates spec matcher file" do
53
+ expect(File.exists?(File.join(@use_dir, "spec", "support", "matchers", "#{subject.kata_name}.rb"))).to be true
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -1,12 +1,15 @@
1
- $: << '.' << File.join(File.dirname(__FILE__), '..', 'lib')
1
+ $: << "." << File.join(File.dirname(__FILE__), "..", "lib")
2
2
 
3
- require 'rspec'
3
+ require "rspec"
4
+ require "kata/base"
5
+ require "simplecov"
4
6
 
5
7
  Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
6
8
 
7
9
  RSpec.configure do |config|
8
10
  config.before(:each) do
9
- Kata::Base.stub(:system)
11
+ allow(Kata::Base).to receive(:system)
10
12
  end
11
13
  end
12
14
 
15
+ SimpleCov.start
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.3.3
4
+ version: 1.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-02-05 00:00:00.000000000 Z
13
+ date: 2014-02-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -61,6 +61,7 @@ files:
61
61
  - spec/kata_base_spec.rb
62
62
  - spec/kata_spec.rb
63
63
  - spec/setup/base_spec.rb
64
+ - spec/setup/ruby_spec.rb
64
65
  - spec/spec_helper.rb
65
66
  - spec/support/helpers/stdout_helper.rb
66
67
  - spec/support/matchers/kata.rb
@@ -79,7 +80,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
80
  version: '0'
80
81
  segments:
81
82
  - 0
82
- hash: -2352903460502696782
83
+ hash: 1742789635939136821
83
84
  required_rubygems_version: !ruby/object:Gem::Requirement
84
85
  none: false
85
86
  requirements:
@@ -96,6 +97,7 @@ test_files:
96
97
  - spec/kata_base_spec.rb
97
98
  - spec/kata_spec.rb
98
99
  - spec/setup/base_spec.rb
100
+ - spec/setup/ruby_spec.rb
99
101
  - spec/spec_helper.rb
100
102
  - spec/support/helpers/stdout_helper.rb
101
103
  - spec/support/matchers/kata.rb