todo_next 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +21 -1
- data/README.md +25 -13
- data/lib/todo_next.rb +3 -6
- data/lib/todo_next/cli.rb +3 -3
- data/lib/todo_next/cli/assets/rspec_example_file.rb.erb +14 -5
- data/lib/todo_next/line.rb +8 -2
- data/lib/todo_next/parser.rb +10 -5
- data/lib/todo_next/tree.rb +13 -4
- data/lib/todo_next/tree/factory.rb +7 -6
- data/lib/todo_next/tree/node.rb +17 -10
- data/lib/todo_next/tree/nodes.rb +14 -0
- data/lib/todo_next/tree/parents_list.rb +2 -3
- data/lib/todo_next/tree/visitor/base.rb +27 -0
- data/lib/todo_next/tree/visitor/example_remover_visitor.rb +21 -0
- data/lib/todo_next/tree/visitor/leaf_maker.rb +18 -0
- data/lib/todo_next/tree/visitor/rspec_generator.rb +29 -0
- data/lib/todo_next/version.rb +1 -1
- data/spec/01_parse_the_text_spec.rb +29 -2
- data/spec/02_visit_the_tree_spec.rb +4 -5
- data/spec/03_rspec_generator_visitor_spec.rb +1 -1
- data/spec/04_generated_rspec_format_spec.rb +54 -0
- data/spec/spec_helper.rb +12 -7
- data/spec/tree_spec.rb +53 -0
- metadata +12 -5
- data/lib/todo_next/rspec_generator_visitor.rb +0 -22
- data/lib/todo_next/tree/depth_first_visitor_base.rb +0 -24
data/CHANGELOG
CHANGED
@@ -1,2 +1,22 @@
|
|
1
|
-
v0.0.
|
1
|
+
v0.0.2:
|
2
|
+
- cleanup leading characters ('-', '+') before converting to rspec
|
3
|
+
- you can include an example in a spec. It won't be converted
|
4
|
+
<text>
|
5
|
+
√ is white by default
|
6
|
+
ex: puts Foobar.new.colour # => 'white'
|
7
|
+
ex :
|
8
|
+
this is a comment too
|
9
|
+
* can be resized
|
10
|
+
example:
|
11
|
+
foobar.resize!(+10, -2)
|
12
|
+
</text>
|
13
|
+
|
14
|
+
will generate the same rspec code as :
|
15
|
+
|
16
|
+
<text>
|
17
|
+
√ is white by default
|
18
|
+
* can be resized
|
19
|
+
</text>
|
20
|
+
|
21
|
+
v0.0.1:
|
2
22
|
- $ todo_next creates a sample rspec test with an todo_next usage example
|
data/README.md
CHANGED
@@ -29,14 +29,22 @@ $ cat spec/stack_spec.rb
|
|
29
29
|
require 'todo_next'
|
30
30
|
|
31
31
|
todo_next(<<TEXT)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
A Foobar
|
33
|
+
√ is white by default
|
34
|
+
ex: puts Foobar.new.colour # => 'white'
|
35
|
+
* can be resized
|
36
|
+
example:
|
37
|
+
foobar.resize!(+10, -2)
|
38
|
+
- can be reset
|
39
|
+
truthiness()
|
40
|
+
is always true
|
41
|
+
is never false
|
42
|
+
(add more tests)
|
38
43
|
TEXT
|
39
44
|
|
45
|
+
# √ == passed => same as a comment line
|
46
|
+
# * == current => leading char - '*' - is kept
|
47
|
+
# example blocks (ex:, example:) are ignored, like comments.
|
40
48
|
|
41
49
|
#describe "<what you're testing>" do
|
42
50
|
# specify 'this should happen' do
|
@@ -46,13 +54,15 @@ $ cat spec/stack_spec.rb
|
|
46
54
|
This text is equivalent to :
|
47
55
|
|
48
56
|
```ruby
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
57
|
+
describe "A Foobar" do
|
58
|
+
it '* can be resized'
|
59
|
+
it 'can be reset'
|
60
|
+
describe 'truthiness()' do
|
61
|
+
it 'is always true'
|
62
|
+
it 'is never false'
|
63
|
+
end
|
64
|
+
it '(add more tests)'
|
65
|
+
end
|
56
66
|
```
|
57
67
|
|
58
68
|
![screenshot1](https://github.com/alainravet/todo_next/raw/master/doc/screenshot_1.png)
|
@@ -65,3 +75,5 @@ This text is equivalent to :
|
|
65
75
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
66
76
|
4. Push to the branch (`git push origin my-new-feature`)
|
67
77
|
5. Create new Pull Request
|
78
|
+
|
79
|
+
[![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/alainravet/todo_next)
|
data/lib/todo_next.rb
CHANGED
@@ -6,7 +6,7 @@ end
|
|
6
6
|
require File.dirname(__FILE__) + '/todo_next/parser'
|
7
7
|
|
8
8
|
main = TOPLEVEL_BINDING.eval('self')
|
9
|
-
def main.todo_next(text, puts_code=
|
9
|
+
def main.todo_next(text, puts_code=true)
|
10
10
|
code = TodoNext(text)
|
11
11
|
if puts_code
|
12
12
|
puts '---' ; puts code ; puts '---'
|
@@ -15,9 +15,6 @@ def main.todo_next(text, puts_code=false)
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def TodoNext(source)
|
18
|
-
TodoNext::Parser.
|
19
|
-
|
20
|
-
visit(TodoNext::RspecGeneratorVisitor.new).
|
21
|
-
flatten.
|
22
|
-
join("\n")
|
18
|
+
tree = TodoNext::Parser.parse(source)
|
19
|
+
tree.to_rspec
|
23
20
|
end
|
data/lib/todo_next/cli.rb
CHANGED
@@ -4,13 +4,22 @@ require 'todo_next'
|
|
4
4
|
|
5
5
|
todo_next(<<TEXT)
|
6
6
|
A <%= classname %>
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
√ is white by default
|
8
|
+
ex: puts Foobar.new.colour # => 'white'
|
9
|
+
* can be resized
|
10
|
+
example:
|
11
|
+
foobar.resize!(+10, -2)
|
12
|
+
- can be reset
|
13
|
+
truthiness()
|
14
|
+
is always true
|
15
|
+
is never false
|
16
|
+
(add more tests)
|
17
|
+
TEXT
|
12
18
|
TEXT
|
13
19
|
|
20
|
+
# √ == passed => same as a comment line
|
21
|
+
# * == current => leading char - '*' - is kept
|
22
|
+
# example blocks (ex:, example:) are ignored, like comments.
|
14
23
|
|
15
24
|
#describe "<what you're testing>" do
|
16
25
|
# specify 'this should happen' do
|
data/lib/todo_next/line.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module TodoNext
|
2
|
-
|
3
2
|
class Line
|
3
|
+
|
4
4
|
attr_accessor :text, :col_offset, :leaf
|
5
5
|
|
6
6
|
def initialize(text, col_offset)
|
@@ -17,9 +17,15 @@ module TodoNext
|
|
17
17
|
def comment?
|
18
18
|
text =~ /^#/
|
19
19
|
end
|
20
|
+
def passed?
|
21
|
+
text =~ /^\s*√/
|
22
|
+
end
|
23
|
+
def example?
|
24
|
+
text =~ /\s*(ex|example)\s*:/
|
25
|
+
end
|
20
26
|
|
21
27
|
def leaf? ; leaf end
|
22
28
|
def branch? ; !leaf? end
|
23
|
-
end
|
24
29
|
|
30
|
+
end
|
25
31
|
end
|
data/lib/todo_next/parser.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/tree'
|
2
2
|
require File.dirname(__FILE__) + '/line'
|
3
|
-
require File.dirname(__FILE__) + '/rspec_generator_visitor'
|
4
3
|
require File.dirname(__FILE__) + '/cli'
|
5
4
|
|
6
5
|
module TodoNext
|
7
|
-
|
8
6
|
class Parser
|
9
|
-
|
7
|
+
|
8
|
+
def self.parse(text, prune_example_nodes=true)
|
10
9
|
lines = extract_meaningful_lines(text)
|
11
10
|
tree = Tree::Factory.build(lines)
|
11
|
+
if prune_example_nodes
|
12
|
+
tree.visit(TodoNext::Tree::Visitor::ExampleNodesRemover.new)
|
13
|
+
tree.visit(TodoNext::Tree::Visitor::LeafMaker .new)
|
14
|
+
end
|
15
|
+
tree
|
12
16
|
end
|
13
17
|
|
14
18
|
def self.extract_meaningful_lines(text)
|
@@ -19,8 +23,9 @@ module TodoNext
|
|
19
23
|
Line.new(text.strip, col_offset)
|
20
24
|
end.
|
21
25
|
reject{|l| l.blank? }.
|
22
|
-
reject{|l| l.comment?}
|
26
|
+
reject{|l| l.comment?}.
|
27
|
+
reject{|l| l.passed?}
|
23
28
|
end
|
24
|
-
end
|
25
29
|
|
30
|
+
end
|
26
31
|
end
|
data/lib/todo_next/tree.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/tree/factory'
|
2
|
+
require File.dirname(__FILE__) + '/tree/visitor/example_remover_visitor'
|
3
|
+
require File.dirname(__FILE__) + '/tree/visitor/rspec_generator'
|
4
|
+
require File.dirname(__FILE__) + '/tree/visitor/leaf_maker'
|
2
5
|
|
3
6
|
module TodoNext
|
4
|
-
|
5
7
|
class Tree
|
8
|
+
|
6
9
|
attr_accessor :children
|
7
10
|
|
8
11
|
def initialize
|
@@ -10,10 +13,16 @@ module TodoNext
|
|
10
13
|
end
|
11
14
|
|
12
15
|
def visit(visitor)
|
13
|
-
|
14
|
-
|
16
|
+
result = []
|
17
|
+
children.each do |node|
|
18
|
+
result << visitor.visit(node, level=1, parent=self)
|
15
19
|
end
|
20
|
+
result
|
16
21
|
end
|
17
|
-
end
|
18
22
|
|
23
|
+
def to_rspec
|
24
|
+
visit(TodoNext::Tree::Visitor::RspecGenerator.new).flatten.join("\n")
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
19
28
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/node'
|
2
|
+
require File.dirname(__FILE__) + '/nodes'
|
2
3
|
require File.dirname(__FILE__) + '/parents_list'
|
3
4
|
|
4
5
|
module TodoNext
|
5
|
-
|
6
6
|
class Tree
|
7
7
|
class Factory
|
8
8
|
|
@@ -16,13 +16,15 @@ module TodoNext
|
|
16
16
|
curr_line_col = line.col_offset
|
17
17
|
parent = parents.get_for_item_at_column(curr_line_col) || tree
|
18
18
|
|
19
|
+
new_node = if line.example? then Tree::EX.new(line.text, parent)
|
20
|
+
elsif line.branch? then Tree::OL.new(line.text, parent)
|
21
|
+
else Tree::LI.new(line.text, parent)
|
22
|
+
end
|
23
|
+
parent.children << new_node
|
24
|
+
|
19
25
|
if line.branch?
|
20
|
-
new_node = Tree::OL.new(line.text, parent)
|
21
26
|
parents.register_parent(new_node, :for_col => curr_line_col)
|
22
|
-
else
|
23
|
-
new_node = Tree::LI.new(line.text, parent)
|
24
27
|
end
|
25
|
-
parent.children << new_node
|
26
28
|
end
|
27
29
|
tree
|
28
30
|
end
|
@@ -39,5 +41,4 @@ module TodoNext
|
|
39
41
|
|
40
42
|
end
|
41
43
|
end
|
42
|
-
|
43
44
|
end
|
data/lib/todo_next/tree/node.rb
CHANGED
@@ -1,25 +1,32 @@
|
|
1
1
|
module TodoNext
|
2
|
-
|
3
2
|
class Tree
|
4
3
|
class Node
|
4
|
+
|
5
5
|
attr_accessor :text, :parent, :children
|
6
6
|
def initialize(text, parent=nil)
|
7
7
|
@text, @parent = text, parent
|
8
8
|
@children = []
|
9
9
|
end
|
10
10
|
|
11
|
-
def terminal?
|
12
|
-
|
11
|
+
def terminal? ; false end
|
12
|
+
def example? ; false end
|
13
|
+
|
14
|
+
def has_children?
|
15
|
+
!children.empty?
|
13
16
|
end
|
14
|
-
end
|
15
17
|
|
16
|
-
|
18
|
+
def remove_from_parent_children
|
19
|
+
parent.children.delete_if do |child|
|
20
|
+
child==self
|
21
|
+
end
|
22
|
+
end
|
17
23
|
|
18
|
-
|
19
|
-
|
20
|
-
|
24
|
+
def make_me_a_leaf
|
25
|
+
me_as_leaf = Tree::LI.new(text, parent)
|
26
|
+
idx = parent.children.find_index(self)
|
27
|
+
parent.children[idx] = me_as_leaf
|
21
28
|
end
|
29
|
+
|
22
30
|
end
|
23
31
|
end
|
24
|
-
|
25
|
-
end
|
32
|
+
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
module TodoNext
|
2
|
-
|
3
2
|
class Tree
|
4
3
|
class ParentsList
|
5
4
|
|
@@ -14,10 +13,10 @@ module TodoNext
|
|
14
13
|
end
|
15
14
|
|
16
15
|
def get_for_item_at_column(curr_col)
|
17
|
-
parent_key = @parents.keys.sort.reverse.detect {|col| col
|
16
|
+
parent_key = @parents.keys.sort.reverse.detect {|col| col <= curr_col}
|
18
17
|
@parents[parent_key]
|
19
18
|
end
|
19
|
+
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
23
22
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module TodoNext::Tree::Visitor
|
2
|
+
class Base
|
3
|
+
|
4
|
+
def visit(curr_node, level, parent) #nodoc#
|
5
|
+
if curr_node.terminal?
|
6
|
+
process_terminal_node(curr_node, level, parent)
|
7
|
+
else
|
8
|
+
process_non_terminal_node(curr_node, level, parent)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def visit_children_of(parent, parent_level)
|
13
|
+
parent.children.each do |node|
|
14
|
+
visit(node, 1+parent_level, parent)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# overwrite in the concrete visitor class
|
19
|
+
def process_terminal_node(curr_node, level, parent)
|
20
|
+
end
|
21
|
+
|
22
|
+
# overwrite in the concrete visitor class
|
23
|
+
def process_non_terminal_node(curr_node, level, parent)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/base'
|
2
|
+
|
3
|
+
module TodoNext::Tree::Visitor
|
4
|
+
class ExampleNodesRemover < Base
|
5
|
+
|
6
|
+
def visit(curr_node, level, parent) #nodoc#
|
7
|
+
if curr_node.example?
|
8
|
+
remove_from_tree(curr_node)
|
9
|
+
elsif curr_node.has_children?
|
10
|
+
visit_children_of(curr_node, level)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def remove_from_tree(curr_node)
|
17
|
+
curr_node.remove_from_parent_children
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/base'
|
2
|
+
|
3
|
+
module TodoNext::Tree::Visitor
|
4
|
+
class LeafMaker < Base
|
5
|
+
|
6
|
+
def process_terminal_node(curr_node, level, parent)
|
7
|
+
end
|
8
|
+
|
9
|
+
def process_non_terminal_node(curr_node, level, parent)
|
10
|
+
if curr_node.has_children?
|
11
|
+
visit_children_of(curr_node, level)
|
12
|
+
else
|
13
|
+
curr_node.make_me_a_leaf
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/base'
|
2
|
+
|
3
|
+
module TodoNext
|
4
|
+
class Tree
|
5
|
+
module Visitor
|
6
|
+
class RspecGenerator < Base
|
7
|
+
|
8
|
+
def process_terminal_node(curr_node, level, parent)
|
9
|
+
tabs = ' '*(level-1)
|
10
|
+
label = label(curr_node)
|
11
|
+
code = %Q|#{tabs}it("#{label}", :pending => "#{label}"){}|
|
12
|
+
end
|
13
|
+
|
14
|
+
def process_non_terminal_node(curr_node, level, parent)
|
15
|
+
tabs = ' '*(level-1)
|
16
|
+
codes = curr_node.children.collect { |node| visit(node, 1+level, parent=self) }
|
17
|
+
[%Q|#{tabs}describe "#{label(curr_node)}" do|] + codes + ["#{tabs}end"]
|
18
|
+
end
|
19
|
+
|
20
|
+
def label(node)
|
21
|
+
text = node.text
|
22
|
+
text.gsub! /^[-\+]\s*/,''
|
23
|
+
text
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/todo_next/version.rb
CHANGED
@@ -27,8 +27,8 @@ describe TodoNext::Parser, 'parsing indented text and producing a Tree' do
|
|
27
27
|
|
28
28
|
it 'converts 2 lines under a header as 2 :li under 1 :ol' do
|
29
29
|
@source = 'HEADER 1' + "\n" +
|
30
|
-
'
|
31
|
-
'
|
30
|
+
' spec a' + "\n" +
|
31
|
+
' spec b'
|
32
32
|
|
33
33
|
result_should_be [ {:type => :ol , :text => "HEADER 1",
|
34
34
|
:children => [
|
@@ -39,6 +39,33 @@ describe TodoNext::Parser, 'parsing indented text and producing a Tree' do
|
|
39
39
|
]
|
40
40
|
end
|
41
41
|
|
42
|
+
#--------------
|
43
|
+
# ex: / example:
|
44
|
+
#--------------
|
45
|
+
it 'converts an example block to a :ex element' do
|
46
|
+
@source = 'HEADER 1' + "\n" +
|
47
|
+
' spec a' + "\n" +
|
48
|
+
' ex :' + "\n" +
|
49
|
+
' blabla' + "\n" +
|
50
|
+
' spec b'
|
51
|
+
|
52
|
+
result_should_be [ {:type => :ol , :text => 'HEADER 1',
|
53
|
+
:children => [
|
54
|
+
{:type => :ol, :text => 'spec a',
|
55
|
+
:children => [
|
56
|
+
{:type => :ex, :text => "ex :",
|
57
|
+
:children => [{:type => :li, :text => "blabla"}]
|
58
|
+
}]
|
59
|
+
},
|
60
|
+
{:type => :li, :text => 'spec b'}
|
61
|
+
]
|
62
|
+
}
|
63
|
+
]
|
64
|
+
end
|
65
|
+
|
66
|
+
#--------------
|
67
|
+
# ALL-in-one
|
68
|
+
#--------------
|
42
69
|
it 'converts a complex text into the proper Tree' do
|
43
70
|
@source = 'HEADER 1' + "\n" +
|
44
71
|
' HEADER 2' + "\n" +
|
@@ -3,14 +3,13 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe TodoNext::Tree, 'visiting the tree depth-first' do
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
def process_terminal_node(curr_node, level)
|
6
|
+
class SimpleVisitor < TodoNext::Tree::Visitor::Base
|
7
|
+
def process_terminal_node(curr_node, level, parent)
|
9
8
|
curr_node.text
|
10
9
|
end
|
11
10
|
|
12
|
-
def process_non_terminal_node(curr_node, level)
|
13
|
-
result = curr_node.children.collect { |node| visit(node, 1+level) }.join(', ')
|
11
|
+
def process_non_terminal_node(curr_node, level, parent)
|
12
|
+
result = curr_node.children.collect { |node| visit(node, 1+level, self) }.join(', ')
|
14
13
|
"#{curr_node.text}=[#{result}]"
|
15
14
|
end
|
16
15
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TodoNext::Tree::Visitor::RspecGenerator, 'fine-tuning' do
|
4
|
+
|
5
|
+
it 'visits the tree depth-first' do
|
6
|
+
source = 'HEADER 1' + "\n" +
|
7
|
+
' HEADER 2' + "\n" +
|
8
|
+
' - HEADER 3' + "\n" +
|
9
|
+
' √ spec a' + "\n" +
|
10
|
+
' * spec b' + "\n" +
|
11
|
+
' - spec c'
|
12
|
+
|
13
|
+
expected =<<RUBY.chomp
|
14
|
+
describe "HEADER 1" do
|
15
|
+
describe "HEADER 2" do
|
16
|
+
describe "HEADER 3" do
|
17
|
+
it("* spec b", :pending => "* spec b"){}
|
18
|
+
it("spec c", :pending => "spec c"){}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
RUBY
|
23
|
+
|
24
|
+
TodoNext(source).should == expected
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'ignores the example blocks' do
|
28
|
+
source = 'A Foo' + "\n" +
|
29
|
+
' it can be created' + "\n" +
|
30
|
+
' ex: ' + "\n" +
|
31
|
+
' Foo.create' + "\n" +
|
32
|
+
' it can be deleted'
|
33
|
+
|
34
|
+
expected =<<RUBY.chomp
|
35
|
+
describe "A Foo" do
|
36
|
+
it("it can be created", :pending => "it can be created"){}
|
37
|
+
it("it can be deleted", :pending => "it can be deleted"){}
|
38
|
+
end
|
39
|
+
RUBY
|
40
|
+
|
41
|
+
source = 'A Foo' + "\n" +
|
42
|
+
' it can be created' + "\n" +
|
43
|
+
' ex: '
|
44
|
+
|
45
|
+
expected =<<RUBY.chomp
|
46
|
+
describe "A Foo" do
|
47
|
+
it("it can be created", :pending => "it can be created"){}
|
48
|
+
end
|
49
|
+
RUBY
|
50
|
+
|
51
|
+
TodoNext(source).should == expected
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -25,26 +25,31 @@ class TodoNext::Tree
|
|
25
25
|
}
|
26
26
|
end
|
27
27
|
|
28
|
-
class
|
28
|
+
class EX
|
29
|
+
def to_hash
|
30
|
+
{ :type => :ex, :text => text,
|
31
|
+
:children => children.collect{|ch| ch.to_hash }
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
29
35
|
|
36
|
+
class OL
|
30
37
|
def to_hash
|
31
|
-
{ :type => :ol,
|
32
|
-
:text => text,
|
38
|
+
{ :type => :ol, :text => text,
|
33
39
|
:children => children.collect{|ch| ch.to_hash }
|
34
40
|
}
|
35
41
|
end
|
36
42
|
end
|
43
|
+
|
37
44
|
class LI
|
38
45
|
def to_hash
|
39
|
-
{ :type => :li,
|
40
|
-
:text => text
|
41
|
-
}
|
46
|
+
{ :type => :li, :text => text}
|
42
47
|
end
|
43
48
|
end
|
44
49
|
end
|
45
50
|
|
46
51
|
def parsed_result(source)
|
47
|
-
TodoNext::Parser.parse(source).to_hash[:children]
|
52
|
+
TodoNext::Parser.parse(source, prune_example_nodes=false).to_hash[:children]
|
48
53
|
end
|
49
54
|
|
50
55
|
def result_should_be(expected)
|
data/spec/tree_spec.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TodoNext::Tree do
|
4
|
+
|
5
|
+
describe '#prune_example_nodes!' do
|
6
|
+
|
7
|
+
specify 'an top-level example line with a sibling is removed' do
|
8
|
+
source = 'spec 1' + "\n" +
|
9
|
+
'example : ignore me' + "\n" +
|
10
|
+
'spec 2'
|
11
|
+
tree = TodoNext::Parser.parse(source, prune_example_nodes=false)
|
12
|
+
tree.to_hash[:children].should ==
|
13
|
+
[ {:type => :li, :text => 'spec 1' },
|
14
|
+
{:type => :ex, :text => 'example : ignore me', :children => []},
|
15
|
+
{:type => :li, :text => 'spec 2' }
|
16
|
+
]
|
17
|
+
tree = TodoNext::Parser.parse(source)
|
18
|
+
tree.to_hash[:children].should ==
|
19
|
+
[ {:type => :li, :text => 'spec 1', },
|
20
|
+
{:type => :li, :text => 'spec 2'}
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
24
|
+
specify 'an sb-level example line with a sibling is removed'
|
25
|
+
|
26
|
+
|
27
|
+
specify 'an example block is removed' do
|
28
|
+
source = 'HEADER 1' + "\n" +
|
29
|
+
' ex :' + "\n" +
|
30
|
+
' blabla' + "\n" +
|
31
|
+
' spec b'
|
32
|
+
|
33
|
+
tree = TodoNext::Parser.parse(source)
|
34
|
+
tree.to_hash[:children].should ==
|
35
|
+
[ {:type => :ol , :text => "HEADER 1",
|
36
|
+
:children => [{:type => :li, :text => "spec b"}]
|
37
|
+
}
|
38
|
+
]
|
39
|
+
end
|
40
|
+
|
41
|
+
specify 'when an OL only child is an EX, it becomes a LI after pruning' do
|
42
|
+
source = 'spec 1' + "\n" +
|
43
|
+
' ex :' + "\n" +
|
44
|
+
' blabla'
|
45
|
+
|
46
|
+
tree = TodoNext::Parser.parse(source)
|
47
|
+
tree.to_hash[:children].should ==
|
48
|
+
[ {:type => :li , :text => "spec 1"}
|
49
|
+
]
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: todo_next
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alain Ravet
|
@@ -74,17 +74,22 @@ files:
|
|
74
74
|
- lib/todo_next/cli/sample_file_generator.rb
|
75
75
|
- lib/todo_next/line.rb
|
76
76
|
- lib/todo_next/parser.rb
|
77
|
-
- lib/todo_next/rspec_generator_visitor.rb
|
78
77
|
- lib/todo_next/tree.rb
|
79
|
-
- lib/todo_next/tree/depth_first_visitor_base.rb
|
80
78
|
- lib/todo_next/tree/factory.rb
|
81
79
|
- lib/todo_next/tree/node.rb
|
80
|
+
- lib/todo_next/tree/nodes.rb
|
82
81
|
- lib/todo_next/tree/parents_list.rb
|
82
|
+
- lib/todo_next/tree/visitor/base.rb
|
83
|
+
- lib/todo_next/tree/visitor/example_remover_visitor.rb
|
84
|
+
- lib/todo_next/tree/visitor/leaf_maker.rb
|
85
|
+
- lib/todo_next/tree/visitor/rspec_generator.rb
|
83
86
|
- lib/todo_next/version.rb
|
84
87
|
- spec/01_parse_the_text_spec.rb
|
85
88
|
- spec/02_visit_the_tree_spec.rb
|
86
89
|
- spec/03_rspec_generator_visitor_spec.rb
|
90
|
+
- spec/04_generated_rspec_format_spec.rb
|
87
91
|
- spec/spec_helper.rb
|
92
|
+
- spec/tree_spec.rb
|
88
93
|
- todo_next.gemspec
|
89
94
|
homepage: ""
|
90
95
|
licenses: []
|
@@ -123,4 +128,6 @@ test_files:
|
|
123
128
|
- spec/01_parse_the_text_spec.rb
|
124
129
|
- spec/02_visit_the_tree_spec.rb
|
125
130
|
- spec/03_rspec_generator_visitor_spec.rb
|
131
|
+
- spec/04_generated_rspec_format_spec.rb
|
126
132
|
- spec/spec_helper.rb
|
133
|
+
- spec/tree_spec.rb
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/tree/depth_first_visitor_base'
|
2
|
-
|
3
|
-
module TodoNext
|
4
|
-
|
5
|
-
class RspecGeneratorVisitor < TodoNext::Tree::DepthFirstVisitorBase
|
6
|
-
def visit(curr_node, level) #nodoc#
|
7
|
-
super
|
8
|
-
end
|
9
|
-
|
10
|
-
def process_terminal_node(curr_node, level)
|
11
|
-
tabs = ' '*(level-1)
|
12
|
-
code = %Q|#{tabs}it("#{curr_node.text}", :pending => "#{curr_node.text}"){}|
|
13
|
-
end
|
14
|
-
|
15
|
-
def process_non_terminal_node(curr_node, level)
|
16
|
-
tabs = ' '*(level-1)
|
17
|
-
codes = curr_node.children.collect { |node| visit(node, 1+level) }
|
18
|
-
[%Q|#{tabs}describe "#{curr_node.text}" do|] + codes + ["#{tabs}end"]
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module TodoNext
|
2
|
-
class Tree
|
3
|
-
|
4
|
-
class DepthFirstVisitorBase
|
5
|
-
|
6
|
-
def visit(curr_node, level) #nodoc#
|
7
|
-
if curr_node.terminal?
|
8
|
-
process_terminal_node(curr_node, level)
|
9
|
-
else
|
10
|
-
process_non_terminal_node(curr_node, level)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
# overwrite in the concrete visitor class
|
15
|
-
def process_terminal_node(curr_node, level)
|
16
|
-
end
|
17
|
-
|
18
|
-
# overwrite in the concrete visitor class
|
19
|
-
def process_non_terminal_node(curr_node, level)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|