turnip 3.1.0 → 4.0.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
  SHA256:
3
- metadata.gz: db04bddfd94b8b6e3e3c5a43fb62f45cb8322873b06ff8a0dd8636efb249b524
4
- data.tar.gz: 3aaa0f8839286df02a563fa2b7903e79747dedf29d27f93f7d737dceda0dfed3
3
+ metadata.gz: 8b5136318e39336ec82b97637d41586f2f8eb062b3a8f0b365bf12d69234f3b9
4
+ data.tar.gz: 5d2519ec243ddf02f790e69adfccb3a3ce768635e6c42f70b91b9f3fd2036a77
5
5
  SHA512:
6
- metadata.gz: 1e9deb546d2b5747a9ab0667e70baccb0469ac59eaa665ac97876258435d9bcfb512e74956ee3567237e8363238251d1a567749547f3e2b991a9d021bedfd733
7
- data.tar.gz: c824cf5ae72f02fd6150e38ec53f9c551a1a2a20768359b1e20efae22948fecce49e07dd6afb0131dbd212b50fbfb2ffbef6082a3e64b9602f41a661b91cced2
6
+ metadata.gz: 07f3ddd379dc52a69950e68bebbd11df4b6727d468feb198b17642c6b84980068846f9c4f00a8a87584ccf5dfb6f42c77fa9b494de5b2d971bf8e2443585c85b
7
+ data.tar.gz: d0ce8fe9c90673a2f3c815cffeb23fa0d37cce0c59726570971b1a9a95e0b615d86aa1d257824829a7f5a6d25099754212d8b568c1d18c0fd2e2b123441e0144
@@ -7,13 +7,21 @@ branches:
7
7
  only:
8
8
  - master
9
9
 
10
+ #
11
+ # Ignore JRuby until https://github.com/cucumber/cucumber/pull/486 is merged
12
+ #
13
+ matrix:
14
+ allow_failures:
15
+ - rvm: jruby
16
+ - rvm: 2.6.0
17
+
10
18
  rvm:
11
- - 2.2
12
19
  - 2.3.6
13
20
  - 2.4.3
14
- - 2.5.0
15
- - jruby-19mode
21
+ - 2.5.3
22
+ - 2.6.0
23
+ - jruby
16
24
 
17
25
  gemfile:
18
- - gemfiles/Gemfile-rspec-3.6.x
19
26
  - gemfiles/Gemfile-rspec-3.7.x
27
+ - gemfiles/Gemfile-rspec-3.8.x
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in turnip.gemspec
4
3
  gemspec
@@ -0,0 +1,25 @@
1
+ Feature: Gherkin 6 syntax
2
+
3
+ Background:
4
+ Given there is a monster with 2 hitpoints
5
+
6
+ Scenario: Battle
7
+ When I attack it
8
+ Then the monster should be alive
9
+ When I attack it
10
+ Then it should die
11
+
12
+ Rule: Battle with preemptive attack
13
+ Background:
14
+ Given I attack the monster and do 1 points damage
15
+
16
+ Example: battle
17
+ When I attack it
18
+ Then it should die
19
+
20
+ Rule: Battle with preemptive critical attack
21
+ Background:
22
+ Given I attack the monster and do 2 points damage
23
+
24
+ Example: battle
25
+ Then it should die
@@ -3,4 +3,4 @@ source "https://rubygems.org"
3
3
  # Specify your gem's dependencies in turnip.gemspec
4
4
  gemspec :path => '..'
5
5
 
6
- gem 'rspec', '~> 3.6.0'
6
+ gem 'rspec', '~> 3.8.0'
@@ -1,13 +1,13 @@
1
- require "gherkin/parser"
1
+ require "gherkin/gherkin"
2
2
  require 'turnip/node/feature'
3
3
 
4
4
  module Turnip
5
5
  class Builder
6
6
  def self.build(feature_file)
