gherkin_format 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/Gemfile +5 -0
- data/README.md +24 -2
- data/Rakefile +3 -14
- data/bin/gherkin_format +10 -0
- data/features/support/env.rb +1 -0
- data/features/template.markdown.feature +183 -0
- data/features/template.multi_markdown.feature +191 -0
- data/features/template.multi_markdown_without_highlighting.feature +177 -0
- data/gherkin_format.gemspec +12 -11
- data/lib/gherkin_format.rb +36 -0
- data/lib/markdown.erb +49 -0
- data/lib/multi_markdown.erb +102 -0
- data/lib/multi_markdown_without_highlight.erb +89 -0
- metadata +25 -3
- data/test/test_gherkin_format.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d5b6cbca7cfc39b6a5ec76b76c0dc55f4694b0b
|
4
|
+
data.tar.gz: e03d5ed13815d698a31c6653b1819dcfbd647dc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c82de390a4747752e87bec0a06d58cdd57a090212bed9f3235c68860861c75771e423bad77e425a6c2dc46173b64e7d27224ac9d4939465d5ca52fb2d2c3515
|
7
|
+
data.tar.gz: 88b5839bc83787d5a37e71f2801087582e687694fb20453db2a082c4cc07cf86ca5630c1485d9aaf2f49fdd6c3bc9106478879660b2dfe1a2d844c6c22db00bc
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
CHANGED
@@ -1,2 +1,24 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
Formatter for Gherkin Files
|
2
|
+
===========================
|
3
|
+
|
4
|
+
[](https://travis-ci.org/funkwerk/gherkin_format)
|
5
|
+
|
6
|
+
This tool formats gherkin files.
|
7
|
+
|
8
|
+
Usage
|
9
|
+
-----
|
10
|
+
|
11
|
+
run `gherkin_format` on a list of files
|
12
|
+
|
13
|
+
gherkin_format FEATURE_FILES
|
14
|
+
|
15
|
+
To replace files with their formatted counterpart add the option `--replace`.
|
16
|
+
|
17
|
+
To get detailed information in case of errors use `--verbose`.
|
18
|
+
|
19
|
+
To format gherkin files using a custom format, it's possible to specify a template using `--template TEMPLATE`.
|
20
|
+
The template provided is a erb-template.
|
21
|
+
|
22
|
+
These templates are predefined:
|
23
|
+
- markdown
|
24
|
+
- multi_markdown
|
data/Rakefile
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'rake/testtask'
|
2
|
-
|
3
1
|
task default: :build
|
4
2
|
|
5
3
|
desc 'Builds the Gem.'
|
@@ -8,22 +6,13 @@ task build: :test do
|
|
8
6
|
end
|
9
7
|
|
10
8
|
task test: :rubocop
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
task test: :cli_test
|
16
|
-
task :cli_test do
|
17
|
-
gherkin_format(%w(foo.feature))
|
18
|
-
end
|
19
|
-
|
20
|
-
def gherkin_format(args)
|
21
|
-
sh "ruby -ilib lib/* bin/gherkin_format #{args.join ' '}"
|
9
|
+
task :test do
|
10
|
+
sh 'cucumber'
|
22
11
|
end
|
23
12
|
|
24
13
|
desc 'Publishes the Gem'
|
25
14
|
task :push do
|
26
|
-
sh 'gem push gherkin_format-
|
15
|
+
sh 'gem push gherkin_format-0.0.2-gem'
|
27
16
|
end
|
28
17
|
|
29
18
|
desc 'Checks ruby style'
|
data/bin/gherkin_format
CHANGED
@@ -11,9 +11,19 @@ OptionParser.new do |opts|
|
|
11
11
|
opts.on('-r', '--[no-]replace', 'Replaces input files') do |replace|
|
12
12
|
options[:replace] = replace
|
13
13
|
end
|
14
|
+
opts.on('--template [TEMPLATE]', 'Renders into template') do |template|
|
15
|
+
options[:template] = template
|
16
|
+
end
|
14
17
|
end.parse!
|
15
18
|
|
16
19
|
formatter = GherkinFormat.new
|
20
|
+
|
21
|
+
if options.key? :template
|
22
|
+
formatter.render(options[:template], ARGV)
|
23
|
+
|
24
|
+
exit 0
|
25
|
+
end
|
26
|
+
|
17
27
|
ARGV.each do |file|
|
18
28
|
formatter.format file, options
|
19
29
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'aruba/cucumber'
|
@@ -0,0 +1,183 @@
|
|
1
|
+
Feature: Markdown Template
|
2
|
+
As a Business Analyst
|
3
|
+
I want to format my feature files as markdown
|
4
|
+
so that I can import them to the wiki of my choice
|
5
|
+
|
6
|
+
Background: Prepare Testee
|
7
|
+
Given a file named "render_markdown.rb" with:
|
8
|
+
"""
|
9
|
+
$LOAD_PATH << '../../lib'
|
10
|
+
require 'gherkin_format'
|
11
|
+
|
12
|
+
formatter = GherkinFormat.new
|
13
|
+
formatter.render('../../lib/markdown.erb', ['foo.feature'])
|
14
|
+
|
15
|
+
"""
|
16
|
+
|
17
|
+
Scenario: Simple Feature
|
18
|
+
Given a file named "foo.feature" with:
|
19
|
+
"""
|
20
|
+
Feature: Foo
|
21
|
+
Scenario: Bar
|
22
|
+
Given a foo
|
23
|
+
When I bar
|
24
|
+
Then I baz
|
25
|
+
"""
|
26
|
+
When I run `ruby render_markdown.rb`
|
27
|
+
Then it should pass with exactly:
|
28
|
+
"""
|
29
|
+
|
30
|
+
## Feature Foo (foo.feature)
|
31
|
+
|
32
|
+
|
33
|
+
### Scenario: Bar
|
34
|
+
|
35
|
+
Given a foo
|
36
|
+
When I bar
|
37
|
+
Then I baz
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
"""
|
42
|
+
|
43
|
+
Scenario: Extract Sentences with background
|
44
|
+
Given a file named "foo.feature" with:
|
45
|
+
"""
|
46
|
+
Feature: Foo
|
47
|
+
Background:
|
48
|
+
Given something
|
49
|
+
|
50
|
+
Scenario: Bar
|
51
|
+
Given a foo
|
52
|
+
When I bar
|
53
|
+
Then I baz
|
54
|
+
"""
|
55
|
+
When I run `ruby render_markdown.rb`
|
56
|
+
Then it should pass with exactly:
|
57
|
+
"""
|
58
|
+
|
59
|
+
## Feature Foo (foo.feature)
|
60
|
+
|
61
|
+
|
62
|
+
### Background:
|
63
|
+
|
64
|
+
Given something
|
65
|
+
|
66
|
+
|
67
|
+
### Scenario: Bar
|
68
|
+
|
69
|
+
Given a foo
|
70
|
+
When I bar
|
71
|
+
Then I baz
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
"""
|
76
|
+
|
77
|
+
Scenario: Extract Sentences from outlines
|
78
|
+
Given a file named "foo.feature" with:
|
79
|
+
"""
|
80
|
+
Feature: Foo
|
81
|
+
Scenario Outline: Bar
|
82
|
+
Given a <foo>
|
83
|
+
When I <bar>
|
84
|
+
Then I <baz>
|
85
|
+
|
86
|
+
Examples: table
|
87
|
+
| foo | bar | baz |
|
88
|
+
| FOO | BAR | BAZ |
|
89
|
+
| oof | rab | zab |
|
90
|
+
"""
|
91
|
+
When I run `ruby render_markdown.rb`
|
92
|
+
Then it should pass with exactly:
|
93
|
+
"""
|
94
|
+
|
95
|
+
## Feature Foo (foo.feature)
|
96
|
+
|
97
|
+
|
98
|
+
### Scenario Outline: Bar
|
99
|
+
|
100
|
+
Given a <foo>
|
101
|
+
When I <bar>
|
102
|
+
Then I <baz>
|
103
|
+
|
104
|
+
#### Examples: table
|
105
|
+
|
106
|
+
| foo | bar | baz |
|
107
|
+
| FOO | BAR | BAZ |
|
108
|
+
| oof | rab | zab |
|
109
|
+
|
110
|
+
|
111
|
+
"""
|
112
|
+
|
113
|
+
Scenario: Extract Sentences considers description
|
114
|
+
Given a file named "foo.feature" with:
|
115
|
+
"""
|
116
|
+
Feature: Foo
|
117
|
+
As a user,
|
118
|
+
I want something
|
119
|
+
so that I have that
|
120
|
+
|
121
|
+
Scenario: Bar
|
122
|
+
Given a foo
|
123
|
+
When I bar
|
124
|
+
Then I baz
|
125
|
+
"""
|
126
|
+
When I run `ruby render_markdown.rb`
|
127
|
+
Then it should pass with exactly:
|
128
|
+
"""
|
129
|
+
|
130
|
+
## Feature Foo (foo.feature)
|
131
|
+
|
132
|
+
|
133
|
+
As a user,
|
134
|
+
I want something
|
135
|
+
so that I have that
|
136
|
+
|
137
|
+
### Scenario: Bar
|
138
|
+
|
139
|
+
Given a foo
|
140
|
+
When I bar
|
141
|
+
Then I baz
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
"""
|
146
|
+
|
147
|
+
Scenario: Extract Sentences considers scenario description
|
148
|
+
Given a file named "foo.feature" with:
|
149
|
+
"""
|
150
|
+
Feature: Foo
|
151
|
+
As a user,
|
152
|
+
I want something
|
153
|
+
so that I have that
|
154
|
+
|
155
|
+
Scenario: Bar
|
156
|
+
This is a sentence description
|
157
|
+
|
158
|
+
Given a foo
|
159
|
+
When I bar
|
160
|
+
Then I baz
|
161
|
+
"""
|
162
|
+
When I run `ruby render_markdown.rb`
|
163
|
+
Then it should pass with exactly:
|
164
|
+
"""
|
165
|
+
|
166
|
+
## Feature Foo (foo.feature)
|
167
|
+
|
168
|
+
|
169
|
+
As a user,
|
170
|
+
I want something
|
171
|
+
so that I have that
|
172
|
+
|
173
|
+
### Scenario: Bar
|
174
|
+
|
175
|
+
This is a sentence description
|
176
|
+
|
177
|
+
Given a foo
|
178
|
+
When I bar
|
179
|
+
Then I baz
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
"""
|
@@ -0,0 +1,191 @@
|
|
1
|
+
Feature: Multi Markdown Template
|
2
|
+
As a Business Analyst
|
3
|
+
I want to format my feature files as multi markdown with highligthing
|
4
|
+
so that I can import them to the wiki of my choice
|
5
|
+
|
6
|
+
Background: Prepare Testee
|
7
|
+
Given a file named "render_multi_markdown.rb" with:
|
8
|
+
"""
|
9
|
+
$LOAD_PATH << '../../lib'
|
10
|
+
require 'gherkin_format'
|
11
|
+
|
12
|
+
formatter = GherkinFormat.new
|
13
|
+
formatter.render('../../lib/multi_markdown.erb', ['foo.feature'])
|
14
|
+
|
15
|
+
"""
|
16
|
+
|
17
|
+
Scenario: Simple Feature
|
18
|
+
Given a file named "foo.feature" with:
|
19
|
+
"""
|
20
|
+
Feature: Foo
|
21
|
+
Scenario: Bar
|
22
|
+
Given a foo
|
23
|
+
When I «bar»
|
24
|
+
Then I baz
|
25
|
+
"""
|
26
|
+
When I run `ruby render_multi_markdown.rb`
|
27
|
+
Then it should pass with exactly:
|
28
|
+
"""
|
29
|
+
|
30
|
+
<h2 id="Foo">Foo</h2>
|
31
|
+
|
32
|
+
Source\: foo.feature
|
33
|
+
|
34
|
+
<h3 id="Bar">Scenario: Bar</h3>
|
35
|
+
|
36
|
+
__Given__ a foo
|
37
|
+
__When__ I _«bar»_
|
38
|
+
__Then__ I baz
|
39
|
+
<hr />
|
40
|
+
|
41
|
+
|
42
|
+
"""
|
43
|
+
|
44
|
+
Scenario: Extract Sentences with background
|
45
|
+
Given a file named "foo.feature" with:
|
46
|
+
"""
|
47
|
+
Feature: Foo
|
48
|
+
Background:
|
49
|
+
Given something
|
50
|
+
|
51
|
+
Scenario: Bar
|
52
|
+
Given a foo
|
53
|
+
When I bar
|
54
|
+
Then I baz
|
55
|
+
"""
|
56
|
+
When I run `ruby render_multi_markdown.rb`
|
57
|
+
Then it should pass with exactly:
|
58
|
+
"""
|
59
|
+
|
60
|
+
<h2 id="Foo">Foo</h2>
|
61
|
+
|
62
|
+
Source\: foo.feature
|
63
|
+
|
64
|
+
<h3 id="">Background</h3>
|
65
|
+
|
66
|
+
__Given__ something
|
67
|
+
|
68
|
+
<h3 id="Bar">Scenario: Bar</h3>
|
69
|
+
|
70
|
+
__Given__ a foo
|
71
|
+
__When__ I bar
|
72
|
+
__Then__ I baz
|
73
|
+
<hr />
|
74
|
+
|
75
|
+
|
76
|
+
"""
|
77
|
+
|
78
|
+
Scenario: Extract Sentences from outlines
|
79
|
+
Given a file named "foo.feature" with:
|
80
|
+
"""
|
81
|
+
Feature: Foo
|
82
|
+
Scenario Outline: Bar
|
83
|
+
Given a <foo>
|
84
|
+
When I <bar>
|
85
|
+
Then I <baz>
|
86
|
+
|
87
|
+
Examples: table
|
88
|
+
| foo | bar | bazzzzzz |
|
89
|
+
| FOOoooo | BAR | BAZ |
|
90
|
+
| oof | rabbbbbbb | zab |
|
91
|
+
"""
|
92
|
+
When I run `ruby render_multi_markdown.rb`
|
93
|
+
Then it should pass with exactly:
|
94
|
+
"""
|
95
|
+
|
96
|
+
<h2 id="Foo">Foo</h2>
|
97
|
+
|
98
|
+
Source\: foo.feature
|
99
|
+
|
100
|
+
<h3 id="Bar">Scenario Outline: Bar</h3>
|
101
|
+
|
102
|
+
__Given__ a _\<foo\>_
|
103
|
+
__When__ I _\<bar\>_
|
104
|
+
__Then__ I _\<baz\>_
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
| foo | bar | bazzzzzz |
|
109
|
+
| ------- | --------- | -------- |
|
110
|
+
| FOOoooo | BAR | BAZ |
|
111
|
+
| oof | rabbbbbbb | zab |
|
112
|
+
[_**Examples: table**_]
|
113
|
+
|
114
|
+
<hr />
|
115
|
+
|
116
|
+
|
117
|
+
"""
|
118
|
+
|
119
|
+
Scenario: Extract Sentences considers description
|
120
|
+
Given a file named "foo.feature" with:
|
121
|
+
"""
|
122
|
+
Feature: Foo
|
123
|
+
As a user,
|
124
|
+
I want something
|
125
|
+
so that I have that
|
126
|
+
|
127
|
+
Scenario: Bar
|
128
|
+
Given a foo
|
129
|
+
When I bar
|
130
|
+
Then I baz
|
131
|
+
"""
|
132
|
+
When I run `ruby render_multi_markdown.rb`
|
133
|
+
Then it should pass with exactly:
|
134
|
+
"""
|
135
|
+
|
136
|
+
<h2 id="Foo">Foo</h2>
|
137
|
+
|
138
|
+
Source\: foo.feature
|
139
|
+
|
140
|
+
> As a user,
|
141
|
+
> I want something
|
142
|
+
> so that I have that
|
143
|
+
|
144
|
+
<h3 id="Bar">Scenario: Bar</h3>
|
145
|
+
|
146
|
+
__Given__ a foo
|
147
|
+
__When__ I bar
|
148
|
+
__Then__ I baz
|
149
|
+
<hr />
|
150
|
+
|
151
|
+
|
152
|
+
"""
|
153
|
+
|
154
|
+
Scenario: Extract Sentences considers scenario description
|
155
|
+
Given a file named "foo.feature" with:
|
156
|
+
"""
|
157
|
+
Feature: Foo
|
158
|
+
As a user,
|
159
|
+
I want something
|
160
|
+
so that I have that
|
161
|
+
|
162
|
+
Scenario: Bar
|
163
|
+
This is a sentence description
|
164
|
+
|
165
|
+
Given a foo
|
166
|
+
When I bar
|
167
|
+
Then I baz
|
168
|
+
"""
|
169
|
+
When I run `ruby render_multi_markdown.rb`
|
170
|
+
Then it should pass with exactly:
|
171
|
+
"""
|
172
|
+
|
173
|
+
<h2 id="Foo">Foo</h2>
|
174
|
+
|
175
|
+
Source\: foo.feature
|
176
|
+
|
177
|
+
> As a user,
|
178
|
+
> I want something
|
179
|
+
> so that I have that
|
180
|
+
|
181
|
+
<h3 id="Bar">Scenario: Bar</h3>
|
182
|
+
|
183
|
+
> This is a sentence description
|
184
|
+
|
185
|
+
__Given__ a foo
|
186
|
+
__When__ I bar
|
187
|
+
__Then__ I baz
|
188
|
+
<hr />
|
189
|
+
|
190
|
+
|
191
|
+
"""
|
@@ -0,0 +1,177 @@
|
|
1
|
+
Feature: Template for Multi Markdown Without Highlight
|
2
|
+
As a Business Analyst
|
3
|
+
I want to format my feature files as multi markdown
|
4
|
+
so that I can import them to the wiki of my choice
|
5
|
+
|
6
|
+
Background:
|
7
|
+
Given a file named "render_multi_markdown.rb" with:
|
8
|
+
"""
|
9
|
+
$LOAD_PATH << '../../lib'
|
10
|
+
require 'gherkin_format'
|
11
|
+
|
12
|
+
formatter = GherkinFormat.new
|
13
|
+
template = '../../lib/multi_markdown_without_highlight.erb'
|
14
|
+
formatter.render(template, ['foo.feature'])
|
15
|
+
|
16
|
+
"""
|
17
|
+
|
18
|
+
Scenario: Simple Feature
|
19
|
+
Given a file named "foo.feature" with:
|
20
|
+
"""
|
21
|
+
Feature: Foo
|
22
|
+
Scenario: Bar
|
23
|
+
Given a foo
|
24
|
+
When I bar
|
25
|
+
Then I baz
|
26
|
+
"""
|
27
|
+
When I run `ruby render_multi_markdown.rb`
|
28
|
+
Then it should pass with exactly:
|
29
|
+
"""
|
30
|
+
|
31
|
+
## Feature Foo (foo.feature)
|
32
|
+
|
33
|
+
### Scenario: Bar
|
34
|
+
|
35
|
+
Given a foo
|
36
|
+
When I bar
|
37
|
+
Then I baz
|
38
|
+
|
39
|
+
|
40
|
+
"""
|
41
|
+
|
42
|
+
Scenario: Extract Sentences with background
|
43
|
+
Given a file named "foo.feature" with:
|
44
|
+
"""
|
45
|
+
Feature: Foo
|
46
|
+
Background:
|
47
|
+
Given something
|
48
|
+
|
49
|
+
Scenario: Bar
|
50
|
+
Given a foo
|
51
|
+
When I bar
|
52
|
+
Then I baz
|
53
|
+
"""
|
54
|
+
When I run `ruby render_multi_markdown.rb`
|
55
|
+
Then it should pass with exactly:
|
56
|
+
"""
|
57
|
+
|
58
|
+
## Feature Foo (foo.feature)
|
59
|
+
|
60
|
+
### Background
|
61
|
+
|
62
|
+
Given something
|
63
|
+
|
64
|
+
### Scenario: Bar
|
65
|
+
|
66
|
+
Given a foo
|
67
|
+
When I bar
|
68
|
+
Then I baz
|
69
|
+
|
70
|
+
|
71
|
+
"""
|
72
|
+
|
73
|
+
Scenario: Extract Sentences from outlines
|
74
|
+
Given a file named "foo.feature" with:
|
75
|
+
"""
|
76
|
+
Feature: Foo
|
77
|
+
Scenario Outline: Bar
|
78
|
+
Given a <foo>
|
79
|
+
When I <bar>
|
80
|
+
Then I <baz>
|
81
|
+
|
82
|
+
Examples: table
|
83
|
+
| foo | bar | bazzzzzz |
|
84
|
+
| FOOoooo | BAR | BAZ |
|
85
|
+
| oof | rabbbbbbb | zab |
|
86
|
+
"""
|
87
|
+
When I run `ruby render_multi_markdown.rb`
|
88
|
+
Then it should pass with exactly:
|
89
|
+
"""
|
90
|
+
|
91
|
+
## Feature Foo (foo.feature)
|
92
|
+
|
93
|
+
### Scenario Outline: Bar
|
94
|
+
|
95
|
+
Given a <foo>
|
96
|
+
When I <bar>
|
97
|
+
Then I <baz>
|
98
|
+
|
99
|
+
#### Examples: table
|
100
|
+
|
101
|
+
| foo | bar | bazzzzzz |
|
102
|
+
| ------- | --------- | -------- |
|
103
|
+
| FOOoooo | BAR | BAZ |
|
104
|
+
| oof | rabbbbbbb | zab |
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
"""
|
110
|
+
|
111
|
+
Scenario: Extract Sentences considers description
|
112
|
+
Given a file named "foo.feature" with:
|
113
|
+
"""
|
114
|
+
Feature: Foo
|
115
|
+
As a user,
|
116
|
+
I want something
|
117
|
+
so that I have that
|
118
|
+
|
119
|
+
Scenario: Bar
|
120
|
+
Given a foo
|
121
|
+
When I bar
|
122
|
+
Then I baz
|
123
|
+
"""
|
124
|
+
When I run `ruby render_multi_markdown.rb`
|
125
|
+
Then it should pass with exactly:
|
126
|
+
"""
|
127
|
+
|
128
|
+
## Feature Foo (foo.feature)
|
129
|
+
|
130
|
+
As a user,
|
131
|
+
I want something
|
132
|
+
so that I have that
|
133
|
+
|
134
|
+
### Scenario: Bar
|
135
|
+
|
136
|
+
Given a foo
|
137
|
+
When I bar
|
138
|
+
Then I baz
|
139
|
+
|
140
|
+
|
141
|
+
"""
|
142
|
+
|
143
|
+
Scenario: Extract Sentences considers scenario description
|
144
|
+
Given a file named "foo.feature" with:
|
145
|
+
"""
|
146
|
+
Feature: Foo
|
147
|
+
As a user,
|
148
|
+
I want something
|
149
|
+
so that I have that
|
150
|
+
|
151
|
+
Scenario: Bar
|
152
|
+
This is a sentence description
|
153
|
+
|
154
|
+
Given a foo
|
155
|
+
When I bar
|
156
|
+
Then I baz
|
157
|
+
"""
|
158
|
+
When I run `ruby render_multi_markdown.rb`
|
159
|
+
Then it should pass with exactly:
|
160
|
+
"""
|
161
|
+
|
162
|
+
## Feature Foo (foo.feature)
|
163
|
+
|
164
|
+
As a user,
|
165
|
+
I want something
|
166
|
+
so that I have that
|
167
|
+
|
168
|
+
### Scenario: Bar
|
169
|
+
|
170
|
+
This is a sentence description
|
171
|
+
|
172
|
+
Given a foo
|
173
|
+
When I bar
|
174
|
+
Then I baz
|
175
|
+
|
176
|
+
|
177
|
+
"""
|
data/gherkin_format.gemspec
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
-
Gem::Specification.new do |
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'gherkin_format'
|
3
|
+
s.version = '0.0.2'
|
4
|
+
s.date = '2015-06-02'
|
5
|
+
s.summary = 'Gherkin Format'
|
6
|
+
s.description = 'Format Gherkin Files'
|
7
|
+
s.authors = ['Stefan Rohe']
|
8
|
+
s.homepage = 'http://github.com/funkwerk/gherkin_format/'
|
9
|
+
s.files = `git ls-files`.split("\n")
|
10
|
+
s.executables = s.files.grep(%r{^bin/}) { |file| File.basename(file) }
|
11
|
+
s.add_runtime_dependency 'gherkin', ['>= 2.12.2']
|
12
|
+
s.add_development_dependency 'aruba', ['>= 0.6.2']
|
12
13
|
end
|
data/lib/gherkin_format.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
require 'gherkin/formatter/json_formatter'
|
1
2
|
require 'gherkin/formatter/pretty_formatter'
|
2
3
|
require 'gherkin/parser/parser'
|
3
4
|
require 'stringio'
|
5
|
+
require 'multi_json'
|
6
|
+
require 'erb'
|
4
7
|
|
5
8
|
# format gherkin files
|
6
9
|
class GherkinFormat
|
@@ -25,4 +28,37 @@ class GherkinFormat
|
|
25
28
|
puts "File #{file} is not formatted well."
|
26
29
|
fail "File #{file} is not formatted well."
|
27
30
|
end
|
31
|
+
|
32
|
+
def render(template, files)
|
33
|
+
features = []
|
34
|
+
files.each do |file|
|
35
|
+
content = File.read file
|
36
|
+
features.push to_json(content, file)
|
37
|
+
end
|
38
|
+
renderer = ERB.new File.read template
|
39
|
+
features = Features.new features.flatten
|
40
|
+
puts renderer.result features.binding_reference
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_json(input, file = 'generated.feature')
|
44
|
+
io = StringIO.new
|
45
|
+
formatter = Gherkin::Formatter::JSONFormatter.new(io)
|
46
|
+
parser = Gherkin::Parser::Parser.new(formatter, true)
|
47
|
+
parser.parse(input, file, 0)
|
48
|
+
formatter.done
|
49
|
+
MultiJson.load io.string
|
50
|
+
end
|
51
|
+
|
52
|
+
# container class for erb variable
|
53
|
+
class Features
|
54
|
+
attr_accessor :features
|
55
|
+
|
56
|
+
def initialize(features)
|
57
|
+
@features = features
|
58
|
+
end
|
59
|
+
|
60
|
+
def binding_reference
|
61
|
+
binding
|
62
|
+
end
|
63
|
+
end
|
28
64
|
end
|
data/lib/markdown.erb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
<%
|
2
|
+
def feature_name(feature)
|
3
|
+
"Feature #{feature['name']} (#{feature['uri']})"
|
4
|
+
end
|
5
|
+
|
6
|
+
def tags(element)
|
7
|
+
return '' unless element.key? 'tags'
|
8
|
+
"\n\nTags: #{element['tags'].map { |tag| tag['name'] } * ' '}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def table(element)
|
12
|
+
return '' unless element.key? 'rows'
|
13
|
+
"\n" + element['rows'].map{ |row| "| #{row['cells'] * ' | '} |" } * "\n"
|
14
|
+
end
|
15
|
+
|
16
|
+
def description(element)
|
17
|
+
return '' unless element.key? 'description'
|
18
|
+
return '' if element['description'].strip.length == 0
|
19
|
+
"\n\n" + element['description']
|
20
|
+
end
|
21
|
+
|
22
|
+
def steps(scenario)
|
23
|
+
|
24
|
+
def docstring(step)
|
25
|
+
return '' unless step.key? 'doc_string'
|
26
|
+
"\n" + '"""' + "\n" + step['doc_string']['value'] + "\n" + '"""'
|
27
|
+
end
|
28
|
+
|
29
|
+
return '' unless scenario.key? 'steps'
|
30
|
+
|
31
|
+
"\n" + scenario['steps'].map do |step|
|
32
|
+
[step['keyword'], step['name'], docstring(step), table(step)].join
|
33
|
+
end * "\n"
|
34
|
+
end
|
35
|
+
|
36
|
+
def examples(element)
|
37
|
+
return '' unless element.key? 'examples'
|
38
|
+
"\n" + element['examples'].map do |example|
|
39
|
+
'#### ' + example['keyword'] + ': ' + example['name'] + "\n" + table(example)
|
40
|
+
end * "\n"
|
41
|
+
end
|
42
|
+
%>
|
43
|
+
<% for @feature in @features %>## <%= feature_name @feature %><%= tags @feature %>
|
44
|
+
<%= description @feature %>
|
45
|
+
<% for @element in @feature['elements'] %>
|
46
|
+
### <%= @element['keyword'] %>: <%= @element['name'] %><%= tags @element %><%= description @element %>
|
47
|
+
<%= steps @element %>
|
48
|
+
<%= examples @element %>
|
49
|
+
<% end %><% end %>
|
@@ -0,0 +1,102 @@
|
|
1
|
+
<%
|
2
|
+
|
3
|
+
def tags(element)
|
4
|
+
return '' unless element.key? 'tags'
|
5
|
+
"\n\nTags: #{element['tags'].map { |tag| escape(tag['name']) } * ' '}"
|
6
|
+
end
|
7
|
+
|
8
|
+
def table(element, name=nil)
|
9
|
+
return '' unless element.key? 'rows'
|
10
|
+
cell_sizes = []
|
11
|
+
element['rows'].each do |row|
|
12
|
+
sizes = row['cells'].map { |cell| escape(cell).length }
|
13
|
+
if cell_sizes == []
|
14
|
+
cell_sizes = sizes
|
15
|
+
next
|
16
|
+
end
|
17
|
+
cell_sizes = cell_sizes.zip sizes
|
18
|
+
cell_sizes.map! { |cells| cells.max }
|
19
|
+
end
|
20
|
+
|
21
|
+
result = "\n\n"
|
22
|
+
|
23
|
+
element['rows'].each do |row|
|
24
|
+
cell_with_size = row['cells'].zip cell_sizes
|
25
|
+
result += '| '
|
26
|
+
result += cell_with_size.map { |cell, size| escape(cell.ljust(size)) } * ' | '
|
27
|
+
result += " |\n"
|
28
|
+
if row == element['rows'][0]
|
29
|
+
result += '| '
|
30
|
+
result += cell_sizes.map { |size| '-' * size } * ' | '
|
31
|
+
result += " |\n"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
result += '[' + name + ']' unless name.nil?
|
35
|
+
result + "\n"
|
36
|
+
end
|
37
|
+
|
38
|
+
def description(element)
|
39
|
+
return '' unless element.key? 'description'
|
40
|
+
return '' if element['description'].strip.length == 0
|
41
|
+
"\n\n" + escape(element['description'].strip).lines.map { |line| "> #{line}" }.join
|
42
|
+
end
|
43
|
+
|
44
|
+
def steps(scenario)
|
45
|
+
|
46
|
+
def docstring(step)
|
47
|
+
return '' unless step.key? 'doc_string'
|
48
|
+
"\n" + '\"\"\"' + "\n" + escape(step['doc_string']['value']).lines.map { |line| "\t#{line}" }.join + "\n" + '\"\"\"'
|
49
|
+
end
|
50
|
+
|
51
|
+
return '' unless scenario.key? 'steps'
|
52
|
+
|
53
|
+
"\n\n" + scenario['steps'].map do |step|
|
54
|
+
['__', step['keyword'].strip, '__ ', highlight(escape(step['name'])), docstring(step), table(step)].join
|
55
|
+
end * "\n"
|
56
|
+
end
|
57
|
+
|
58
|
+
def escape(value)
|
59
|
+
value.gsub('<', '\<').gsub('>', '\>').gsub('*', '\*').gsub('#', '\#').gsub('-', '\-').gsub('[', '\[').gsub(']', '\]').gsub('|', '\|').gsub('"', '\"')
|
60
|
+
end
|
61
|
+
|
62
|
+
def highlight(value)
|
63
|
+
value.gsub('«', '_«').gsub('»', '»_').gsub('\<', '_\<').gsub('\>', '\>_')
|
64
|
+
end
|
65
|
+
|
66
|
+
def examples(element)
|
67
|
+
return '' unless element.key? 'examples'
|
68
|
+
"\n\n" + element['examples'].map do |example|
|
69
|
+
name = example['keyword'] + ': ' + escape(example['name'])
|
70
|
+
table(example, '_**' + name + '**_')
|
71
|
+
end * "\n"
|
72
|
+
end
|
73
|
+
|
74
|
+
def scenarios(element)
|
75
|
+
return '' unless element.key? 'elements'
|
76
|
+
element['elements'].map { |scenario_or_background| scenario(scenario_or_background) } * "\n"
|
77
|
+
end
|
78
|
+
|
79
|
+
def scenario(element)
|
80
|
+
elements = []
|
81
|
+
elements.push "\n"
|
82
|
+
elements.push '<h3 id="'
|
83
|
+
elements.push element['name']
|
84
|
+
elements.push '">'
|
85
|
+
elements.push element['keyword']
|
86
|
+
elements.push ': ' unless element['name'].empty?
|
87
|
+
elements.push element['name']
|
88
|
+
elements.push '</h3>'
|
89
|
+
elements.push tags element
|
90
|
+
elements.push description element
|
91
|
+
elements.push steps element
|
92
|
+
elements.push examples element
|
93
|
+
return elements.join
|
94
|
+
end
|
95
|
+
|
96
|
+
%>
|
97
|
+
<% for @feature in @features %><h2 id="<%= @feature['name'] %>"><%= @feature['name'] %></h2>
|
98
|
+
|
99
|
+
Source\: <%= @feature['uri'] %><%= tags @feature %><%= description @feature %>
|
100
|
+
<%= scenarios @feature %>
|
101
|
+
<hr />
|
102
|
+
<% end %>
|
@@ -0,0 +1,89 @@
|
|
1
|
+
<%
|
2
|
+
def feature_name(feature)
|
3
|
+
"Feature #{feature['name']} (#{feature['uri']})"
|
4
|
+
end
|
5
|
+
|
6
|
+
def tags(element)
|
7
|
+
return '' unless element.key? 'tags'
|
8
|
+
"\n\nTags: #{element['tags'].map { |tag| tag['name'] } * ' '}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def table(element)
|
12
|
+
return '' unless element.key? 'rows'
|
13
|
+
cell_sizes = []
|
14
|
+
element['rows'].each do |row|
|
15
|
+
sizes = row['cells'].map { |cell| cell.length }
|
16
|
+
if cell_sizes == []
|
17
|
+
cell_sizes = sizes
|
18
|
+
next
|
19
|
+
end
|
20
|
+
cell_sizes = cell_sizes.zip sizes
|
21
|
+
cell_sizes.map! { |cells| cells.max }
|
22
|
+
end
|
23
|
+
|
24
|
+
result = "\n"
|
25
|
+
|
26
|
+
element['rows'].each do |row|
|
27
|
+
cell_with_size = row['cells'].zip cell_sizes
|
28
|
+
result += '| '
|
29
|
+
result += cell_with_size.map { |cell, size| cell.ljust(size) } * ' | '
|
30
|
+
result += " |\n"
|
31
|
+
if row == element['rows'][0]
|
32
|
+
result += '| '
|
33
|
+
result += cell_sizes.map { |size| '-' * size } * ' | '
|
34
|
+
result += " |\n"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
result + "\n"
|
38
|
+
end
|
39
|
+
|
40
|
+
def description(element)
|
41
|
+
return '' unless element.key? 'description'
|
42
|
+
return '' if element['description'].strip.length == 0
|
43
|
+
"\n\n" + element['description'].strip
|
44
|
+
end
|
45
|
+
|
46
|
+
def steps(scenario)
|
47
|
+
|
48
|
+
def docstring(step)
|
49
|
+
return '' unless step.key? 'doc_string'
|
50
|
+
"\n" + '"""' + "\n" + step['doc_string']['value'] + "\n" + '"""'
|
51
|
+
end
|
52
|
+
|
53
|
+
return '' unless scenario.key? 'steps'
|
54
|
+
|
55
|
+
"\n\n" + scenario['steps'].map do |step|
|
56
|
+
[step['keyword'], step['name'], docstring(step), table(step)].join
|
57
|
+
end * "\n"
|
58
|
+
end
|
59
|
+
|
60
|
+
def examples(element)
|
61
|
+
return '' unless element.key? 'examples'
|
62
|
+
"\n\n" + element['examples'].map do |example|
|
63
|
+
'#### ' + example['keyword'] + ': ' + example['name'] + "\n" + table(example)
|
64
|
+
end * "\n"
|
65
|
+
end
|
66
|
+
|
67
|
+
def scenarios(element)
|
68
|
+
return '' unless element.key? 'elements'
|
69
|
+
element['elements'].map { |scenario_or_background| scenario(scenario_or_background) } * "\n"
|
70
|
+
end
|
71
|
+
|
72
|
+
def scenario(element)
|
73
|
+
elements = []
|
74
|
+
elements.push "\n"
|
75
|
+
elements.push '### '
|
76
|
+
elements.push element['keyword']
|
77
|
+
elements.push ': ' unless element['name'].empty?
|
78
|
+
elements.push element['name']
|
79
|
+
elements.push tags element
|
80
|
+
elements.push description element
|
81
|
+
elements.push steps element
|
82
|
+
elements.push examples element
|
83
|
+
return elements.join
|
84
|
+
end
|
85
|
+
|
86
|
+
%>
|
87
|
+
<% for @feature in @features %>## <%= feature_name @feature %><%= tags @feature %><%= description @feature %>
|
88
|
+
<%= scenarios @feature %>
|
89
|
+
<% end %>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gherkin_format
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Rohe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gherkin
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 2.12.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: aruba
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.6.2
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.6.2
|
27
41
|
description: Format Gherkin Files
|
28
42
|
email:
|
29
43
|
executables:
|
@@ -31,13 +45,21 @@ executables:
|
|
31
45
|
extensions: []
|
32
46
|
extra_rdoc_files: []
|
33
47
|
files:
|
48
|
+
- ".travis.yml"
|
49
|
+
- Gemfile
|
34
50
|
- LICENSE
|
35
51
|
- README.md
|
36
52
|
- Rakefile
|
37
53
|
- bin/gherkin_format
|
54
|
+
- features/support/env.rb
|
55
|
+
- features/template.markdown.feature
|
56
|
+
- features/template.multi_markdown.feature
|
57
|
+
- features/template.multi_markdown_without_highlighting.feature
|
38
58
|
- gherkin_format.gemspec
|
39
59
|
- lib/gherkin_format.rb
|
40
|
-
-
|
60
|
+
- lib/markdown.erb
|
61
|
+
- lib/multi_markdown.erb
|
62
|
+
- lib/multi_markdown_without_highlight.erb
|
41
63
|
homepage: http://github.com/funkwerk/gherkin_format/
|
42
64
|
licenses: []
|
43
65
|
metadata: {}
|
data/test/test_gherkin_format.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
require 'gherkin_format'
|
3
|
-
|
4
|
-
# gherkin format test
|
5
|
-
class GherkinFormatTest < Minitest::Unit::TestCase
|
6
|
-
def setup
|
7
|
-
@format = GherkinFormat.new
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_formats_string
|
11
|
-
# setup
|
12
|
-
feature = %(Feature: Foo
|
13
|
-
Scenario: Bar)
|
14
|
-
expected = %(Feature: Foo
|
15
|
-
|
16
|
-
Scenario: Bar
|
17
|
-
)
|
18
|
-
|
19
|
-
# exercise
|
20
|
-
actual = @format.format_string(feature)
|
21
|
-
|
22
|
-
# verify
|
23
|
-
assert_equal expected, actual
|
24
|
-
end
|
25
|
-
end
|