turnip 2.1.1 → 3.0.0.pre.beta.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4688d31baee09b9a1620f80d29a619ac86d73db9
4
- data.tar.gz: 6c2ca9e0469398260c5f558bfb4c0a43f24a752b
3
+ metadata.gz: a8425f714759628ba119de6a3d1c4f8d7b8822c1
4
+ data.tar.gz: 342a721605fd9f29e0812962c1abbd7f98d5eaa7
5
5
  SHA512:
6
- metadata.gz: da9af90c2aa18ea9bdb22b4854fd60e64cb4652b2c247cf1701afcf2ebce10d924e96ca8bba1168d5320205e8a15d74acbf5ca071f33232968435b84254be249
7
- data.tar.gz: 139d1bd5f7af49ca90545ec0a31c216dcdd37bfd264b0cb74a2d016713c49cf9634494c2e75177bc1a33dcdb87e02d2dd9cf3b9072ade20a61643361028944aa
6
+ metadata.gz: 83c07693eb5d083086cbd570532566e3bbcdbce60b5114f57091612b2d4dc1ec25b46794d9c5603eee547a4167eaad555d6cc9969a8bac2e53941455b51ad649
7
+ data.tar.gz: 2116eac308a84e0d4119f26fef894dafd9fcfbf11d34671297bf50920268e8b4a2102da61aeae8b43396a1c4a1fad0f16847b23aa45ccba2575367461059ba64
@@ -1,10 +1,11 @@
1
- require "gherkin"
1
+ require "gherkin/parser"
2
+ require "gherkin/token_scanner"
2
3
 
3
4
  module Turnip
4
5
  class Builder
5
6
  module Tags
6
7
  def tags
7
- @raw.tags.map { |tag| tag.name.sub(/^@/, '') }
8
+ @raw[:tags].map { |tag| tag[:name].sub(/^@/, '') }
8
9
  end
9
10
 
10
11
  def tags_hash
@@ -18,13 +19,30 @@ module Turnip
18
19
 
19
20
  module Name
20
21
  def name
21
- @raw.name
22
+ @raw[:name]
22
23
  end
23
24
  end
24
25
 
25
26
  module Line
26
27
  def line
27
- @raw.line
28
+ @raw[:location][:line]
29
+ end
30
+ end
31
+
32
+ module Steps
33
+ def steps
34
+ @steps ||= @raw[:steps].map do |step|
35
+ extra_args = []
36
+ if (arg = step[:argument])
37
+ if arg[:type] == :DataTable
38
+ table = Turnip::Table.new(arg[:rows].map {|r| r[:cells].map {|c| c[:value]}})
39
+ extra_args.push(table)
40
+ else
41
+ extra_args.push arg[:content]
42
+ end
43
+ end
44
+ Step.new(step[:text], extra_args, step[:location][:line], step[:keyword])
45
+ end
28
46
  end
29
47
  end
30
48
 
@@ -48,10 +66,10 @@ module Turnip
48
66
  end
49
67
 
50
68
  class Background
51
- attr_reader :steps
69
+ include Steps
70
+
52
71
  def initialize(raw)
53
72
  @raw = raw
54
- @steps = []
55
73
  end
56
74
  end
57
75
 
@@ -59,47 +77,48 @@ module Turnip
59
77
  include Tags
60
78
  include Name
61
79
  include Line
80
+ include Steps
62
81
 
63
- attr_accessor :steps
82
+ attr_writer :steps
64
83
 
65
84
  def initialize(raw)
66
85
  @raw = raw
67
- @steps = []
68
86
  end
69
87
  end
70
88
 
71
89
  class ScenarioOutline
72
90
  include Tags
73
91
  include Name
74
-
75
- attr_reader :steps
92
+ include Steps
76
93
 
77
94
  def initialize(raw)
78
95
  @raw = raw
