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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9efe1814b0c5cdfbd914a80f900c9cc066377e4
4
- data.tar.gz: 5a598253c9b72d40133a96712e8fb1535f695455
3
+ metadata.gz: c7ddf801d76b6879a3e7d348307f1f86e7160174
4
+ data.tar.gz: 4d1d99982cb6898dc9c487343f15fce09f93e732
5
5
  SHA512:
6
- metadata.gz: 68f6f7a7e2bb627f51619ebad972f9d73a7777b14f8e474cd520f69b0a1e62371423ea28672bef19dc236e785e75e6a8f22dc9a5afe7e16b20662897e6d187ea
7
- data.tar.gz: 09f8ab184f08990fefff3f1ebfbaca52f276153f8cf42ddfa1617c95193d82e5baa1b00d9178303afda4d69e0c3301340657333cc0dd2059fd505e83a2662c74
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 2015-10-31 21:09:23 +0100 using RuboCop version 0.34.2.
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: 3
9
+ # Offense count: 2
10
10
  Metrics/AbcSize:
11
- Max: 22
11
+ Max: 21
12
12
 
13
13
  # Offense count: 1
14
14
  # Configuration parameters: CountComments.
15
15
  Metrics/ClassLength:
16
- Max: 140
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: 115
22
+ Max: 111
22
23
 
23
- # Offense count: 2
24
+ # Offense count: 1
24
25
  # Configuration parameters: CountComments.
25
26
  Metrics/MethodLength:
26
- Max: 21
27
+ Max: 17
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
  gem 'aruba'
3
- gem 'gherkin', '=2.12.2'
3
+ gem 'gherkin', '=3.2.0'
4
4
  gem 'gherkin_lint'
5
5
  gem 'gherkin_format'
6
6
  gem 'rake'
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ task test: :cucumber
12
12
 
13
13
  desc 'Publishes the Gem'
14
14
  task push: :build do
15
- sh 'gem push gherkin_readability-0.0.5.gem'
15
+ sh 'gem push gherkin_readability-0.1.0.gem'
16
16
  end
17
17
 
18
18
  desc 'Checks ruby style'
@@ -1,14 +1,15 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'gherkin_readability'
3
- s.version = '0.0.5'
4
- s.date = '2016-01-17'
3
+ s.version = '0.1.0'
4
+ s.date = '2016-02-28'
5
5
  s.summary = 'Gherkin Readability'
6
- s.description = 'Check readability of Gherkin Files'
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.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']
@@ -1,8 +1,7 @@
1
1
  # encoding: utf-8
2
- gem 'gherkin', '=2.12.2'
2
+ gem 'gherkin', '=3.2.0'
3
3
 
4
- require 'gherkin/formatter/json_formatter'
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
- to_json(content, file)
77
+ Gherkin::Parser.new.parse content
79
78
  end
80
79
 
81
- def extract_sentences(parsed)
82
- feature_names = lambda do |input|
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 = feature_names.call(parsed) + descriptions.call(parsed) + scenario_names(parsed) + sentences(parsed)
91
- sentences.select! { |sentence| sentence }
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
- input.each do |features|
108
- next unless features.key? 'elements'
109
- elements = features['elements']
110
- elements.each do |scenario|
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
- input.each do |features|
123
- next unless features.key? 'elements'
124
- features['elements'].each do |scenario|
125
- next unless scenario.key? 'steps'
126
- terms = background.dup
127
- if scenario['type'] == 'background'
128
- background.push extract_terms_from_scenario(scenario['steps'], terms)
129
- next
130
- end
131
-
132
- terms.push extract_terms_from_scenario(scenario['steps'], background)
133
- sentence = terms.join(' ').strip
134
- if scenario.key? 'examples'
135
- sentences += extract_examples(scenario['examples'], sentence)
136
- else
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['keyword']
126
+ keyword = step[:keyword]
147
127
  keyword = 'and ' unless background.empty? || keyword != 'Given '
148
- terms = [keyword, step['name']].join
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['name'] unless example['name'].empty?
159
- sentences.push example['description'] unless example['description'].empty?
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['rows'][0]['cells']
172
- example['rows'].slice(1, example['rows'].length).each do |row|
150
+ headers = example[:tableHeader][:cells].map { |cell| cell[:value] }
151
+
152
+ example[:tableBody].each do |row|
173
153
  modified_sentence = sentence.dup
174
- headers.zip(row['cells']).map { |key, value| modified_sentence.gsub!("<#{key}>", value) }
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.5
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-01-17 00:00:00.000000000 Z
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.12.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.12.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: Check readability of Gherkin Files
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.5
111
+ rubygems_version: 2.2.2
111
112
  signing_key:
112
113
  specification_version: 4
113
114
  summary: Gherkin Readability