gherkin_jruby 0.3.1.pre.jruby

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,45 @@
1
+ require 'test_helper'
2
+
3
+ module GherkinRuby
4
+ describe Parser do
5
+ before do
6
+ @lexer = Parser.new
7
+ end
8
+
9
+ it 'ignores commments' do
10
+ @lexer.tokenize("# this is a comment").must_equal []
11
+ end
12
+
13
+ it 'parses newlines' do
14
+ @lexer.tokenize("\n\n").must_equal [[:NEWLINE, "\n"], [:NEWLINE, "\n"]]
15
+ end
16
+
17
+ it 'parses text and strips it' do
18
+ @lexer.tokenize(" Arbitrary text ").must_equal [[:TEXT, "Arbitrary text"]]
19
+ end
20
+
21
+ it 'parses tags' do
22
+ @lexer.tokenize("@javascript @wip").must_equal [
23
+ [:TAG, "javascript"],
24
+ [:TAG, "wip"],
25
+ ]
26
+ end
27
+
28
+ describe 'Keywords' do
29
+ %w(Feature: Background: Scenario:).each do |keyword|
30
+ it "parses #{keyword}:" do
31
+ name = keyword[0..-2]
32
+ @lexer.tokenize(keyword).must_equal [[name.upcase.to_sym, name]]
33
+ end
34
+ end
35
+ end
36
+
37
+ describe 'Step keywords' do
38
+ %w(Given When Then And But).each do |keyword|
39
+ it "parses #{keyword}" do
40
+ @lexer.tokenize(keyword).must_equal [[keyword.upcase.to_sym, keyword]]
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,132 @@
1
+ require 'test_helper'
2
+
3
+ module GherkinRuby
4
+ describe Parser do
5
+ def parse(input)
6
+ parser = Parser.new
7
+ parser.parse(input)
8
+ end
9
+
10
+ describe 'Feature name and description' do
11
+ it 'parses feature header without description' do
12
+ feature = parse(
13
+ "Feature: my feature"
14
+ )
15
+ feature.must_be_kind_of AST::Feature
16
+ feature.name.must_equal "my feature"
17
+ end
18
+
19
+ it 'parses feature header with description' do
20
+ feature = parse(
21
+ "Feature: my feature\n In order to do something\n As a user\n"
22
+ )
23
+ feature.must_be_kind_of AST::Feature
24
+ feature.name.must_equal "my feature"
25
+ end
26
+
27
+ it 'parses feature with tags' do
28
+ feature = parse("""
29
+ @wip @with-dash
30
+ Feature: Do something
31
+ """)
32
+ feature.name.must_equal "Do something"
33
+ feature.tags.first.name.must_equal "wip"
34
+ feature.tags.last.name.must_equal "with-dash"
35
+ end
36
+
37
+ it 'parses feature with tagsi event without newline at start' do
38
+ feature = parse(
39
+ "@wip\nFeature: Do something"
40
+ )
41
+ feature.name.must_equal "Do something"
42
+ feature.tags.first.name.must_equal "wip"
43
+ end
44
+
45
+ it 'parses feature with background' do
46
+ feature = parse("""
47
+ Feature: Do something
48
+
49
+ Background:
50
+ Given blah foo bar
51
+ Then something else
52
+ """)
53
+ feature.name.must_equal "Do something"
54
+ feature.background.must_be_kind_of AST::Background
55
+ steps = feature.background.steps
56
+
57
+ given_step = steps.first
58
+ then_step = steps.last
59
+
60
+ given_step.keyword.must_equal "Given"
61
+ given_step.name.must_equal "blah foo bar"
62
+ then_step.keyword.must_equal "Then"
63
+ then_step.name.must_equal "something else"
64
+ end
65
+
66
+ it 'parses feature with scenarios' do
67
+ feature = parse("""
68
+ Feature: Do something
69
+
70
+ Scenario: Foo bar baz
71
+ Given blah foo bar
72
+ Then something else
73
+
74
+ Scenario: Foo bar baz blah
75
+ Given blah foo bar
76
+ Then something else
77
+ """)
78
+ scenarios = feature.scenarios
79
+
80
+ first_scenario = scenarios.first
81
+ last_scenario = scenarios.last
82
+
83
+ first_scenario.name.must_equal "Foo bar baz"
84
+ first_scenario.steps.first.name.must_equal "blah foo bar"
85
+ first_scenario.steps.last.name.must_equal "something else"
86
+
87
+ last_scenario.name.must_equal "Foo bar baz blah"
88
+ last_scenario.steps.first.name.must_equal "blah foo bar"
89
+ last_scenario.steps.last.name.must_equal "something else"
90
+ end
91
+
92
+ it 'parses feature with no ending newline' do
93
+ feature = parse(%(
94
+ Feature: Do something
95
+
96
+ Scenario: Foo bar baz
97
+ Given blah foo bar
98
+ Then something else))
99
+ scenarios = feature.scenarios
100
+ scenarios.size.must_equal 1
101
+
102
+ first_scenario = scenarios.first
103
+
104
+ first_scenario.name.must_equal "Foo bar baz"
105
+ first_scenario.steps.first.name.must_equal "blah foo bar"
106
+ first_scenario.steps.last.name.must_equal "something else"
107
+ end
108
+
109
+ it 'parses feature with scenarios with tags' do
110
+ feature = parse("""
111
+ Feature: Do something
112
+
113
+ Scenario: Foo bar baz
114
+ Given blah foo bar
115
+ Then something else
116
+
117
+ @javascript @wip @with-vcr
118
+ Scenario: Foo bar baz blah
119
+ Given blah foo bar
120
+ Then something else
121
+ """)
122
+ scenarios = feature.scenarios
123
+
124
+ last_scenario = scenarios.last
125
+
126
+ last_scenario.tags[0].name.must_equal "javascript"
127
+ last_scenario.tags[1].name.must_equal "wip"
128
+ last_scenario.tags[2].name.must_equal "with-vcr"
129
+ end
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,77 @@
1
+ require_relative '../test_helper'
2
+
3
+ module GherkinRuby
4
+ describe 'Feature parsing' do
5
+ before do
6
+ @scenario = """Feature: My Feature
7
+ In order to do something #w000t peoeple
8
+ As a developer
9
+ I want to be happy #yeah
10
+
11
+ # Attend people. This is going to be fun
12
+
13
+ Background:
14
+ Given something happens before anything else happens
15
+ And more things happens before anything else happens
16
+ # And I wipe the hard drive
17
+
18
+ Scenario: something happens # yeah
19
+ Given something happens
20
+ Then something cooler happens
21
+
22
+ @javascript @wip #@destroy
23
+ Scenario: something else happens
24
+ Given foo
25
+ Then bar
26
+ """
27
+
28
+ parser = GherkinRuby::Parser.new
29
+ @result = parser.parse(@scenario)
30
+ end
31
+
32
+ it 'generates a nice tree' do
33
+ @result.must_be_kind_of AST::Feature
34
+ @result.line.must_equal 1
35
+ @result.description.must_equal [
36
+ "In order to do something",
37
+ "As a developer",
38
+ "I want to be happy"]
39
+
40
+ background = @result.background
41
+ background.must_be_kind_of AST::Background
42
+ background.line.must_equal 8
43
+ background.steps.first.keyword.must_equal 'Given'
44
+ background.steps.first.name.must_equal 'something happens before anything else happens'
45
+ background.steps.first.line.must_equal 9
46
+ background.steps.last.keyword.must_equal 'And'
47
+ background.steps.last.name.must_equal 'more things happens before anything else happens'
48
+ background.steps.last.line.must_equal 10
49
+
50
+ first_scenario = @result.scenarios.first
51
+ first_scenario.must_be_kind_of AST::Scenario
52
+ first_scenario.line.must_equal 13
53
+ first_scenario.name.must_equal 'something happens'
54
+ first_scenario.steps.first.keyword.must_equal 'Given'
55
+ first_scenario.steps.first.name.must_equal 'something happens'
56
+ first_scenario.steps.first.line.must_equal 14
57
+ first_scenario.steps.last.keyword.must_equal 'Then'
58
+ first_scenario.steps.last.name.must_equal 'something cooler happens'
59
+ first_scenario.steps.last.line.must_equal 15
60
+
61
+ last_scenario = @result.scenarios.last
62
+ last_scenario.must_be_kind_of AST::Scenario
63
+ last_scenario.line.must_equal 18
64
+ last_scenario.name.must_equal 'something else happens'
65
+
66
+ last_scenario.tags.first.name.must_equal 'javascript'
67
+ last_scenario.tags.last.name.must_equal 'wip'
68
+
69
+ last_scenario.steps.first.keyword.must_equal 'Given'
70
+ last_scenario.steps.first.name.must_equal 'foo'
71
+ last_scenario.steps.first.line.must_equal 19
72
+ last_scenario.steps.last.keyword.must_equal 'Then'
73
+ last_scenario.steps.last.name.must_equal 'bar'
74
+ last_scenario.steps.last.line.must_equal 20
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,4 @@
1
+ gem 'minitest'
2
+ require 'minitest/spec'
3
+ require 'minitest/autorun'
4
+ require 'gherkin_jruby'
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gherkin_jruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1.pre.jruby
5
+ platform: ruby
6
+ authors:
7
+ - Marc Divins
8
+ - Josep M. Bach
9
+ - Rodrigo Alvarez
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-06-30 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: minitest
17
+ version_requirements: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ requirement: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ prerelease: false
28
+ type: :development
29
+ - !ruby/object:Gem::Dependency
30
+ name: rexical
31
+ version_requirements: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ prerelease: false
42
+ type: :development
43
+ description: Gherkin-ruby is a Gherkin parser in pure Ruby using Rexical and Racc that works on jruby
44
+ email:
45
+ - marcdivc@gmail.com
46
+ - josep.m.bach@gmail.com
47
+ - papipo@gmail.com
48
+ executables: []
49
+ extensions: []
50
+ extra_rdoc_files: []
51
+ files:
52
+ - .gitignore
53
+ - .travis.yml
54
+ - Gemfile
55
+ - Rakefile
56
+ - Readme.md
57
+ - gherkin_jruby.gemspec
58
+ - lib/gherkin_jruby.rb
59
+ - lib/gherkin_ruby/ast.rb
60
+ - lib/gherkin_ruby/parser.rb
61
+ - lib/gherkin_ruby/parser/gherkin.rex
62
+ - lib/gherkin_ruby/parser/gherkin.y
63
+ - lib/gherkin_ruby/parser/lexer.rb
64
+ - lib/gherkin_ruby/parser/parser.rb
65
+ - lib/gherkin_ruby/version.rb
66
+ - test/gherkin/ast_test.rb
67
+ - test/gherkin/parser/lexer_test.rb
68
+ - test/gherkin/parser/parser_test.rb
69
+ - test/gherkin/parser_test.rb
70
+ - test/test_helper.rb
71
+ homepage: http://github.com/Papipo/gherkin-jruby
72
+ licenses: []
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>'
86
+ - !ruby/object:Gem::Version
87
+ version: 1.3.1
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.2.2
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Gherkin-ruby is a Gherkin parser in pure Ruby using Rexical and Racc that works on jruby
94
+ test_files:
95
+ - test/gherkin/ast_test.rb
96
+ - test/gherkin/parser/lexer_test.rb
97
+ - test/gherkin/parser/parser_test.rb
98
+ - test/gherkin/parser_test.rb
99
+ - test/test_helper.rb
100
+ has_rdoc: