pdd 0.6.1 → 0.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -19,12 +19,14 @@ Run it locally and read its output:
19
19
  pdd --help
20
20
  ```
21
21
 
22
- Every puzzle has to be formatted like this:
22
+ Every puzzle has to be formatted like this (pay attention
23
+ to the leading space in every consecutive line):
23
24
 
24
25
  ```java
25
26
  /**
26
27
  * @todo #234:15m/DEV This is something to do later
27
- * in one of the next releases
28
+ * in one of the next releases. I can't figure out how
29
+ * how to implement it now, that's why the puzzle.
28
30
  */
29
31
  ```
30
32
 
@@ -0,0 +1,35 @@
1
+ Feature: Catches Broken Puzzles
2
+ As a source code writer I want to be sure that
3
+ broken puzzles won't be processed and will
4
+ cause runtime errors
5
+
6
+ Scenario: Throwing exception on broken puzzles
7
+ Given I have a "Sample.java" file with content:
8
+ """
9
+ public class Main {
10
+ /**
11
+ * @todo #13 This puzzle has an incorrect format
12
+ * because it doesn't start with a space on
13
+ * the second and the third lines
14
+ */
15
+ public void main(String[] args) {
16
+ // later
17
+ }
18
+ }
19
+ """
20
+ When I run pdd it fails with "Space expected"
21
+
22
+ Scenario: Throwing exception on another broken puzzle
23
+ Given I have a "Sample.java" file with content:
24
+ """
25
+ public class Main {
26
+ /**
27
+ * @todo #13 This puzzle has an incorrect format
28
+ * because its second line starts with too many spaces
29
+ */
30
+ public void main(String[] args) {
31
+ // later
32
+ }
33
+ }
34
+ """
35
+ When I run pdd it fails with "Too many spaces"
data/lib/pdd/source.rb CHANGED
@@ -41,25 +41,7 @@ module PDD
41
41
  lines = File.readlines(@file)
42
42
  lines.each_with_index do |line, idx|
43
43
  re.match(line) do |match|
44
- prefix = match[1] + ' '
45
- total = 0
46
- body = (match[3] + ' ' + lines.drop(idx + 1)
47
- .take_while { |txt| txt.start_with?(prefix) }
48
- .map { |txt| txt[prefix.length, txt.length] }
49
- .map do |txt|
50
- total += 1
51
- txt
52
- end
53
- .join(' '))
54
- .gsub(/\s+/, ' ')
55
- .strip
56
- puzzles << Puzzle.new(
57
- marker(match[2]).merge(
58
- lines: "#{idx + 1}-#{idx + total + 1}",
59
- body: body,
60
- file: @path
61
- )
62
- )
44
+ puzzles << puzzle(lines.drop(idx + 1), match, idx)
63
45
  end
64
46
  end
65
47
  puzzles
@@ -85,5 +67,29 @@ module PDD
85
67
  min *= 60 if !units.nil? && units.start_with?('h')
86
68
  min
87
69
  end
70
+
71
+ # Fetch puzzle
72
+ def puzzle(lines, match, idx)
73
+ tail = tail(lines, match[1])
74
+ body = (match[3] + ' ' + tail.join(' ')).gsub(/\s+/, ' ').strip
75
+ Puzzle.new(
76
+ marker(match[2]).merge(
77
+ lines: "#{idx + 1}-#{idx + tail.size + 1}",
78
+ body: body,
79
+ file: @path
80
+ )
81
+ )
82
+ end
83
+
84
+ # Fetch puzzle tail (all lines after the first one)
85
+ def tail(lines, prefix)
86
+ lines
87
+ .take_while { |txt| txt.start_with?(prefix) }
88
+ .map { |txt| txt[prefix.length, txt.length] }
89
+ .take_while { |txt| txt =~ /^[ a-zA-Z0-9\-_]/ }
90
+ .each { |txt| fail Error, 'Space expected' unless txt.start_with?(' ') }
91
+ .each { |txt| fail Error, 'Too many spaces' if txt =~ /^\s{2,}/ }
92
+ .map { |txt| txt[1, txt.length] }
93
+ end
88
94
  end
89
95
  end
data/lib/pdd/version.rb CHANGED
@@ -26,5 +26,5 @@
26
26
  # Copyright:: Copyright (c) 2014 Yegor Bugayenko
27
27
  # License:: MIT
28
28
  module PDD
29
- VERSION = '0.6.1'
29
+ VERSION = '0.7'
30
30
  end
data/pdd.gemspec CHANGED
@@ -45,15 +45,15 @@ Gem::Specification.new do |s|
45
45
  s.test_files = s.files.grep(/^(test|spec|features)\//)
46
46
  s.rdoc_options = ['--charset=UTF-8']
47
47
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
48
- s.add_runtime_dependency 'nokogiri', '~> 1.6', '>= 1.6.3.1'
49
- s.add_runtime_dependency 'ruby-filemagic', '~> 0.6', '>= 0.6.0'
50
- s.add_runtime_dependency 'slop', '~> 3.6', '>= 3.6.0'
51
- s.add_runtime_dependency 'rake', '~> 10.1'
52
- s.add_development_dependency 'coveralls', '~> 0.7', '>= 0.7.0'
53
- s.add_development_dependency 'rdoc', '~> 3.11'
48
+ s.add_runtime_dependency 'nokogiri', '1.6'
49
+ s.add_runtime_dependency 'ruby-filemagic', '0.6'
50
+ s.add_runtime_dependency 'slop', '3.6'
51
+ s.add_runtime_dependency 'rake', '10.1'
52
+ s.add_development_dependency 'coveralls', '0.7'
53
+ s.add_development_dependency 'rdoc', '3.11'
54
54
  s.add_development_dependency 'cucumber', '1.3.11'
55
- s.add_development_dependency 'minitest', '~> 5.4', '>= 5.4.0'
56
- s.add_development_dependency 'rubocop', '~> 0.24', '>= 0.24.1'
57
- s.add_development_dependency 'rubocop-rspec', '~> 1.1', '>= 1.1.0'
58
- s.add_development_dependency 'rspec-rails', '~> 2.13'
55
+ s.add_development_dependency 'minitest', '5.4'
56
+ s.add_development_dependency 'rubocop', '0.24.1'
57
+ s.add_development_dependency 'rubocop-rspec', '1.1'
58
+ s.add_development_dependency 'rspec-rails', '2.13'
59
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.6.1
4
+ version: '0.7'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,80 +9,62 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-22 00:00:00.000000000 Z
12
+ date: 2014-11-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ~>
19
+ - - '='
20
20
  - !ruby/object:Gem::Version
21
21
  version: '1.6'
22
- - - ! '>='
23
- - !ruby/object:Gem::Version
24
- version: 1.6.3.1
25
22
  type: :runtime
26
23
  prerelease: false
27
24
  version_requirements: !ruby/object:Gem::Requirement
28
25
  none: false
29
26
  requirements:
30
- - - ~>
27
+ - - '='
31
28
  - !ruby/object:Gem::Version
32
29
  version: '1.6'
33
- - - ! '>='
34
- - !ruby/object:Gem::Version
35
- version: 1.6.3.1
36
30
  - !ruby/object:Gem::Dependency
37
31
  name: ruby-filemagic
38
32
  requirement: !ruby/object:Gem::Requirement
39
33
  none: false
40
34
  requirements:
41
- - - ~>
35
+ - - '='
42
36
  - !ruby/object:Gem::Version
43
37
  version: '0.6'
44
- - - ! '>='
45
- - !ruby/object:Gem::Version
46
- version: 0.6.0
47
38
  type: :runtime
48
39
  prerelease: false
49
40
  version_requirements: !ruby/object:Gem::Requirement
50
41
  none: false
51
42
  requirements:
52
- - - ~>
43
+ - - '='
53
44
  - !ruby/object:Gem::Version
54
45
  version: '0.6'
55
- - - ! '>='
56
- - !ruby/object:Gem::Version
57
- version: 0.6.0
58
46
  - !ruby/object:Gem::Dependency
59
47
  name: slop
60
48
  requirement: !ruby/object:Gem::Requirement
61
49
  none: false
62
50
  requirements:
63
- - - ~>
51
+ - - '='
64
52
  - !ruby/object:Gem::Version
65
53
  version: '3.6'
66
- - - ! '>='
67
- - !ruby/object:Gem::Version
68
- version: 3.6.0
69
54
  type: :runtime
70
55
  prerelease: false
71
56
  version_requirements: !ruby/object:Gem::Requirement
72
57
  none: false
73
58
  requirements:
74
- - - ~>
59
+ - - '='
75
60
  - !ruby/object:Gem::Version
76
61
  version: '3.6'
77
- - - ! '>='
78
- - !ruby/object:Gem::Version
79
- version: 3.6.0
80
62
  - !ruby/object:Gem::Dependency
81
63
  name: rake
82
64
  requirement: !ruby/object:Gem::Requirement
83
65
  none: false
84
66
  requirements:
85
- - - ~>
67
+ - - '='
86
68
  - !ruby/object:Gem::Version
87
69
  version: '10.1'
88
70
  type: :runtime
@@ -90,7 +72,7 @@ dependencies:
90
72
  version_requirements: !ruby/object:Gem::Requirement
91
73
  none: false
92
74
  requirements:
93
- - - ~>
75
+ - - '='
94
76
  - !ruby/object:Gem::Version
95
77
  version: '10.1'
96
78
  - !ruby/object:Gem::Dependency
@@ -98,29 +80,23 @@ dependencies:
98
80
  requirement: !ruby/object:Gem::Requirement
99
81
  none: false
100
82
  requirements:
101
- - - ~>
83
+ - - '='
102
84
  - !ruby/object:Gem::Version
103
85
  version: '0.7'
104
- - - ! '>='
105
- - !ruby/object:Gem::Version
106
- version: 0.7.0
107
86
  type: :development
108
87
  prerelease: false
109
88
  version_requirements: !ruby/object:Gem::Requirement
110
89
  none: false
111
90
  requirements:
112
- - - ~>
91
+ - - '='
113
92
  - !ruby/object:Gem::Version
114
93
  version: '0.7'
115
- - - ! '>='
116
- - !ruby/object:Gem::Version
117
- version: 0.7.0
118
94
  - !ruby/object:Gem::Dependency
119
95
  name: rdoc
120
96
  requirement: !ruby/object:Gem::Requirement
121
97
  none: false
122
98
  requirements:
123
- - - ~>
99
+ - - '='
124
100
  - !ruby/object:Gem::Version
125
101
  version: '3.11'
126
102
  type: :development
@@ -128,7 +104,7 @@ dependencies:
128
104
  version_requirements: !ruby/object:Gem::Requirement
129
105
  none: false
130
106
  requirements:
131
- - - ~>
107
+ - - '='
132
108
  - !ruby/object:Gem::Version
133
109
  version: '3.11'
134
110
  - !ruby/object:Gem::Dependency
@@ -152,32 +128,23 @@ dependencies:
152
128
  requirement: !ruby/object:Gem::Requirement
153
129
  none: false
154
130
  requirements:
155
- - - ~>
131
+ - - '='
156
132
  - !ruby/object:Gem::Version
157
133
  version: '5.4'
158
- - - ! '>='
159
- - !ruby/object:Gem::Version
160
- version: 5.4.0
161
134
  type: :development
162
135
  prerelease: false
163
136
  version_requirements: !ruby/object:Gem::Requirement
164
137
  none: false
165
138
  requirements:
166
- - - ~>
139
+ - - '='
167
140
  - !ruby/object:Gem::Version
168
141
  version: '5.4'
169
- - - ! '>='
170
- - !ruby/object:Gem::Version
171
- version: 5.4.0
172
142
  - !ruby/object:Gem::Dependency
173
143
  name: rubocop
174
144
  requirement: !ruby/object:Gem::Requirement
175
145
  none: false
176
146
  requirements:
177
- - - ~>
178
- - !ruby/object:Gem::Version
179
- version: '0.24'
180
- - - ! '>='
147
+ - - '='
181
148
  - !ruby/object:Gem::Version
182
149
  version: 0.24.1
183
150
  type: :development
@@ -185,10 +152,7 @@ dependencies:
185
152
  version_requirements: !ruby/object:Gem::Requirement
186
153
  none: false
187
154
  requirements:
188
- - - ~>
189
- - !ruby/object:Gem::Version
190
- version: '0.24'
191
- - - ! '>='
155
+ - - '='
192
156
  - !ruby/object:Gem::Version
193
157
  version: 0.24.1
194
158
  - !ruby/object:Gem::Dependency
@@ -196,29 +160,23 @@ dependencies:
196
160
  requirement: !ruby/object:Gem::Requirement
197
161
  none: false
198
162
  requirements:
199
- - - ~>
163
+ - - '='
200
164
  - !ruby/object:Gem::Version
201
165
  version: '1.1'
202
- - - ! '>='
203
- - !ruby/object:Gem::Version
204
- version: 1.1.0
205
166
  type: :development
206
167
  prerelease: false
207
168
  version_requirements: !ruby/object:Gem::Requirement
208
169
  none: false
209
170
  requirements:
210
- - - ~>
171
+ - - '='
211
172
  - !ruby/object:Gem::Version
212
173
  version: '1.1'
213
- - - ! '>='
214
- - !ruby/object:Gem::Version
215
- version: 1.1.0
216
174
  - !ruby/object:Gem::Dependency
217
175
  name: rspec-rails
218
176
  requirement: !ruby/object:Gem::Requirement
219
177
  none: false
220
178
  requirements:
221
- - - ~>
179
+ - - '='
222
180
  - !ruby/object:Gem::Version
223
181
  version: '2.13'
224
182
  type: :development
@@ -226,7 +184,7 @@ dependencies:
226
184
  version_requirements: !ruby/object:Gem::Requirement
227
185
  none: false
228
186
  requirements:
229
- - - ~>
187
+ - - '='
230
188
  - !ruby/object:Gem::Version
231
189
  version: '2.13'
232
190
  description: Collects puzzles from source code base
@@ -253,6 +211,7 @@ files:
253
211
  - bin/pdd
254
212
  - cucumber.yml
255
213
  - features/avoiding_duplicates.feature
214
+ - features/catches_broken_puzzles.feature
256
215
  - features/cli.feature
257
216
  - features/gem_package.feature
258
217
  - features/html_output.feature
@@ -298,6 +257,7 @@ specification_version: 2
298
257
  summary: Puzzle Driven Development collector
299
258
  test_files:
300
259
  - features/avoiding_duplicates.feature
260
+ - features/catches_broken_puzzles.feature
301
261
  - features/cli.feature
302
262
  - features/gem_package.feature
303
263
  - features/html_output.feature