pdd 0.2.3 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -12,10 +12,10 @@ Install it first:
12
12
  gem install pdd
13
13
  ```
14
14
 
15
- Run it locally:
15
+ Run it locally and read its output:
16
16
 
17
17
  ```bash
18
- pdd
18
+ pdd --help
19
19
  ```
20
20
 
21
21
  Every puzzle has to be formatted like this:
@@ -35,7 +35,8 @@ Possible formats of puzzle markers:
35
35
  #TEST-13
36
36
  #55:45min
37
37
  #67/DES
38
+ #678:40m/DEV
38
39
  ```
39
40
 
40
41
  Read this article about
41
- [Puzzle Drive Development](http://www.xdsd.org/2009/03/04/pdd.html).
42
+ [Puzzle Drive Development](http://www.yegor256.com/2009/03/04/pdd.html).
data/Rakefile CHANGED
@@ -24,6 +24,9 @@
24
24
  require 'rubygems'
25
25
  require 'rake'
26
26
  require 'rdoc'
27
+ require 'rake/clean'
28
+
29
+ CLEAN = FileList['coverage', 'rdoc']
27
30
 
28
31
  def name
29
32
  @name ||= File.basename(Dir['*.gemspec'].first, '.*')
@@ -33,14 +36,14 @@ def version
33
36
  Gem::Specification.load(Dir['*.gemspec'].first).version
34
37
  end
35
38
 
36
- task default: [:test, :features, :rubocop]
39
+ task default: [:clean, :test, :features, :rubocop]
37
40
 
38
41
  require 'rake/testtask'
39
42
  desc 'Run all unit tests'
40
43
  Rake::TestTask.new(:test) do |test|
41
44
  test.libs << 'lib' << 'test'
42
45
  test.pattern = 'test/**/test_*.rb'
43
- test.verbose = true
46
+ test.verbose = false
44
47
  end
45
48
 
46
49
  require 'rdoc/task'
data/bin/pdd CHANGED
@@ -33,6 +33,7 @@ opts = Slop.parse do
33
33
  on 'v', 'verbose', 'Enable verbose mode'
34
34
  on 's', 'source', 'Source directory to parse', argument: :required
35
35
  on 'f', 'file', 'File to save XML into', argument: :required
36
+ on 'e', 'exclude', 'Glob pattern to exclude', as: Array, argument: :required
36
37
  end
37
38
 
38
39
  fail '-f is mandatory when using -v' if opts.verbose? && !opts.file?
data/lib/pdd.rb CHANGED
@@ -66,11 +66,16 @@ module PDD
66
66
  def xml
67
67
  dir = @opts.source? ? @opts[:source] : Dir.pwd
68
68
  PDD.log.info "reading #{dir}"
69
+ sources = Sources.new(dir)
70
+ @opts[:exclude].each do |p|
71
+ sources = sources.exclude(p)
72
+ PDD.log.info "excluding #{p}"
73
+ end unless @opts[:exclude].nil?
69
74
  sanitize(
70
75
  Nokogiri::XML::Builder.new do |xml|
71
76
  xml << '<?xml-stylesheet type="text/xsl" href="puzzles.xsl"?>'
72
77
  xml.puzzles do
73
- Sources.new(dir).fetch.each do |source|
78
+ sources.fetch.each do |source|
74
79
  source.puzzles.each do |puzzle|
75
80
  PDD.log.info "puzzle #{puzzle.props[:ticket]}:" \
76
81
  "#{puzzle.props[:estimate]}/#{puzzle.props[:role]}" \
@@ -23,25 +23,38 @@
23
23
 
24
24
  require 'filemagic'
25
25
  require 'pdd/source'
26
+ require 'rake/file_list'
26
27
 
27
28
  module PDD
28
29
  # Code base abstraction
29
30
  class Sources
30
31
  # Ctor.
31
32
  # +dir+:: Directory with source code files
32
- def initialize(dir)
33
+ def initialize(dir, ptns = [])
33
34
  @dir = dir
35
+ @exclude = ptns
34
36
  @magic = FileMagic.new(FileMagic::MAGIC_MIME)
35
37
  end
36
38
 
37
39
  # Fetch all sources.
38
40
  def fetch
41
+ files = Rake::FileList.new(@dir + '/**/*') do |list|
42
+ @exclude.each do |ptn|
43
+ Rake::FileList.new(@dir + '/' + ptn).each do |f|
44
+ list.exclude(f)
45
+ end
46
+ end
47
+ end
39
48
  types = [/^text\//, /application\/xml/]
40
- Dir.glob(@dir + '/**/*')
49
+ files.to_a
41
50
  .select { |f| types.index { |re| @magic.file(f) =~ re } }
42
51
  .map do |file|
43
52
  Source.new(file, file[@dir.length + 1, file.length])
44
53
  end
45
54
  end
55
+
56
+ def exclude(ptn)
57
+ Sources.new(@dir, @exclude.push(ptn))
58
+ end
46
59
  end
47
60
  end
@@ -29,7 +29,7 @@ Gem::Specification.new do |s|
29
29
  s.rubygems_version = '2.2.2'
30
30
  s.required_ruby_version = '>= 1.9.3'
31
31
  s.name = 'pdd'
32
- s.version = '0.2.3'
32
+ s.version = '0.3'
33
33
  s.license = 'MIT'
34
34
  s.summary = 'Puzzle Driven Development collector'
35
35
  s.description = 'Collects puzzles from source code base'
@@ -44,7 +44,7 @@ Gem::Specification.new do |s|
44
44
  s.add_runtime_dependency 'nokogiri', '~> 1.6', '>= 1.6.3.1'
45
45
  s.add_runtime_dependency 'ruby-filemagic', '~> 0.6', '>= 0.6.0'
46
46
  s.add_runtime_dependency 'slop', '~> 3.6', '>= 3.6.0'
47
- s.add_development_dependency 'rake', '~> 10.1'
47
+ s.add_runtime_dependency 'rake', '~> 10.1'
48
48
  s.add_development_dependency 'coveralls', '~> 0.7', '>= 0.7.0'
49
49
  s.add_development_dependency 'rdoc', '~> 3.11'
50
50
  s.add_development_dependency 'cucumber', '1.3.11'
@@ -34,9 +34,10 @@ require 'slop'
34
34
  class TestPDD < Minitest::Test
35
35
  def test_basic
36
36
  Dir.mktmpdir 'test' do |dir|
37
- opts = Slop.parse ['-v', '-s', dir] do
37
+ opts = Slop.parse ['-v', '-s', dir, '-e', '**/*.png'] do
38
38
  on 'v', 'verbose'
39
39
  on 's', 'source', argument: :required
40
+ on 'e', 'exclude', as: Array, argument: :required
40
41
  end
41
42
  File.write(File.join(dir, 'a.txt'), '@todo #55 hello!')
42
43
  xml = Nokogiri::XML::Document.parse(PDD::Base.new(opts).xml)
@@ -31,18 +31,14 @@ require 'tmpdir'
31
31
  # License:: MIT
32
32
  class TestSources < Minitest::Test
33
33
  def test_iterator
34
- Dir.mktmpdir 'test' do |dir|
35
- File.write(File.join(dir, 'a.txt'), '@todo hello!')
36
- Dir.mkdir(File.join(dir, 'b'))
37
- File.write(File.join(dir, 'b/c.txt'), 'hello, again')
34
+ in_temp(['a.txt', 'b/c.txt']) do |dir|
38
35
  list = PDD::Sources.new(dir).fetch
39
36
  assert_equal 2, list.size
40
37
  end
41
38
  end
42
39
 
43
40
  def test_ignores_binary_files
44
- Dir.mktmpdir 'test' do |dir|
45
- File.write(File.join(dir, 'c'), 'how are you?')
41
+ in_temp(['c', 'd.png']) do |dir|
46
42
  File.write(File.join(dir, 'd.png'), '')
47
43
  list = PDD::Sources.new(dir).fetch
48
44
  assert_equal 1, list.size
@@ -50,7 +46,7 @@ class TestSources < Minitest::Test
50
46
  end
51
47
 
52
48
  def test_detects_all_text_files
53
- Dir.mktmpdir 'test' do |dir|
49
+ in_temp([]) do |dir|
54
50
  exts = %w[(xsl java rb cpp apt)]
55
51
  exts.each do |ext|
56
52
  File.write(File.join(dir, "test.#{ext}"), 'text')
@@ -61,10 +57,28 @@ class TestSources < Minitest::Test
61
57
  end
62
58
 
63
59
  def test_detects_xml_file
64
- Dir.mktmpdir 'test' do |dir|
60
+ in_temp(['a.xml']) do |dir|
65
61
  File.write(File.join(dir, 'a.xml'), '<?xml version="1.0"?><hello/>')
66
62
  list = PDD::Sources.new(dir).fetch
67
63
  assert_equal 1, list.size
68
64
  end
69
65
  end
66
+
67
+ def test_excludes_by_pattern
68
+ in_temp(['a/first.txt', 'b/c/d/second.txt']) do |dir|
69
+ list = PDD::Sources.new(dir).exclude('b/c/d/second.txt').fetch
70
+ assert_equal 1, list.size
71
+ end
72
+ end
73
+
74
+ def in_temp(files)
75
+ Dir.mktmpdir 'x' do |dir|
76
+ files.each do |path|
77
+ file = File.join(dir, path)
78
+ FileUtils.mkdir_p(File.dirname(file))
79
+ File.write(file, 'some test content')
80
+ end
81
+ yield dir
82
+ end
83
+ end
70
84
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: '0.3'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-11 00:00:00.000000000 Z
12
+ date: 2014-08-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -85,7 +85,7 @@ dependencies:
85
85
  - - ~>
86
86
  - !ruby/object:Gem::Version
87
87
  version: '10.1'
88
- type: :development
88
+ type: :runtime
89
89
  prerelease: false
90
90
  version_requirements: !ruby/object:Gem::Requirement
91
91
  none: false