7
- parser = Gherkin::Parser.new
8
- result = parser.parse(File.read(feature_file))
7
+ messages = Gherkin::Gherkin.from_paths([feature_file], include_source: false, include_pickles: false)
8
+ result = messages.first&.gherkinDocument&.to_hash
9
9
 
10
- return nil unless result[:feature]
10
+ return nil if result.nil? || result[:feature].nil?
11
11
  Node::Feature.new(result[:feature])
12
12
  end
13
13
  end
@@ -42,7 +42,7 @@ module Turnip
42
42
  # @return [Array]
43
43
  #
44
44
  def header
45
- @header ||= @raw[:tableHeader][:cells].map { |c| c[:value] }
45
+ @header ||= @raw[:table_header][:cells].map { |c| c[:value] }
46
46
  end
47
47
 
48
48
  #
@@ -56,7 +56,7 @@ module Turnip
56
56
  # @return [Array]
57
57
  #
58
58
  def rows
59
- @rows ||= @raw[:tableBody].map do |row|
59
+ @rows ||= @raw[:table_body].map do |row|
60
60
  row[:cells].map { |c| c[:value] }
61
61
  end
62
62
  end
@@ -1,8 +1,7 @@
1
1
  require 'turnip/node/base'
2
2
  require 'turnip/node/tag'
3
- require 'turnip/node/scenario'
4
- require 'turnip/node/scenario_outline'
5
- require 'turnip/node/background'
3
+ require 'turnip/node/scenario_group_definition'
4
+ require 'turnip/node/rule'
6
5
 
7
6
  module Turnip
8
7
  module Node
@@ -20,55 +19,36 @@ module Turnip
20
19
  # children: [], # Array of Background, Scenario and Scenario Outline
21
20
  # }
22
21
  #
23
- class Feature < Base
22
+ class Feature < ScenarioGroupDefinition
24
23
  include HasTags
25
24
 
26
- def name
27
- @raw[:name]
28
- end
29
-
30
25
  def language
31
26
  @raw[:language]
32
27
  end
33
28
 
34
- def keyword
35
- @raw[:keyword]
36
- end
29
+ def children
30
+ @children ||= @raw[:children].map do |child|
31
+ unless child[:background].nil?
32
+ next Background.new(child[:background])
33
+ end
37
34
 
38
- def description
39
- @raw[:description]
40
- end
35
+ unless child[:scenario].nil?
36
+ klass = child[:scenario][:examples].empty? ? Scenario : ScenarioOutline
37
+ next klass.new(child[:scenario])
38
+ end
41
39
 
42
- def children
43
- @children ||= @raw[:children].map do |c|
44
- case c[:type]
45
- when :Background
46
- Background.new(c)
47
- when :Scenario
48
- Scenario.new(c)
49
- when :ScenarioOutline
50
- ScenarioOutline.new(c)
40
+ unless child[:rule].nil?
41
+ next Rule.new(child[:rule])
51
42
  end
52
43
  end.compact
53
44
  end
54
45
 
55
- def backgrounds
56
- @backgrounds ||= children.select do |c|
57
- c.is_a?(Background)
46
+ def rules
47
+ @rules ||= children.select do |c|
48
+ c.is_a?(Rule)
58
49
  end
59
50
  end
60
51
 
61
- def scenarios
62
- @scenarios ||= children.map do |c|
63
- case c
64
- when Scenario
65
- c
66
- when ScenarioOutline
67
- c.to_scenarios
68
- end
69
- end.flatten.compact
70
- end
71
-
72
52
  def metadata_hash
73
53
  super.merge(:type => Turnip.type, :turnip => true)
74
54
  end
@@ -0,0 +1,32 @@
1
+ require 'turnip/node/scenario_group_definition'
2
+
3
+ module Turnip
4
+ module Node
5
+ #
6
+ # @note Rule metadata generated by Gherkin
7
+ #
8
+ # {
9
+ # type: :Rule,
10
+ # location: { line: 10, column: 3 },
11
+ # keyword: 'Rule',
12
+ # name: 'Rule name',
13
+ # description: 'Rule description',
14
+ # children: [] # Array of Background, Scenario and Scenario Outline
15
+ # }
16
+ #
17
+ class Rule < ScenarioGroupDefinition
18
+ def children
19
+ @children ||= @raw[:children].map do |child|
20
+ unless child[:background].nil?
21
+ next Background.new(child[:background])
22
+ end
23
+
24
+ unless child[:scenario].nil?
25
+ klass = child[:scenario][:examples].empty? ? Scenario : ScenarioOutline
26
+ next klass.new(child[:scenario])
27
+ end
28
+ end.compact
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,39 @@
1
+ require 'turnip/node/base'
2
+ require 'turnip/node/scenario'
3
+ require 'turnip/node/scenario_outline'
4
+ require 'turnip/node/background'
5
+
6
+ module Turnip
7
+ module Node
8
+ class ScenarioGroupDefinition < Base
9
+ def name
10
+ @raw[:name]
11
+ end
12
+
13
+ def keyword
14
+ @raw[:keyword]
15
+ end
16
+
17
+ def description
18
+ @raw[:description]
19
+ end
20
+
21
+ def backgrounds
22
+ @backgrounds ||= children.select do |c|
23
+ c.is_a?(Background)
24
+ end
25
+ end
26
+
27
+ def scenarios
28
+ @scenarios ||= children.map do |c|
29
+ case c
30
+ when Scenario
31
+ c
32
+ when ScenarioOutline
33
+ c.to_scenarios
34
+ end
35
+ end.flatten.compact
36
+ end
37
+ end
38
+ end
39
+ end
@@ -65,13 +65,11 @@ module Turnip
65
65
  metadata[:steps].each do |step|
66
66
  step[:text] = substitute(step[:text], header, row)
67
67
 
68
- next if step[:argument].nil?
69
-
70
- case step[:argument][:type]
71
- when :DocString
72
- step[:argument][:content] = substitute(step[:argument][:content], header, row)
73
- when :DataTable
74
- step[:argument][:rows].map do |table_row|
68
+ case
69
+ when step[:doc_string]
70
+ step[:doc_string][:content] = substitute(step[:doc_string][:content], header, row)
71
+ when step[:data_table]
72
+ step[:data_table][:rows].map do |table_row|
75
73
  table_row[:cells].map do |cell|
76
74
  cell[:value] = substitute(cell[:value], header, row)
77
75
  end
@@ -31,13 +31,11 @@ module Turnip
31
31
  end
32
32
 
33
33
  def argument
34
- return nil if @raw[:argument].nil?
35
-
36
- @argument ||= case @raw[:argument][:type]
37
- when :DocString
38
- doc_string(@raw[:argument])
39
- when :DataTable
40
- data_table(@raw[:argument])
34
+ @argument ||= case
35
+ when @raw[:doc_string]
36
+ doc_string(@raw[:doc_string])
37
+ when @raw[:data_table]
38
+ data_table(@raw[:data_table])
41
39
  end
42
40
  end
43
41
 
@@ -70,14 +70,19 @@ module Turnip
70
70
 
71
71
  instance_eval <<-EOS, feature_file, feature.line
72
72
  context = ::RSpec.describe feature.name, feature.metadata_hash
73
- run_feature(context, feature, feature_file)
73
+ run_scenario_group(context, feature, feature_file)
74
74
  EOS
75
75
  end
76
76
 
77
77
  private
78
78
 
79
- def run_feature(context, feature, filename)
80
- background_steps = feature.backgrounds.map(&:steps).flatten
79
+ #
80
+ # @param [RSpec::ExampleGroups] context
81
+ # @param [Turnip::Node::Feature|Turnip::Node::Rule] group
82
+ # @param [String] filename
83
+ #
84
+ def run_scenario_group(context, group, filename)
85
+ background_steps = group.backgrounds.map(&:steps).flatten
81
86
 
82
87
  context.before do
83
88
  background_steps.each do |step|
@@ -85,7 +90,7 @@ module Turnip
85
90
  end
86
91
  end
87
92
 
88
- feature.scenarios.each do |scenario|
93
+ group.scenarios.each do |scenario|
89
94
  step_names = (background_steps + scenario.steps).map(&:to_s)
90
95
  description = step_names.join(' -> ')
91
96
 
@@ -99,6 +104,13 @@ module Turnip
99
104
  EOS
100
105
  end
101
106
  end
107
+
108
+ if group.is_a?(Turnip::Node::Feature)
109
+ group.rules.each do |rule|
110
+ rule_context = context.context(rule.name, { turnip: true })
111
+ run_scenario_group(rule_context, rule, filename)
112
+ end
113
+ end
102
114
  end
103
115
  end
104
116
  end
@@ -1,3 +1,3 @@
1
1
  module Turnip
2
- VERSION = '3.1.0'
2
+ VERSION = '4.0.0'
3
3
  end
@@ -12,7 +12,7 @@ describe 'The CLI', :type => :integration do
12
12
  end
13
13
 
14
14
  it "prints out failures and successes" do
15
- @result.should include('39 examples, 4 failures, 5 pending')
15
+ @result.should include('42 examples, 4 failures, 5 pending')
16
16
  end
17
17
 
18
18
  it "includes features in backtraces" do
@@ -20,7 +20,8 @@ Gem::Specification.new do |s|
20
20
  s.require_paths = ["lib"]
21
21
 
22
22
  s.add_runtime_dependency "rspec", [">=3.0", "<4.0"]
23
- s.add_runtime_dependency "gherkin", "~> 5.0"
23
+ s.add_runtime_dependency "gherkin", "~> 6.0"
24
24
  s.add_development_dependency "rake"
25
25
  s.add_development_dependency "pry"
26
+ s.add_development_dependency "pry-byebug"
26
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turnip
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Nicklas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-01 00:00:00.000000000 Z
11
+ date: 2019-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -36,14 +36,14 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '5.0'
39
+ version: '6.0'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '5.0'
46
+ version: '6.0'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -72,6 +72,20 @@ dependencies:
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: pry-byebug
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
75
89
  description: Provides the ability to define steps and run Gherkin files from with
76
90
  RSpec
77
91
  email:
@@ -91,6 +105,7 @@ files:
91
105
  - examples/backgrounds.feature
92
106
  - examples/blank.feature
93
107
  - examples/errors.feature
108
+ - examples/gherkin6_syntax.feature
94
109
  - examples/interpolation.feature
95
110
  - examples/multiline_string.feature
96
111
  - examples/pending.feature
@@ -114,8 +129,8 @@ files:
114
129
  - examples/tags.feature
115
130
  - examples/with_backticks.feature
116
131
  - examples/with_comments.feature
117
- - gemfiles/Gemfile-rspec-3.6.x
118
132
  - gemfiles/Gemfile-rspec-3.7.x
133
+ - gemfiles/Gemfile-rspec-3.8.x
119
134
  - lib/turnip.rb
120
135
  - lib/turnip/builder.rb
121
136
  - lib/turnip/capybara.rb
@@ -127,8 +142,10 @@ files:
127
142
  - lib/turnip/node/example.rb
128
143
  - lib/turnip/node/feature.rb
129
144
  - lib/turnip/node/location.rb
145
+ - lib/turnip/node/rule.rb
130
146
  - lib/turnip/node/scenario.rb
131
147
  - lib/turnip/node/scenario_definition.rb
148
+ - lib/turnip/node/scenario_group_definition.rb
132
149
  - lib/turnip/node/scenario_outline.rb
133
150
  - lib/turnip/node/step.rb
134
151
  - lib/turnip/node/tag.rb
@@ -166,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
183
  version: '0'
167
184
  requirements: []
168
185
  rubyforge_project: turnip
169
- rubygems_version: 2.7.3
186
+ rubygems_version: 2.7.6
170
187
  signing_key:
171
188
  specification_version: 4
172
189
  summary: Gherkin extension for RSpec