pdd 0.7 → 0.7.1

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.
@@ -33,3 +33,19 @@ Feature: Catches Broken Puzzles
33
33
  }
34
34
  """
35
35
  When I run pdd it fails with "Too many spaces"
36
+
37
+ Scenario: Throwing exception on yet another broken puzzle
38
+ Given I have a "Sample.java" file with content:
39
+ """
40
+ public class Main {
41
+ //
42
+ // @todo #13 This puzzle has an incorrect format
43
+ // because there is no space character in the
44
+ // second and third lines
45
+ //
46
+ public void main(String[] args) {
47
+ // later
48
+ }
49
+ }
50
+ """
51
+ When I run pdd it fails with "Space expected"
@@ -92,4 +92,22 @@ module PDD
92
92
  .map { |txt| txt[1, txt.length] }
93
93
  end
94
94
  end
95
+
96
+ # Verbose Source.
97
+ class VerboseSource
98
+ # Ctor.
99
+ # +file+:: Absolute file name with source code
100
+ # +source+:: Instance of source
101
+ def initialize(file, source)
102
+ @file = file
103
+ @source = source
104
+ end
105
+
106
+ # Fetch all puzzles.
107
+ def puzzles
108
+ @source.puzzles
109
+ rescue Error => ex
110
+ raise Error, "#{ex.message} in #{@file}"
111
+ end
112
+ end
95
113
  end
@@ -50,7 +50,10 @@ module PDD
50
50
  files
51
51
  .select { |f| types.index { |re| @magic.file(f) =~ re } }
52
52
  .map do |file|
53
- Source.new(file, file[@dir.length + 1, file.length])
53
+ VerboseSource.new(
54
+ file,
55
+ Source.new(file, file[@dir.length + 1, file.length])
56
+ )
54
57
  end
55
58
  end
56
59
 
@@ -26,5 +26,5 @@
26
26
  # Copyright:: Copyright (c) 2014 Yegor Bugayenko
27
27
  # License:: MIT
28
28
  module PDD
29
- VERSION = '0.7'
29
+ VERSION = '0.7.1'
30
30
  end
@@ -43,7 +43,7 @@ class TestSources < Minitest::Test
43
43
  ~~ and it also has to work
44
44
  '
45
45
  )
46
- list = PDD::Source.new(file, 'hey').puzzles
46
+ list = PDD::VerboseSource.new(file, PDD::Source.new(file, 'hey')).puzzles
47
47
  assert_equal 2, list.size
48
48
  puzzle = list.first
49
49
  assert_equal '2-3', puzzle.props[:lines]
@@ -51,4 +51,21 @@ class TestSources < Minitest::Test
51
51
  assert_equal '44', puzzle.props[:ticket]
52
52
  end
53
53
  end
54
+
55
+ def test_failing_on_invalid_puzzle
56
+ Dir.mktmpdir 'test' do |dir|
57
+ file = File.join(dir, 'a.txt')
58
+ File.write(
59
+ file,
60
+ '
61
+ * @todo #44 this is an incorrectly formatted puzzle,
62
+ * with a second line without a leading space
63
+ '
64
+ )
65
+ error = assert_raises PDD::Error do
66
+ PDD::VerboseSource.new(file, PDD::Source.new(file, 'hey')).puzzles
67
+ end
68
+ assert !error.message.index('Space expected').nil?
69
+ end
70
+ end
54
71
  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.7'
4
+ version: 0.7.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: