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
@@ -1,134 +0,0 @@
1
- require 'spec_helper'
2
- require 'gherkin/parser/formatter_listener'
3
- require 'gherkin/parser/parser'
4
- require 'gherkin/parser/row'
5
- require 'gherkin/i18n_lexer'
6
- require 'stringio'
7
-
8
- module Gherkin
9
- module Parser
10
- describe FormatterListener do
11
- before do
12
- @formatter = Gherkin::SexpRecorder.new
13
- @fl = Gherkin::Parser::FormatterListener.new(@formatter)
14
- @lexer = Gherkin::I18nLexer.new(Gherkin::Parser::Parser.new(@fl))
15
- end
16
-
17
- it "should pass tags to #feature method" do
18
- @fl.tag("@hello", 1)
19
- @fl.feature("Feature", "awesome", "description", 2)
20
- @fl.eof
21
-
22
- @formatter.to_sexp.should == [
23
- [:feature, [], ["@hello"], "Feature", "awesome", "description", nil],
24
- [:eof]
25
- ]
26
- end
27
-
28
- it "should pass comments to #feature method" do
29
- @fl.comment("# comment", 1)
30
- @fl.feature("Feature", "awesome", "description", 2)
31
- @fl.eof
32
-
33
- @formatter.to_sexp.should == [
34
- [:feature, ["# comment"], [], "Feature", "awesome", "description", nil],
35
- [:eof]
36
- ]
37
- end
38
-
39
- it "should pass comments and tags to #feature and #scenario methods" do
40
- @fl.comment("# one", 1)
41
- @fl.tag("@two", 2)
42
- @fl.feature("Feature", "three", "feature description", 3)
43
- @fl.comment("# four", 4)
44
- @fl.tag("@five", 5)
45
- @fl.scenario("Scenario", "six", "scenario description", 6)
46
- @fl.eof
47
-
48
- @formatter.to_sexp.should == [
49
- [:feature, ["# one"], ["@two"], "Feature", "three", "feature description", nil],
50
- [:scenario, ["# four"], ["@five"], "Scenario", "six", "scenario description", 6],
51
- [:eof]
52
- ]
53
- end
54
-
55
- it "should replay step table" do
56
- @fl.step("Given ", "foo", 10)
57
- @fl.row(['yo'], 11)
58
- @fl.comment("# Hello", 12)
59
- @fl.comment("# World", 13)
60
- @fl.row(['bro'], 14)
61
- @fl.eof
62
-
63
- @formatter.to_sexp.should == [
64
- [:step, [], "Given ", "foo", 10, [
65
- {"line"=>11, "comments"=>[], "cells"=>["yo"]},
66
- {"line"=>14, "comments"=>["# Hello", "# World"], "cells"=>["bro"]}
67
- ], nil, nil, nil, nil],
68
- [:eof]
69
- ]
70
- end
71
-
72
- it "should format an entire feature" do
73
- @lexer.scan(File.new(File.dirname(__FILE__) + "/../fixtures/complex.feature").read, "complex.feature", 0)
74
- @formatter.to_sexp.should == [
75
- [:feature, ["#Comment on line 1", "#Comment on line 2"], ["@tag1", "@tag2"],
76
- "Feature",
77
- "Feature Text",
78
- "In order to test multiline forms\nAs a ragel writer\nI need to check for complex combinations",
79
- "complex.feature"],
80
- [:background, ["#Comment on line 9", "#Comment on line 11"], "Background", "", "", 13],
81
- [:step, [], "Given ", "this is a background step", 14, nil, nil, nil, nil, nil],
82
- [:step, [], "And ", "this is another one", 15, nil, nil, nil, nil, nil],
83
- [:scenario, [], ["@tag3", "@tag4"], "Scenario", "Reading a Scenario", "", 18],
84
- [:step, [], "Given ", "there is a step", 19, nil, nil, nil, nil, nil],
85
- [:step, [], "But ", "not another step", 20, nil, nil, nil, nil, nil],
86
- [:scenario, [], ["@tag3"], "Scenario", "Reading a second scenario", "With two lines of text", 23],
87
- [:step, ["#Comment on line 24"], "Given ", "a third step with a table", 26, [
88
- {
89
- "comments" => [],
90
- "line" => 27,
91
- "cells" => ["a", "b"]
92
- },
93
- {
94
- "comments" => [],
95
- "line" => 28,
96
- "cells" => ["c", "d"]
97
- },
98
- {
99
- "comments" => [],
100
- "line" => 29,
101
- "cells" => ["e", "f"]
102
- } ], nil, nil, nil, nil],
103
- [:step, [], "And ", "I am still testing things", 30, [
104
- {
105
- "comments" => [],
106
- "line" => 31,
107
- "cells" => ["g", "h"]
108
- },
109
- {
110
- "comments" => [],
111
- "line" => 32,
112
- "cells" => ["e", "r"]
113
- },
114
- {
115
- "comments" => [],
116
- "line" => 33,
117
- "cells" => ["k", "i"]
118
- },
119
- {
120
- "comments" => [],
121
- "line" => 34,
122
- "cells" => ["n", ""]
123
- } ], nil, nil, nil, nil],
124
- [:step, [], "And ", "I am done testing these tables", 35, nil, nil, nil, nil, nil],
125
- [:step, ["#Comment on line 29"], "Then ", "I am happy", 37, nil, nil, nil, nil, nil],
126
- [:scenario, [], [], "Scenario", "Hammerzeit", "", 39],
127
- [:step, [], "Given ", "All work and no play", 40, "Makes Homer something something\nAnd something else", nil, nil, nil, nil],
128
- [:step, [], "Then ", "crazy", 45, nil, nil, nil, nil, nil],
129
- [:eof]
130
- ]
131
- end
132
- end
133
- end
134
- end
@@ -1,50 +0,0 @@
1
- require 'spec_helper'
2
- require 'gherkin/parser/parser'
3
-
4
- module Gherkin
5
- module Parser
6
- describe Parser do
7
- before do
8
- @listener = mock('listener')
9
- @parser = Gherkin::Parser::Parser.new(@listener, true)
10
- end
11
-
12
- it "should delegate events to the listener" do
13
- @listener.should_receive(:comment).with("# Content", 1)
14
- @parser.comment("# Content", 1)
15
- end
16
-
17
- it "should raise helpful error messages by default" do
18
- lambda {
19
- @parser.scenario("Scenario", "My pet scenario", "", 12)
20
- }.should raise_error(/Parse error on line 12\. Found scenario when expecting one of: comment, feature, tag\. \(Current state: root\)\.$/)
21
- end
22
-
23
- it "should allow empty files" do
24
- @listener.should_receive(:eof)
25
- @parser.eof
26
- end
27
-
28
- it "should delegate an error message when raise on error is false" do
29
- @listener.should_receive(:syntax_error).with(sym(:root), sym(:background), a([:comment, :feature, :tag]), 1)
30
- @parser = Gherkin::Parser::Parser.new(@listener, false)
31
- @parser.background("Background", "Content", "", 1)
32
- end
33
-
34
- [true, false].each do |native|
35
- it "should be reusable for several feature files (native lexer: #{native})" do
36
- listener = mock('listener').as_null_object
37
- parser = Gherkin::Parser::Parser.new(listener, true)
38
- lexer = Gherkin::I18nLexer.new(parser, native)
39
- feature = <<-EOF
40
- Feature: foo
41
- Scenario: bar
42
- Given zap
43
- EOF
44
- lexer.scan(feature, "test.feature", 0)
45
- lexer.scan(feature, "test.feature", 0)
46
- end
47
- end
48
- end
49
- end
50
- end
@@ -1,116 +0,0 @@
1
- require 'spec_helper'
2
- require 'gherkin/parser/tag_expression'
3
-
4
- module Gherkin
5
- module Parser
6
- describe TagExpression do
7
- context "no tags" do
8
- before(:each) do
9
- @e = Gherkin::Parser::TagExpression.new([])
10
- end
11
-
12
- it "should match @foo" do
13
- @e.eval(['@foo']).should == true
14
- end
15
-
16
- it "should match empty tags" do
17
- @e.eval([]).should == true
18
- end
19
- end
20
-
21
- context "@foo" do
22
- before(:each) do
23
- @e = Gherkin::Parser::TagExpression.new(['@foo'])
24
- end
25
-
26
- it "should match @foo" do
27
- @e.eval(['@foo']).should == true
28
- end
29
-
30
- it "should not match @bar" do
31
- @e.eval(['@bar']).should == false
32
- end
33
-
34
- it "should not match no tags" do
35
- @e.eval([]).should == false
36
- end
37
- end
38
-
39
- context "!@foo" do
40
- before(:each) do
41
- @e = Gherkin::Parser::TagExpression.new(['~@foo'])
42
- end
43
-
44
- it "should match @bar" do
45
- @e.eval(['@bar']).should == true
46
- end
47
-
48
- it "should not match @foo" do
49
- @e.eval(['@foo']).should == false
50
- end
51
- end
52
-
53
- context "@foo || @bar" do
54
- before(:each) do
55
- @e = Gherkin::Parser::TagExpression.new(['@foo,@bar'])
56
- end
57
-
58
- it "should match @foo" do
59
- @e.eval(['@foo']).should == true
60
- end
61
-
62
- it "should match @bar" do
63
- @e.eval(['@bar']).should == true
64
- end
65
-
66
- it "should not match @zap" do
67
- @e.eval(['@zap']).should == false
68
- end
69
- end
70
-
71
- context "(@foo || @bar) && !@zap" do
72
- before(:each) do
73
- @e = Gherkin::Parser::TagExpression.new(['@foo,@bar', '~@zap'])
74
- end
75
-
76
- it "should match @foo" do
77
- @e.eval(['@foo']).should == true
78
- end
79
-
80
- it "should not match @foo @zap" do
81
- @e.eval(['@foo', '@zap']).should == false
82
- end
83
- end
84
-
85
- context "(@foo:3 || !@bar:4) && @zap:5" do
86
- before(:each) do
87
- @e = Gherkin::Parser::TagExpression.new(['@foo:3,~@bar','@zap:5'])
88
- end
89
-
90
- it "should count tags for positive tags" do
91
- rubify_hash(@e.limits).should == {'@foo' => 3, '@zap' => 5}
92
- end
93
-
94
- it "should match @foo @zap" do
95
- @e.eval(['@foo', '@zap']).should == true
96
- end
97
- end
98
-
99
- context "Parsing '@foo:3,~@bar', '@zap:5'" do
100
- before(:each) do
101
- @e = Gherkin::Parser::TagExpression.new([' @foo:3 , ~@bar ', ' @zap:5 '])
102
- end
103
-
104
- unless defined?(JRUBY_VERSION)
105
- it "should split and trim (ruby implementation detail)" do
106
- @e.__send__(:ruby_expression).should == "(!vars['@bar']||vars['@foo'])&&(vars['@zap'])"
107
- end
108
- end
109
-
110
- it "should have limits" do
111
- rubify_hash(@e.limits).should == {"@zap"=>5, "@foo"=>3}
112
- end
113
- end
114
- end
115
- end
116
- end