gherkin 2.0.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/History.txt +12 -0
  2. data/LICENSE +1 -1
  3. data/README.rdoc +2 -2
  4. data/Rakefile +2 -2
  5. data/VERSION.yml +2 -2
  6. data/features/json_formatter.feature +3 -41
  7. data/features/step_definitions/gherkin_steps.rb +5 -6
  8. data/features/step_definitions/json_formatter_steps.rb +3 -2
  9. data/features/step_definitions/json_lexer_steps.rb +5 -5
  10. data/features/step_definitions/pretty_formatter_steps.rb +9 -13
  11. data/features/support/env.rb +1 -1
  12. data/lib/gherkin/formatter/argument.rb +1 -0
  13. data/lib/gherkin/formatter/filter_formatter.rb +149 -0
  14. data/lib/gherkin/formatter/json_formatter.rb +35 -45
  15. data/lib/gherkin/formatter/line_filter.rb +26 -0
  16. data/lib/gherkin/formatter/model.rb +85 -0
  17. data/lib/gherkin/formatter/pretty_formatter.rb +36 -39
  18. data/lib/gherkin/formatter/regexp_filter.rb +17 -0
  19. data/lib/gherkin/formatter/tag_count_formatter.rb +44 -0
  20. data/lib/gherkin/i18n.rb +5 -5
  21. data/lib/gherkin/i18n.yml +13 -0
  22. data/lib/gherkin/i18n_lexer.rb +2 -2
  23. data/lib/gherkin/{json_lexer.rb → json_parser.rb} +17 -5
  24. data/lib/gherkin/{parser → listener}/event.rb +1 -1
  25. data/lib/gherkin/{parser → listener}/formatter_listener.rb +30 -23
  26. data/lib/gherkin/native/java.rb +9 -1
  27. data/lib/gherkin/parser/parser.rb +27 -14
  28. data/lib/gherkin/rubify.rb +5 -1
  29. data/lib/gherkin/tag_expression.rb +62 -0
  30. data/lib/gherkin/tools/files.rb +3 -4
  31. data/lib/gherkin/tools/reformat.rb +2 -2
  32. data/lib/gherkin/tools/stats.rb +3 -4
  33. data/lib/gherkin/tools/stats_listener.rb +1 -1
  34. data/ragel/lexer.c.rl.erb +2 -3
  35. data/ragel/lexer.java.rl.erb +1 -2
  36. data/ragel/lexer.rb.rl.erb +1 -2
  37. data/spec/gherkin/fixtures/complex_for_filtering.feature +60 -0
  38. data/spec/gherkin/fixtures/complex_with_tags.feature +61 -0
  39. data/spec/gherkin/fixtures/hantu_pisang.feature +35 -0
  40. data/spec/gherkin/formatter/filter_formatter_spec.rb +156 -0
  41. data/spec/gherkin/formatter/model_spec.rb +15 -0
  42. data/spec/gherkin/formatter/pretty_formatter_spec.rb +17 -16
  43. data/spec/gherkin/formatter/tag_count_formatter_spec.rb +31 -0
  44. data/spec/gherkin/i18n_lexer_spec.rb +3 -3
  45. data/spec/gherkin/i18n_spec.rb +2 -4
  46. data/spec/gherkin/{json_lexer_spec.rb → json_parser_spec.rb} +13 -8
  47. data/spec/gherkin/sexp_recorder.rb +10 -4
  48. data/spec/gherkin/shared/lexer_group.rb +0 -40
  49. data/spec/gherkin/shared/py_string_group.rb +0 -1
  50. data/spec/gherkin/shared/row_group.rb +1 -2
  51. data/spec/gherkin/tag_expression_spec.rb +137 -0
  52. data/spec/spec_helper.rb +5 -1
  53. data/tasks/bench.rake +5 -9
  54. metadata +35 -25
  55. data/lib/gherkin/parser/filter_listener.rb +0 -203
  56. data/lib/gherkin/parser/row.rb +0 -15
  57. data/lib/gherkin/parser/tag_expression.rb +0 -50
  58. data/spec/gherkin/parser/filter_listener_spec.rb +0 -397
  59. data/spec/gherkin/parser/formatter_listener_spec.rb +0 -134
  60. data/spec/gherkin/parser/parser_spec.rb +0 -50
  61. data/spec/gherkin/parser/tag_expression_spec.rb +0 -116
@@ -52,7 +52,6 @@ EOS
52
52
  it "should parse content separated by two newlines" do
53
53
  scan ps("A\n\nB")
54
54
  @listener.to_sexp.should == [
55
- [:location, 'test.feature', 0],
56
55
  [:py_string, "A\n\nB", 1],
57
56
  [:eof]
58
57
  ]
@@ -5,7 +5,7 @@ module Gherkin
5
5
  module Lexer
6
6
  shared_examples_for "a Gherkin lexer lexing rows" do
7
7
  def scan(gherkin)
8
- @lexer.scan(gherkin, "test.feature", 0)
8
+ @lexer.scan(gherkin)
9
9
  end
10
10
 
11
11
  rows = {
@@ -43,7 +43,6 @@ module Gherkin
43
43
  it "should allow utf-8" do
44
44
  scan(" | ůﻚ | 2 | \n")
45
45
  @listener.to_sexp.should == [
46
- [:location, 'test.feature', 0],
47
46
  [:row, ["ůﻚ", "2"], 1],
48
47
  [:eof]
49
48
  ]
@@ -0,0 +1,137 @@
1
+ require 'spec_helper'
2
+ require 'gherkin/tag_expression'
3
+
4
+ module Gherkin
5
+ describe TagExpression do
6
+ context "no tags" do
7
+ before(:each) do
8
+ @e = Gherkin::TagExpression.new([])
9
+ end
10
+
11
+ it "should match @foo" do
12
+ @e.eval(['@foo']).should == true
13
+ end
14
+
15
+ it "should match empty tags" do
16
+ @e.eval([]).should == true
17
+ end
18
+ end
19
+
20
+ context "@foo" do
21
+ before(:each) do
22
+ @e = Gherkin::TagExpression.new(['@foo'])
23
+ end
24
+
25
+ it "should match @foo" do
26
+ @e.eval(['@foo']).should == true
27
+ end
28
+
29
+ it "should not match @bar" do
30
+ @e.eval(['@bar']).should == false
31
+ end
32
+
33
+ it "should not match no tags" do
34
+ @e.eval([]).should == false
35
+ end
36
+ end
37
+
38
+ context "!@foo" do
39
+ before(:each) do
40
+ @e = Gherkin::TagExpression.new(['~@foo'])
41
+ end
42
+
43
+ it "should match @bar" do
44
+ @e.eval(['@bar']).should == true
45
+ end
46
+
47
+ it "should not match @foo" do
48
+ @e.eval(['@foo']).should == false
49
+ end
50
+ end
51
+
52
+ context "@foo || @bar" do
53
+ before(:each) do
54
+ @e = Gherkin::TagExpression.new(['@foo,@bar'])
55
+ end
56
+
57
+ it "should match @foo" do
58
+ @e.eval(['@foo']).should == true
59
+ end
60
+
61
+ it "should match @bar" do
62
+ @e.eval(['@bar']).should == true
63
+ end
64
+
65
+ it "should not match @zap" do
66
+ @e.eval(['@zap']).should == false
67
+ end
68
+ end
69
+
70
+ context "(@foo || @bar) && !@zap" do
71
+ before(:each) do
72
+ @e = Gherkin::TagExpression.new(['@foo,@bar', '~@zap'])
73
+ end
74
+
75
+ it "should match @foo" do
76
+ @e.eval(['@foo']).should == true
77
+ end
78
+
79
+ it "should not match @foo @zap" do
80
+ @e.eval(['@foo', '@zap']).should == false
81
+ end
82
+ end
83
+
84
+ context "(@foo:3 || !@bar:4) && @zap:5" do
85
+ before(:each) do
86
+ @e = Gherkin::TagExpression.new(['@foo:3,~@bar','@zap:5'])
87
+ end
88
+
89
+ it "should count tags for positive tags" do
90
+ rubify_hash(@e.limits).should == {'@foo' => 3, '@zap' => 5}
91
+ end
92
+
93
+ it "should match @foo @zap" do
94
+ @e.eval(['@foo', '@zap']).should == true
95
+ end
96
+ end
97
+
98
+ context "Parsing '@foo:3,~@bar', '@zap:5'" do
99
+ before(:each) do
100
+ @e = Gherkin::TagExpression.new([' @foo:3 , ~@bar ', ' @zap:5 '])
101
+ end
102
+
103
+ unless defined?(JRUBY_VERSION)
104
+ it "should split and trim (ruby implementation detail)" do
105
+ @e.__send__(:ruby_expression).should == "(!vars['@bar']||vars['@foo'])&&(vars['@zap'])"
106
+ end
107
+ end
108
+
109
+ it "should have limits" do
110
+ rubify_hash(@e.limits).should == {"@zap"=>5, "@foo"=>3}
111
+ end
112
+ end
113
+
114
+ context "Tag limits" do
115
+ it "should be counted for negative tags" do
116
+ @e = Gherkin::TagExpression.new(['~@todo:3'])
117
+ rubify_hash(@e.limits).should == {"@todo"=>3}
118
+ end
119
+
120
+ it "should be counted for positive tags" do
121
+ @e = Gherkin::TagExpression.new(['@todo:3'])
122
+ rubify_hash(@e.limits).should == {"@todo"=>3}
123
+ end
124
+
125
+ it "should raise an error for inconsistent limits" do
126
+ lambda do
127
+ @e = Gherkin::TagExpression.new(['@todo:3', '~@todo:4'])
128
+ end.should raise_error(/Inconsistent tag limits for @todo: 3 and 4/)
129
+ end
130
+
131
+ it "should allow duplicate consistent limits" do
132
+ @e = Gherkin::TagExpression.new(['@todo:3', '~@todo:3'])
133
+ rubify_hash(@e.limits).should == {"@todo"=>3}
134
+ end
135
+ end
136
+ end
137
+ end
@@ -11,7 +11,11 @@ require 'gherkin/shared/row_group'
11
11
 
12
12
  module GherkinSpecHelper
13
13
  def scan_file(file)
14
- @lexer.scan(File.new(File.dirname(__FILE__) + "/gherkin/fixtures/" + file).read, file, 0)
14
+ @lexer.scan(fixture(file))
15
+ end
16
+
17
+ def fixture(file)
18
+ File.new(File.dirname(__FILE__) + "/gherkin/fixtures/" + file).read
15
19
  end
16
20
 
17
21
  def rubify_hash(hash)
@@ -106,23 +106,19 @@ class Benchmarker
106
106
 
107
107
  def run_rb_gherkin
108
108
  require 'gherkin'
109
- require 'gherkin/i18n_lexer'
110
- require 'null_listener'
111
- parser = Gherkin::Parser::Parser.new(NullListener.new, true, "root")
112
- lexer = Gherkin::I18nLexer.new(parser, true)
109
+ require 'null_formatter'
110
+ parser = Gherkin::Parser::Parser.new(NullFormatter.new, true, "root", true)
113
111
  @features.each do |feature|
114
- lexer.scan(File.read(feature), feature, 0)
112
+ parser.parse(File.read(feature), feature, 0)
115
113
  end
116
114
  end
117
115
 
118
116
  def run_native_gherkin
119
117
  require 'gherkin'
120
- require 'gherkin/i18n_lexer'
121
118
  require 'null_listener'
122
- parser = Gherkin::Parser::Parser.new(NullListener.new, true, "root")
123
- lexer = Gherkin::I18nLexer.new(parser, false)
119
+ parser = Gherkin::Parser::Parser.new(NullFormatter.new, true, "root", false)
124
120
  @features.each do |feature|
125
- lexer.scan(File.read(feature), feature, 0)
121
+ parser.parse(File.read(feature), feature, 0)
126
122
  end
127
123
  end
128
124
 
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
+ - 1
8
9
  - 0
9
- - 2
10
- version: 2.0.2
10
+ version: 2.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mike Sassak
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-06-16 00:00:00 +02:00
20
+ date: 2010-07-12 00:00:00 +02:00
21
21
  default_executable: gherkin
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- hash: 62196469
47
+ hash: 62196477
48
48
  segments:
49
49
  - 2
50
50
  - 0
51
51
  - 0
52
52
  - beta
53
- - 11
54
- version: 2.0.0.beta.11
53
+ - 15
54
+ version: 2.0.0.beta.15
55
55
  type: :development
56
56
  version_requirements: *id002
57
57
  - !ruby/object:Gem::Dependency
@@ -62,12 +62,12 @@ dependencies:
62
62
  requirements:
63
63
  - - ~>
64
64
  - !ruby/object:Gem::Version
65
- hash: 61
65
+ hash: 55
66
66
  segments:
67
67
  - 0
68
68
  - 8
69
- - 1
70
- version: 0.8.1
69
+ - 4
70
+ version: 0.8.4
71
71
  type: :development
72
72
  version_requirements: *id003
73
73
  - !ruby/object:Gem::Dependency
@@ -101,6 +101,7 @@ extensions:
101
101
  - ext/gherkin_lexer_en/extconf.rb
102
102
  - ext/gherkin_lexer_en_au/extconf.rb
103
103
  - ext/gherkin_lexer_en_lol/extconf.rb
104
+ - ext/gherkin_lexer_en_pirate/extconf.rb
104
105
  - ext/gherkin_lexer_en_scouse/extconf.rb
105
106
  - ext/gherkin_lexer_en_tx/extconf.rb
106
107
  - ext/gherkin_lexer_eo/extconf.rb
@@ -160,6 +161,7 @@ files:
160
161
  - ext/gherkin_lexer_en/gherkin_lexer_en.c
161
162
  - ext/gherkin_lexer_en_au/gherkin_lexer_en_au.c
162
163
  - ext/gherkin_lexer_en_lol/gherkin_lexer_en_lol.c
164
+ - ext/gherkin_lexer_en_pirate/gherkin_lexer_en_pirate.c
163
165
  - ext/gherkin_lexer_en_scouse/gherkin_lexer_en_scouse.c
164
166
  - ext/gherkin_lexer_en_tx/gherkin_lexer_en_tx.c
165
167
  - ext/gherkin_lexer_eo/gherkin_lexer_eo.c
@@ -219,26 +221,28 @@ files:
219
221
  - lib/gherkin/formatter/argument.rb
220
222
  - lib/gherkin/formatter/colors.rb
221
223
  - lib/gherkin/formatter/escaping.rb
224
+ - lib/gherkin/formatter/filter_formatter.rb
222
225
  - lib/gherkin/formatter/json_formatter.rb
226
+ - lib/gherkin/formatter/line_filter.rb
227
+ - lib/gherkin/formatter/model.rb
223
228
  - lib/gherkin/formatter/monochrome_format.rb
224
229
  - lib/gherkin/formatter/pretty_formatter.rb
230
+ - lib/gherkin/formatter/regexp_filter.rb
231
+ - lib/gherkin/formatter/tag_count_formatter.rb
225
232
  - lib/gherkin/i18n.rb
226
233
  - lib/gherkin/i18n.yml
227
234
  - lib/gherkin/i18n_lexer.rb
228
- - lib/gherkin/json_lexer.rb
235
+ - lib/gherkin/json_parser.rb
236
+ - lib/gherkin/listener/event.rb
237
+ - lib/gherkin/listener/formatter_listener.rb
229
238
  - lib/gherkin/native.rb
230
239
  - lib/gherkin/native/ikvm.rb
231
240
  - lib/gherkin/native/java.rb
232
241
  - lib/gherkin/native/null.rb
233
- - lib/gherkin/parser/event.rb
234
- - lib/gherkin/parser/filter_listener.rb
235
- - lib/gherkin/parser/formatter_listener.rb
236
242
  - lib/gherkin/parser/meta.txt
237
243
  - lib/gherkin/parser/parser.rb
238
244
  - lib/gherkin/parser/root.txt
239
- - lib/gherkin/parser/row.rb
240
245
  - lib/gherkin/parser/steps.txt
241
- - lib/gherkin/parser/tag_expression.rb
242
246
  - lib/gherkin/rb_lexer.rb
243
247
  - lib/gherkin/rb_lexer/.gitignore
244
248
  - lib/gherkin/rb_lexer/README.rdoc
@@ -252,6 +256,7 @@ files:
252
256
  - lib/gherkin/rb_lexer/en.rb
253
257
  - lib/gherkin/rb_lexer/en_au.rb
254
258
  - lib/gherkin/rb_lexer/en_lol.rb
259
+ - lib/gherkin/rb_lexer/en_pirate.rb
255
260
  - lib/gherkin/rb_lexer/en_scouse.rb
256
261
  - lib/gherkin/rb_lexer/en_tx.rb
257
262
  - lib/gherkin/rb_lexer/eo.rb
@@ -287,6 +292,7 @@ files:
287
292
  - lib/gherkin/rb_lexer/zh_cn.rb
288
293
  - lib/gherkin/rb_lexer/zh_tw.rb
289
294
  - lib/gherkin/rubify.rb
295
+ - lib/gherkin/tag_expression.rb
290
296
  - lib/gherkin/tools.rb
291
297
  - lib/gherkin/tools/files.rb
292
298
  - lib/gherkin/tools/reformat.rb
@@ -302,7 +308,10 @@ files:
302
308
  - spec/gherkin/fixtures/comments_in_table.feature
303
309
  - spec/gherkin/fixtures/complex.feature
304
310
  - spec/gherkin/fixtures/complex.json
311
+ - spec/gherkin/fixtures/complex_for_filtering.feature
312
+ - spec/gherkin/fixtures/complex_with_tags.feature
305
313
  - spec/gherkin/fixtures/dos_line_endings.feature
314
+ - spec/gherkin/fixtures/hantu_pisang.feature
306
315
  - spec/gherkin/fixtures/i18n_fr.feature
307
316
  - spec/gherkin/fixtures/i18n_no.feature
308
317
  - spec/gherkin/fixtures/i18n_zh-CN.feature
@@ -311,24 +320,24 @@ files:
311
320
  - spec/gherkin/fixtures/with_bom.feature
312
321
  - spec/gherkin/formatter/argument_spec.rb
313
322
  - spec/gherkin/formatter/colors_spec.rb
323
+ - spec/gherkin/formatter/filter_formatter_spec.rb
324
+ - spec/gherkin/formatter/model_spec.rb
314
325
  - spec/gherkin/formatter/pretty_formatter_spec.rb
315
326
  - spec/gherkin/formatter/spaces.feature
316
327
  - spec/gherkin/formatter/tabs.feature
328
+ - spec/gherkin/formatter/tag_count_formatter_spec.rb
317
329
  - spec/gherkin/i18n_lexer_spec.rb
318
330
  - spec/gherkin/i18n_spec.rb
319
331
  - spec/gherkin/java_lexer_spec.rb
320
- - spec/gherkin/json_lexer_spec.rb
332
+ - spec/gherkin/json_parser_spec.rb
321
333
  - spec/gherkin/output_stream_string_io.rb
322
- - spec/gherkin/parser/filter_listener_spec.rb
323
- - spec/gherkin/parser/formatter_listener_spec.rb
324
- - spec/gherkin/parser/parser_spec.rb
325
- - spec/gherkin/parser/tag_expression_spec.rb
326
334
  - spec/gherkin/rb_lexer_spec.rb
327
335
  - spec/gherkin/sexp_recorder.rb
328
336
  - spec/gherkin/shared/lexer_group.rb
329
337
  - spec/gherkin/shared/py_string_group.rb
330
338
  - spec/gherkin/shared/row_group.rb
331
339
  - spec/gherkin/shared/tags_group.rb
340
+ - spec/gherkin/tag_expression_spec.rb
332
341
  - spec/spec_helper.rb
333
342
  - tasks/bench.rake
334
343
  - tasks/bench/feature_builder.rb
@@ -352,6 +361,7 @@ files:
352
361
  - ext/gherkin_lexer_en/extconf.rb
353
362
  - ext/gherkin_lexer_en_au/extconf.rb
354
363
  - ext/gherkin_lexer_en_lol/extconf.rb
364
+ - ext/gherkin_lexer_en_pirate/extconf.rb
355
365
  - ext/gherkin_lexer_en_scouse/extconf.rb
356
366
  - ext/gherkin_lexer_en_tx/extconf.rb
357
367
  - ext/gherkin_lexer_eo/extconf.rb
@@ -424,20 +434,20 @@ test_files:
424
434
  - spec/gherkin/c_lexer_spec.rb
425
435
  - spec/gherkin/formatter/argument_spec.rb
426
436
  - spec/gherkin/formatter/colors_spec.rb
437
+ - spec/gherkin/formatter/filter_formatter_spec.rb
438
+ - spec/gherkin/formatter/model_spec.rb
427
439
  - spec/gherkin/formatter/pretty_formatter_spec.rb
440
+ - spec/gherkin/formatter/tag_count_formatter_spec.rb
428
441
  - spec/gherkin/i18n_lexer_spec.rb
429
442
  - spec/gherkin/i18n_spec.rb
430
443
  - spec/gherkin/java_lexer_spec.rb
431
- - spec/gherkin/json_lexer_spec.rb
444
+ - spec/gherkin/json_parser_spec.rb
432
445
  - spec/gherkin/output_stream_string_io.rb
433
- - spec/gherkin/parser/filter_listener_spec.rb
434
- - spec/gherkin/parser/formatter_listener_spec.rb
435
- - spec/gherkin/parser/parser_spec.rb
436
- - spec/gherkin/parser/tag_expression_spec.rb
437
446
  - spec/gherkin/rb_lexer_spec.rb
438
447
  - spec/gherkin/sexp_recorder.rb
439
448
  - spec/gherkin/shared/lexer_group.rb
440
449
  - spec/gherkin/shared/py_string_group.rb
441
450
  - spec/gherkin/shared/row_group.rb
442
451
  - spec/gherkin/shared/tags_group.rb
452
+ - spec/gherkin/tag_expression_spec.rb
443
453
  - spec/spec_helper.rb
@@ -1,203 +0,0 @@
1
- require 'gherkin/parser/event'
2
- require 'gherkin/parser/tag_expression'
3
- require 'gherkin/native'
4
-
5
- module Gherkin
6
- module Parser
7
- # This class filters events based on filter criteria.
8
- class FilterListener
9
- native_impl('gherkin')
10
-
11
- # Creates a new instance that replays events to +listener+, filtered by +filters+,
12
- # an Array that can contain one of the following:
13
- #
14
- # * Line numbers (Fixnum) to filter on.
15
- # * Name regexen (Regexp) to filter on. Matches against :feature, :background, :scenario, :scenario_outline and :examples
16
- # * Tag expressions (String) to filter on.
17
- #
18
- def initialize(listener, filters)
19
- @listener = listener
20
- @filter_method = detect_filter(filters)
21
-
22
- @meta_buffer = []
23
- @feature_buffer = []
24
- @scenario_buffer = []
25
- @examples_buffer = []
26
- @examples_rows_buffer = []
27
-
28
- @feature_tags = []
29
- @scenario_tags = []
30
- @example_tags = []
31
-
32
- @table_state = :step
33
- end
34
-
35
- def location(uri, offset)
36
- @listener.location(uri, offset)
37
- end
38
-
39
- private
40
-
41
- def method_missing(*event_args)
42
- event = Event.new(event_args)
43
-
44
- return event.replay(@listener) if no_filters?
45
-
46
- case(event.event)
47
- when :tag
48
- @meta_buffer << event
49
- when :comment
50
- @meta_buffer << event
51
- when :feature
52
- @feature_buffer = @meta_buffer
53
- @feature_buffer << event
54
- @feature_tags = extract_tags
55
- @meta_buffer = []
56
- @feature_ok = true if filter_match?(event)
57
- when :background
58
- @feature_buffer += @meta_buffer
59
- @feature_buffer << event
60
- @meta_buffer = []
61
- @table_state = :background
62
- @background_ok = true if filter_match?(event)
63
- when :scenario
64
- replay_examples_rows_buffer
65
- @scenario_buffer = @meta_buffer
66
- @scenario_buffer << event
67
- @scenario_tags = extract_tags
68
- @example_tags = []
69
- @meta_buffer = []
70
- @scenario_ok = filter_match?(*@scenario_buffer) || tag_match?
71
- @examples_ok = false
72
- @background_ok = false
73
- @table_state = :step
74
- when :scenario_outline
75
- replay_examples_rows_buffer
76
- @scenario_buffer = @meta_buffer
77
- @scenario_buffer << event
78
- @scenario_tags = extract_tags
79
- @example_tags = []
80
- @meta_buffer = []
81
- @scenario_ok = filter_match?(*@scenario_buffer)
82
- @examples_ok = false
83
- @background_ok = false
84
- @table_state = :step
85
- when :examples
86
- replay_examples_rows_buffer
87
- @examples_buffer = @meta_buffer
88
- @examples_buffer << event
89
- @example_tags = extract_tags
90
- @meta_buffer = []
91
- @examples_rows_buffer = []
92
- @examples_ok = filter_match?(*@examples_buffer) || tag_match?
93
- @table_state = :examples
94
- when :step
95
- case(@table_state)
96
- when :background
97
- @feature_buffer += @meta_buffer
98
- @feature_buffer << event
99
- @meta_buffer = []
100
- @background_ok = true if filter_match?(event)
101
- else
102
- @scenario_buffer << event
103
- @scenario_ok ||= filter_match?(*@scenario_buffer)
104
- @table_state = :step
105
- end
106
- when :row
107
- case(@table_state)
108
- when :examples
109
- unless header_row_already_buffered?
110
- @examples_buffer << event
111
- @examples_ok = true if filter_match?(*@examples_buffer)
112
- else
113
- @examples_rows_buffer << event if @scenario_ok || @examples_ok || @feature_ok || filter_match?(event)
114
- end
115
- when :step
116
- @scenario_buffer << event
117
- @scenario_ok ||= filter_match?(*@scenario_buffer)
118
- when :background
119
- @feature_buffer += @meta_buffer
120
- @feature_buffer << event
121
- @meta_buffer = []
122
- else
123
- raise "Bad table_state:#{@table_state.inspect}"
124
- end
125
- when :py_string
126
- if @table_state == :background
127
- @feature_buffer << event
128
- @feature_ok ||= filter_match?(*@feature_buffer)
129
- else
130
- @scenario_buffer << event
131
- @scenario_ok ||= filter_match?(*@scenario_buffer)
132
- end
133
- when :eof
134
- replay_examples_rows_buffer
135
- event.replay(@listener)
136
- return
137
- else
138
- super
139
- end
140
-
141
- if @scenario_ok || @examples_ok || @feature_ok || @background_ok
142
- replay_buffers
143
- end
144
- end
145
-
146
- def detect_filter(filters)
147
- @filters = filters
148
- raise "Bad filter: #{filters.inspect}" if filters.map{|filter| filter.class}.uniq.length > 1
149
- @filter_method = case(filters[0])
150
- when Fixnum
151
- :line_match?
152
- when Regexp
153
- :name_match?
154
- when String
155
- TagExpression.new(filters)
156
- end
157
- end
158
-
159
- def no_filters?
160
- @filters.empty?
161
- end
162
-
163
- def header_row_already_buffered?
164
- return @examples_buffer.any? && @examples_buffer[-1].event == :row
165
- end
166
-
167
- def filter_match?(*events)
168
- return false unless[:name_match?, :line_match?].include?(@filter_method)
169
- events.detect{|event| event.__send__(@filter_method, @filters)}
170
- end
171
-
172
- def tag_match?
173
- return TagExpression === @filter_method && @filter_method.eval(current_tags)
174
- end
175
-
176
- def replay_buffers
177
- (@feature_buffer + @scenario_buffer).each do |event|
178
- event.replay(@listener)
179
- end
180
- @feature_buffer = []
181
- @scenario_buffer = []
182
- end
183
-
184
- def replay_examples_rows_buffer
185
- if @examples_rows_buffer.any?
186
- replay_buffers
187
- (@examples_buffer + @examples_rows_buffer).each do |event|
188
- event.replay(@listener)
189
- end
190
- @examples_rows_buffer = []
191
- end
192
- end
193
-
194
- def current_tags
195
- @feature_tags + @scenario_tags + @example_tags
196
- end
197
-
198
- def extract_tags
199
- @meta_buffer.select { |event| event.event == :tag }.map { |event| event.keyword }
200
- end
201
- end
202
- end
203
- end