pdd 0.10 → 0.11

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/bin/pdd CHANGED
@@ -33,11 +33,39 @@ opts = Slop.parse(ARGV, strict: true, help: true) do
33
33
  banner "Usage (#{PDD::VERSION}): pdd [options]"
34
34
  on 'v', 'verbose', 'Enable verbose mode'
35
35
  on 'version', 'Show current version'
36
- on 's', 'source', 'Source directory to parse', argument: :required
37
- on 'f', 'file', 'File to save XML into', argument: :required
38
- on 'e', 'exclude', 'Glob pattern to exclude', as: Array, argument: :required
39
- on 't', 'format', 'Format to use (xml|html)', argument: :required
40
- on 'r', 'rule', 'Format to use (xml|html)', argument: :required, as: Array
36
+ on(
37
+ 's',
38
+ 'source',
39
+ 'Source directory to parse',
40
+ argument: :required
41
+ )
42
+ on(
43
+ 'f',
44
+ 'file',
45
+ 'File to save XML into',
46
+ argument: :required
47
+ )
48
+ on(
49
+ 'e',
50
+ 'exclude',
51
+ 'Glob pattern to exclude',
52
+ as: Array,
53
+ argument: :required
54
+ )
55
+ on(
56
+ 't',
57
+ 'format',
58
+ 'Format to use (xml|html)',
59
+ argument: :required
60
+ )
61
+ on(
62
+ 'r',
63
+ 'rule',
64
+ 'Format to use (xml|html)',
65
+ argument: :required,
66
+ as: Array,
67
+ limit: 1
68
+ )
41
69
  end
42
70
 
43
71
  fail '-f is mandatory when using -v' if opts.verbose? && !opts.file?
@@ -29,3 +29,13 @@ Feature: Applies Post-Parsing Rules
29
29
  When I run bin/pdd with ""
30
30
  Then Exit code is not zero
31
31
  Then Stdout contains "there are 2 duplicate"
32
+
33
+ Scenario: Throwing exception on duplicates
34
+ Given I have a "Sample.java" file with content:
35
+ """
36
+ @todo #13/DEV:15min Some text first
37
+ @todo #13/TEST:15min The text second
38
+ """
39
+ When I run bin/pdd with "--rule=available-roles:DEV,IMP"
40
+ Then Exit code is not zero
41
+ Then Stdout contains "defines role TEST"
data/lib/pdd.rb CHANGED
@@ -26,6 +26,7 @@ require 'pdd/version'
26
26
  require 'pdd/rule/estimates'
27
27
  require 'pdd/rule/text'
28
28
  require 'pdd/rule/duplicates'
29
+ require 'pdd/rule/roles'
29
30
  require 'nokogiri'
30
31
  require 'logger'
31
32
  require 'time'
@@ -47,7 +48,8 @@ module PDD
47
48
  'min-estimate' => PDD::Rule::Estimate::Min,
48
49
  'max-estimate' => PDD::Rule::Estimate::Max,
49
50
  'min-words' => PDD::Rule::Text::MinWords,
50
- 'max-duplicates' => PDD::Rule::MaxDuplicates
51
+ 'max-duplicates' => PDD::Rule::MaxDuplicates,
52
+ 'available-roles' => PDD::Rule::Roles::Available
51
53
  }
52
54
 
53
55
  # Get logger.
@@ -139,7 +141,7 @@ module PDD
139
141
  name, value = r.split(':')
140
142
  rule = RULES[name]
141
143
  fail "rule '#{name}' doesn't exist" if rule.nil?
142
- rule.new(doc, value.to_i).errors.each do |e|
144
+ rule.new(doc, value).errors.each do |e|
143
145
  PDD.log.error e
144
146
  total += 1
145
147
  end
@@ -29,7 +29,7 @@ module PDD
29
29
  # +xml+:: XML with puzzles
30
30
  def initialize(xml, max)
31
31
  @xml = xml
32
- @max = max
32
+ @max = max.to_i
33
33
  end
34
34
 
35
35
  def errors
@@ -30,7 +30,7 @@ module PDD
30
30
  # +xml+:: XML with puzzles
31
31
  def initialize(xml, min)
32
32
  @xml = xml
33
- @min = min
33
+ @min = min.to_i
34
34
  end
35
35
 
36
36
  def errors
@@ -48,7 +48,7 @@ module PDD
48
48
  # +xml+:: XML with puzzles
49
49
  def initialize(xml, min)
50
50
  @xml = xml
51
- @min = min
51
+ @min = min.to_i
52
52
  end
53
53
 
54
54
  def errors
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2014 TechnoPark Corp.
4
+ # Copyright (c) 2014 Yegor Bugayenko
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the 'Software'), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ module PDD
25
+ module Rule
26
+ module Roles
27
+ # Rule for available roles checking.
28
+ class Available
29
+ # Ctor.
30
+ # +xml+:: XML with puzzles
31
+ def initialize(xml, roles)
32
+ @xml = xml
33
+ @roles = roles.split(',')
34
+ end
35
+
36
+ def errors
37
+ @xml.xpath('//puzzle').map do |p|
38
+ role = p.xpath('role/text()').to_s
39
+ next nil if @roles.include?(role)
40
+ "puzzle #{p.xpath('file/text()')}:#{p.xpath('lines/text()')}" +
41
+ if role.empty?
42
+ " doesn't define any role"\
43
+ ", while one of these roles is required: #{@roles}"
44
+ else
45
+ " defines role #{role}"\
46
+ ", while only these roles are allowed: #{@roles}"
47
+ end
48
+ end.compact
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -30,7 +30,7 @@ module PDD
30
30
  # +xml+:: XML with puzzles
31
31
  def initialize(xml, min)
32
32
  @xml = xml
33
- @min = min
33
+ @min = min.to_i
34
34
  end
35
35
 
36
36
  def errors
@@ -26,5 +26,5 @@
26
26
  # Copyright:: Copyright (c) 2014 Yegor Bugayenko
27
27
  # License:: MIT
28
28
  module PDD
29
- VERSION = '0.10'
29
+ VERSION = '0.11'
30
30
  end
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2014 TechnoPark Corp.
4
+ # Copyright (c) 2014 Yegor Bugayenko
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the 'Software'), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ require 'minitest/autorun'
25
+ require 'nokogiri'
26
+ require 'pdd/rule/roles'
27
+
28
+ # PDD::Rule::Role module tests.
29
+ # Author:: Yegor Bugayenko (yegor@teamed.io)
30
+ # Copyright:: Copyright (c) 2014 Yegor Bugayenko
31
+ # License:: MIT
32
+ class TestRoles < Minitest::Test
33
+ def test_incorrect_role
34
+ rule = PDD::Rule::Roles::Available.new(
35
+ Nokogiri::XML::Document.parse(
36
+ '<puzzles><puzzle><role>D</role></puzzle></puzzles>'
37
+ ), 'A,B,C'
38
+ )
39
+ assert !rule.errors.empty?, 'why it is empty?'
40
+ end
41
+
42
+ def test_correct_role
43
+ rule = PDD::Rule::Roles::Available.new(
44
+ Nokogiri::XML::Document.parse(
45
+ '<puzzles><puzzle><role>F</role></puzzle></puzzles>'
46
+ ), 'F,E,G'
47
+ )
48
+ assert rule.errors.empty?, 'why it is not empty?'
49
+ end
50
+
51
+ def test_empty_role
52
+ rule = PDD::Rule::Roles::Available.new(
53
+ Nokogiri::XML::Document.parse(
54
+ '<puzzles><puzzle></puzzle></puzzles>'
55
+ ), 'T,R,L'
56
+ )
57
+ assert !rule.errors.empty?, 'why it is empty?'
58
+ end
59
+ 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.10'
4
+ version: '0.11'
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-12-05 00:00:00.000000000 Z
12
+ date: 2014-12-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -224,6 +224,7 @@ files:
224
224
  - lib/pdd/puzzle.rb
225
225
  - lib/pdd/rule/duplicates.rb
226
226
  - lib/pdd/rule/estimates.rb
227
+ - lib/pdd/rule/roles.rb
227
228
  - lib/pdd/rule/text.rb
228
229
  - lib/pdd/source.rb
229
230
  - lib/pdd/sources.rb
@@ -233,6 +234,7 @@ files:
233
234
  - test/test_duplicates.rb
234
235
  - test/test_estimates.rb
235
236
  - test/test_pdd.rb
237
+ - test/test_roles.rb
236
238
  - test/test_source.rb
237
239
  - test/test_sources.rb
238
240
  - test/test_text.rb
@@ -277,6 +279,7 @@ test_files:
277
279
  - test/test_duplicates.rb
278
280
  - test/test_estimates.rb
279
281
  - test/test_pdd.rb
282
+ - test/test_roles.rb
280
283
  - test/test_source.rb
281
284
  - test/test_sources.rb
282
285
  - test/test_text.rb