79
- @steps = []
80
- end
81
-
82
- def to_scenarios(examples)
83
- rows = examples.rows.map(&:cells)
84
- headers = rows.shift
85
- rows.map do |row|
86
- Scenario.new(@raw).tap do |scenario|
87
- scenario.steps = steps.map do |step|
88
- new_description = substitute(step.description, headers, row)
89
- new_extra_args = step.extra_args.map do |ea|
90
- case ea
91
- when String
92
- substitute(ea, headers, row)
93
- when Turnip::Table
94
- Turnip::Table.new(ea.map {|t_row| t_row.map {|t_col| substitute(t_col, headers, row) } })
95
- else
96
- ea
96
+ end
97
+
98
+ def to_scenarios
99
+ return [] unless @raw[:examples]
100
+ @raw[:examples].map { |example|
101
+ headers = example[:tableHeader][:cells].map {|c| c[:value]}
102
+ rows = example[:tableBody].map {|r| r[:cells].map {|c| c[:value]}}
103
+ rows.map do |row|
104
+ Scenario.new(@raw).tap do |scenario|
105
+ scenario.steps = steps.map do |step|
106
+ new_description = substitute(step.description, headers, row)
107
+ new_extra_args = step.extra_args.map do |ea|
108
+ case ea
109
+ when String
110
+ substitute(ea, headers, row)
111
+ when Turnip::Table
112
+ Turnip::Table.new(ea.map {|t_row| t_row.map {|t_col| substitute(t_col, headers, row) } })
113
+ else
114
+ ea
115
+ end
97
116
  end
117
+ Step.new(new_description, new_extra_args, step.line, step.keyword)
98
118
  end
99
- Step.new(new_description, new_extra_args, step.line, step.keyword)
100
119
  end
101
120
  end
102
- end
121
+ }.flatten
103
122
  end
104
123
 
105
124
  private
@@ -120,8 +139,9 @@ module Turnip
120
139
  class << self
121
140
  def build(feature_file)
122
141
  Turnip::Builder.new.tap do |builder|
123
- parser = Gherkin::Parser::Parser.new(builder, true)
124
- parser.parse(File.read(feature_file), feature_file, 0)
142
+ parser = Gherkin::Parser.new
143
+ result = parser.parse(File.read(feature_file))
144
+ builder.build(result)
125
145
  end
126
146
  end
127
147
  end
@@ -130,44 +150,21 @@ module Turnip
130
150
  @features = []
131
151
  end
132
152
 
133
- def background(background)
134
- @current_step_context = Background.new(background)
135
- @current_feature.backgrounds << @current_step_context
136
- end
137
-
138
- def feature(feature)
139
- @current_feature = Feature.new(feature)
140
- @features << @current_feature
141
- end
142
-
143
- def scenario(scenario)
144
- @current_step_context = Scenario.new(scenario)
145
- @current_feature.scenarios << @current_step_context
146
- end
147
-
148
- def scenario_outline(outline)
149
- @current_step_context = ScenarioOutline.new(outline)
150
- end
151
-
152
- def examples(examples)
153
- @current_feature.scenarios.push(*@current_step_context.to_scenarios(examples))
154
- end
155
-
156
- def step(step)
157
- extra_args = []
158
- if step.doc_string
159
- extra_args.push step.doc_string.value
160
- elsif step.rows
161
- table = Turnip::Table.new(step.rows.map(&:cells).map(&:to_a))
162
- extra_args.push(table)
153
+ def build(attributes)
154
+ return unless attributes[:feature]
155
+ attr = attributes[:feature]
156
+ feature = Feature.new(attr)
157
+ attr[:children].each do |child|
158
+ case child[:type]
159
+ when :Background
160
+ feature.backgrounds << Background.new(child)
161
+ when :Scenario
162
+ feature.scenarios << Scenario.new(child)
163
+ else
164
+ feature.scenarios.push(*ScenarioOutline.new(child).to_scenarios)
165
+ end
163
166
  end
164
- @current_step_context.steps << Step.new(step.name, extra_args, step.line, step.keyword)
165
- end
166
-
167
- def uri(*)
168
- end
169
-
170
- def eof
167
+ @features << feature
171
168
  end
172
169
  end
173
170
  end
@@ -1,3 +1,3 @@
1
1
  module Turnip
2
- VERSION = '2.1.1'
2
+ VERSION = '3.0.0-beta.1'
3
3
  end
data/turnip.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  s.add_runtime_dependency "rspec", [">=3.0", "<4.0"]
22
- s.add_runtime_dependency "gherkin", "~> 2.5"
22
+ s.add_runtime_dependency "gherkin", "~> 4.0"
23
23
  s.add_development_dependency "rake"
24
24
  s.add_development_dependency "pry"
25
25
  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: 2.1.1
4
+ version: 3.0.0.pre.beta.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Nicklas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-09 00:00:00.000000000 Z
11
+ date: 2016-09-22 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: '2.5'
39
+ version: '4.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: '2.5'
46
+ version: '4.0'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -150,9 +150,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
150
150
  version: '0'
151
151
  required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  requirements:
153
- - - ">="
153
+ - - ">"
154
154
  - !ruby/object:Gem::Version
155
- version: '0'
155
+ version: 1.3.1
156
156
  requirements: []
157
157
  rubyforge_project: turnip
158
158
  rubygems_version: 2.5.1