gherkin_readability 0.0.5 → 0.1.0
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/.rubocop.yml +9 -8
- data/Gemfile +1 -1
- data/Rakefile +1 -1
- data/gherkin_readability.gemspec +5 -4
- data/lib/gherkin_readability.rb +38 -57
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7ddf801d76b6879a3e7d348307f1f86e7160174
|
4
|
+
data.tar.gz: 4d1d99982cb6898dc9c487343f15fce09f93e732
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 307e3d01180f8bbc0144ec6ee36f16e7379cf5044059849c8e46dd2e30efeaf366c78649366889a685d4d345e27360e23dcd25253ed8d49cbebe284717e46883
|
7
|
+
data.tar.gz: e7645371433a2df1690c8f18405b1fcadc3fafb40a1be037181f050c7347051660f7c0400e073977e05f4d5e4acc7ea09d262d65a4294d5ba50a326b3d49b048
|
data/.rubocop.yml
CHANGED
@@ -1,26 +1,27 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
3
|
+
# on 2016-02-28 18:50:53 +0100 using RuboCop version 0.37.2.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
-
# Offense count:
|
9
|
+
# Offense count: 2
|
10
10
|
Metrics/AbcSize:
|
11
|
-
Max:
|
11
|
+
Max: 21
|
12
12
|
|
13
13
|
# Offense count: 1
|
14
14
|
# Configuration parameters: CountComments.
|
15
15
|
Metrics/ClassLength:
|
16
|
-
Max:
|
16
|
+
Max: 121
|
17
17
|
|
18
18
|
# Offense count: 8
|
19
|
-
# Configuration parameters: AllowURI, URISchemes.
|
19
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
|
20
|
+
# URISchemes: http, https
|
20
21
|
Metrics/LineLength:
|
21
|
-
Max:
|
22
|
+
Max: 111
|
22
23
|
|
23
|
-
# Offense count:
|
24
|
+
# Offense count: 1
|
24
25
|
# Configuration parameters: CountComments.
|
25
26
|
Metrics/MethodLength:
|
26
|
-
Max:
|
27
|
+
Max: 17
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/gherkin_readability.gemspec
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'gherkin_readability'
|
3
|
-
s.version = '0.0
|
4
|
-
s.date = '2016-
|
3
|
+
s.version = '0.1.0'
|
4
|
+
s.date = '2016-02-28'
|
5
5
|
s.summary = 'Gherkin Readability'
|
6
|
-
s.description = '
|
6
|
+
s.description = 'Determine readability of Gherkin Files'
|
7
7
|
s.authors = ['Stefan Rohe']
|
8
|
+
s.licenses = ['MIT']
|
8
9
|
s.homepage = 'http://github.com/funkwerk/gherkin_readability/'
|
9
10
|
s.files = `git ls-files`.split("\n")
|
10
11
|
s.executables = s.files.grep(%r{^bin/}) { |file| File.basename(file) }
|
11
|
-
s.add_runtime_dependency 'gherkin', ['= 2.
|
12
|
+
s.add_runtime_dependency 'gherkin', ['= 3.2.0']
|
12
13
|
s.add_runtime_dependency 'term-ansicolor', ['>= 1.3.2']
|
13
14
|
s.add_runtime_dependency 'syllables', ['>= 0.1.4']
|
14
15
|
s.add_development_dependency 'aruba', ['>= 0.6.2']
|
data/lib/gherkin_readability.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
gem 'gherkin', '=2.
|
2
|
+
gem 'gherkin', '=3.2.0'
|
3
3
|
|
4
|
-
require 'gherkin/
|
5
|
-
require 'gherkin/parser/parser'
|
4
|
+
require 'gherkin/parser'
|
6
5
|
require 'rexml/document'
|
7
6
|
require 'stringio'
|
8
7
|
require 'multi_json'
|
@@ -75,43 +74,26 @@ class GherkinReadability
|
|
75
74
|
|
76
75
|
def parse(file)
|
77
76
|
content = File.read file
|
78
|
-
|
77
|
+
Gherkin::Parser.new.parse content
|
79
78
|
end
|
80
79
|
|
81
|
-
def extract_sentences(
|
82
|
-
|
83
|
-
input.map { |feature| feature['name'] unless feature['name'] == '' }
|
84
|
-
end
|
85
|
-
|
86
|
-
descriptions = lambda do |input|
|
87
|
-
input.map { |feature| feature['description'] unless feature['description'] == '' }
|
88
|
-
end
|
80
|
+
def extract_sentences(input)
|
81
|
+
sentences = []
|
89
82
|
|
90
|
-
sentences
|
91
|
-
sentences.
|
83
|
+
sentences.push input[:name] unless input[:name].empty?
|
84
|
+
sentences.push input[:description] if input.key? :description
|
85
|
+
sentences.push input[:background][:name] if input.key?(:background) && !input[:background][:name].empty?
|
86
|
+
sentences += scenario_names input
|
87
|
+
sentences += sentences input
|
92
88
|
sentences.map { |sentence| sentence.gsub(/ «.+»/, '') }
|
93
89
|
end
|
94
90
|
|
95
|
-
def to_json(input, file = 'generated.feature')
|
96
|
-
io = StringIO.new
|
97
|
-
formatter = Gherkin::Formatter::JSONFormatter.new(io)
|
98
|
-
parser = Gherkin::Parser::Parser.new(formatter, true)
|
99
|
-
parser.parse(input, file, 0)
|
100
|
-
formatter.done
|
101
|
-
MultiJson.load io.string
|
102
|
-
end
|
103
|
-
|
104
91
|
def scenario_names(input)
|
105
|
-
# TODO: scenario outlines with example values inside?
|
106
92
|
scenarios = []
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
scenarios.push scenario['name'] if scenario['type'] == 'scenario'
|
112
|
-
scenarios.push scenario['name'] if scenario['type'] == 'scenario_outline'
|
113
|
-
scenarios.push scenario['description'] unless scenario['description'].empty?
|
114
|
-
end
|
93
|
+
|
94
|
+
input[:scenarioDefinitions].each do |scenario|
|
95
|
+
scenarios.push scenario[:name]
|
96
|
+
scenarios.push scenario[:description] if scenario.key? :description
|
115
97
|
end
|
116
98
|
scenarios
|
117
99
|
end
|
@@ -119,23 +101,21 @@ class GherkinReadability
|
|
119
101
|
def sentences(input)
|
120
102
|
sentences = []
|
121
103
|
background = []
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
sentences.push sentence
|
138
|
-
end
|
104
|
+
|
105
|
+
if input.key?(:background) && input[:background].key?(:steps)
|
106
|
+
background = extract_terms_from_scenario(input[:background][:steps], [])
|
107
|
+
end
|
108
|
+
|
109
|
+
input[:scenarioDefinitions].each do |scenario|
|
110
|
+
next unless scenario.key? :steps
|
111
|
+
terms = background.dup
|
112
|
+
|
113
|
+
terms.push extract_terms_from_scenario(scenario[:steps], background)
|
114
|
+
sentence = terms.join(' ').strip
|
115
|
+
if scenario.key? :examples
|
116
|
+
sentences += extract_examples(scenario[:examples], sentence)
|
117
|
+
else
|
118
|
+
sentences.push sentence
|
139
119
|
end
|
140
120
|
end
|
141
121
|
sentences
|
@@ -143,20 +123,19 @@ class GherkinReadability
|
|
143
123
|
|
144
124
|
def extract_terms_from_scenario(steps, background)
|
145
125
|
steps.map do |step|
|
146
|
-
keyword = step[
|
126
|
+
keyword = step[:keyword]
|
147
127
|
keyword = 'and ' unless background.empty? || keyword != 'Given '
|
148
|
-
terms = [keyword, step[
|
128
|
+
terms = [keyword, step[:text]].join
|
149
129
|
terms = uncapitalize(terms) unless background.empty?
|
150
130
|
background = terms
|
151
|
-
terms
|
152
131
|
end.flatten
|
153
132
|
end
|
154
133
|
|
155
134
|
def extract_examples(examples, prototype)
|
156
135
|
examples.map do |example|
|
157
136
|
sentences = []
|
158
|
-
sentences.push example[
|
159
|
-
sentences.push example[
|
137
|
+
sentences.push example[:name] unless example[:name].empty?
|
138
|
+
sentences.push example[:description] if example.key? :description
|
160
139
|
sentences += expand_outlines(prototype, example)
|
161
140
|
sentences
|
162
141
|
end.flatten
|
@@ -168,10 +147,12 @@ class GherkinReadability
|
|
168
147
|
|
169
148
|
def expand_outlines(sentence, example)
|
170
149
|
result = []
|
171
|
-
headers = example[
|
172
|
-
|
150
|
+
headers = example[:tableHeader][:cells].map { |cell| cell[:value] }
|
151
|
+
|
152
|
+
example[:tableBody].each do |row|
|
173
153
|
modified_sentence = sentence.dup
|
174
|
-
|
154
|
+
values = row[:cells].map { |cell| cell[:value] }
|
155
|
+
headers.zip(values).map { |key, value| modified_sentence.gsub!("<#{key}>", value) }
|
175
156
|
result.push modified_sentence
|
176
157
|
end
|
177
158
|
result
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gherkin_readability
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Rohe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gherkin
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: 3.2.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.
|
26
|
+
version: 3.2.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: term-ansicolor
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 0.6.2
|
69
|
-
description:
|
69
|
+
description: Determine readability of Gherkin Files
|
70
70
|
email:
|
71
71
|
executables:
|
72
72
|
- gherkin_readability
|
@@ -89,7 +89,8 @@ files:
|
|
89
89
|
- gherkin_readability.gemspec
|
90
90
|
- lib/gherkin_readability.rb
|
91
91
|
homepage: http://github.com/funkwerk/gherkin_readability/
|
92
|
-
licenses:
|
92
|
+
licenses:
|
93
|
+
- MIT
|
93
94
|
metadata: {}
|
94
95
|
post_install_message:
|
95
96
|
rdoc_options: []
|
@@ -107,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
108
|
version: '0'
|
108
109
|
requirements: []
|
109
110
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.2.
|
111
|
+
rubygems_version: 2.2.2
|
111
112
|
signing_key:
|
112
113
|
specification_version: 4
|
113
114
|
summary: Gherkin Readability
|