bryanl-gherkin 2.11.1.1-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitattributes +2 -0
- data/.mailmap +2 -0
- data/.rbenv-gemsets +1 -0
- data/.rspec +1 -0
- data/.rvmrc +1 -0
- data/.travis.yml +16 -0
- data/.yardopts +5 -0
- data/Gemfile +5 -0
- data/History.md +788 -0
- data/LICENSE +20 -0
- data/README.md +272 -0
- data/Rakefile +26 -0
- data/build_native_gems.sh +7 -0
- data/cucumber.yml +4 -0
- data/examples/parse_and_output_json.rb +19 -0
- data/features/.cucumber/stepdefs.json +244 -0
- data/features/escaped_pipes.feature +8 -0
- data/features/feature_parser.feature +237 -0
- data/features/json_formatter.feature +498 -0
- data/features/json_parser.feature +331 -0
- data/features/native_lexer.feature +19 -0
- data/features/parser_with_native_lexer.feature +205 -0
- data/features/pretty_formatter.feature +16 -0
- data/features/step_definitions/eyeball_steps.rb +3 -0
- data/features/step_definitions/gherkin_steps.rb +29 -0
- data/features/step_definitions/json_formatter_steps.rb +30 -0
- data/features/step_definitions/json_parser_steps.rb +20 -0
- data/features/step_definitions/pretty_formatter_steps.rb +85 -0
- data/features/steps_parser.feature +46 -0
- data/features/support/env.rb +42 -0
- data/gherkin.gemspec +77 -0
- data/install_mingw_os_x.sh +7 -0
- data/js/.npmignore +1 -0
- data/js/lib/gherkin/lexer/.npmignore +0 -0
- data/lib/gherkin/c_lexer.rb +17 -0
- data/lib/gherkin/formatter/ansi_escapes.rb +97 -0
- data/lib/gherkin/formatter/argument.rb +16 -0
- data/lib/gherkin/formatter/escaping.rb +15 -0
- data/lib/gherkin/formatter/filter_formatter.rb +146 -0
- data/lib/gherkin/formatter/hashable.rb +19 -0
- data/lib/gherkin/formatter/json_formatter.rb +122 -0
- data/lib/gherkin/formatter/line_filter.rb +26 -0
- data/lib/gherkin/formatter/model.rb +281 -0
- data/lib/gherkin/formatter/pretty_formatter.rb +244 -0
- data/lib/gherkin/formatter/regexp_filter.rb +21 -0
- data/lib/gherkin/formatter/step_printer.rb +21 -0
- data/lib/gherkin/formatter/tag_count_formatter.rb +47 -0
- data/lib/gherkin/formatter/tag_filter.rb +19 -0
- data/lib/gherkin/i18n.rb +180 -0
- data/lib/gherkin/i18n.yml +613 -0
- data/lib/gherkin/js_lexer.rb +20 -0
- data/lib/gherkin/json_parser.rb +177 -0
- data/lib/gherkin/lexer/i18n_lexer.rb +46 -0
- data/lib/gherkin/listener/event.rb +45 -0
- data/lib/gherkin/listener/formatter_listener.rb +143 -0
- data/lib/gherkin/native/java.rb +72 -0
- data/lib/gherkin/native/null.rb +5 -0
- data/lib/gherkin/native/therubyracer.rb +39 -0
- data/lib/gherkin/native.rb +7 -0
- data/lib/gherkin/parser/meta.txt +5 -0
- data/lib/gherkin/parser/parser.rb +164 -0
- data/lib/gherkin/parser/root.txt +11 -0
- data/lib/gherkin/parser/steps.txt +4 -0
- data/lib/gherkin/rb_lexer/README.rdoc +8 -0
- data/lib/gherkin/rb_lexer.rb +8 -0
- data/lib/gherkin/rubify.rb +24 -0
- data/lib/gherkin/tag_expression.rb +62 -0
- data/lib/gherkin.jar +0 -0
- data/lib/gherkin.rb +2 -0
- data/ragel/lexer.c.rl.erb +454 -0
- data/ragel/lexer.java.rl.erb +219 -0
- data/ragel/lexer.js.rl.erb +227 -0
- data/ragel/lexer.rb.rl.erb +174 -0
- data/ragel/lexer_common.rl.erb +50 -0
- data/spec/gherkin/c_lexer_spec.rb +22 -0
- data/spec/gherkin/fixtures/1.feature +8 -0
- data/spec/gherkin/fixtures/comments_in_table.feature +9 -0
- data/spec/gherkin/fixtures/complex.feature +45 -0
- data/spec/gherkin/fixtures/complex.json +139 -0
- data/spec/gherkin/fixtures/complex_for_filtering.feature +60 -0
- data/spec/gherkin/fixtures/complex_with_tags.feature +61 -0
- data/spec/gherkin/fixtures/dos_line_endings.feature +45 -0
- data/spec/gherkin/fixtures/examples_with_only_header.feature +14 -0
- data/spec/gherkin/fixtures/hantu_pisang.feature +35 -0
- data/spec/gherkin/fixtures/i18n_fr.feature +14 -0
- data/spec/gherkin/fixtures/i18n_fr2.feature +8 -0
- data/spec/gherkin/fixtures/i18n_no.feature +7 -0
- data/spec/gherkin/fixtures/i18n_pt1.feature +44 -0
- data/spec/gherkin/fixtures/i18n_pt2.feature +4 -0
- data/spec/gherkin/fixtures/i18n_pt3.feature +4 -0
- data/spec/gherkin/fixtures/i18n_pt4.feature +4 -0
- data/spec/gherkin/fixtures/i18n_zh-CN.feature +9 -0
- data/spec/gherkin/fixtures/issue_145.feature +22 -0
- data/spec/gherkin/fixtures/scenario_outline_with_tags.feature +13 -0
- data/spec/gherkin/fixtures/scenario_without_steps.feature +5 -0
- data/spec/gherkin/fixtures/simple_with_comments.feature +7 -0
- data/spec/gherkin/fixtures/simple_with_tags.feature +11 -0
- data/spec/gherkin/fixtures/with_bom.feature +3 -0
- data/spec/gherkin/formatter/ansi_escapes_spec.rb +32 -0
- data/spec/gherkin/formatter/filter_formatter_spec.rb +204 -0
- data/spec/gherkin/formatter/json_formatter_spec.rb +92 -0
- data/spec/gherkin/formatter/model_spec.rb +28 -0
- data/spec/gherkin/formatter/pretty_formatter_spec.rb +177 -0
- data/spec/gherkin/formatter/spaces.feature +9 -0
- data/spec/gherkin/formatter/step_printer_spec.rb +55 -0
- data/spec/gherkin/formatter/tabs.feature +9 -0
- data/spec/gherkin/formatter/tag_count_formatter_spec.rb +30 -0
- data/spec/gherkin/i18n_spec.rb +241 -0
- data/spec/gherkin/java_lexer_spec.rb +20 -0
- data/spec/gherkin/js_lexer_spec.rb +23 -0
- data/spec/gherkin/json_parser_spec.rb +176 -0
- data/spec/gherkin/lexer/i18n_lexer_spec.rb +43 -0
- data/spec/gherkin/output_stream_string_io.rb +20 -0
- data/spec/gherkin/parser/parser_spec.rb +16 -0
- data/spec/gherkin/rb_lexer_spec.rb +20 -0
- data/spec/gherkin/sexp_recorder.rb +59 -0
- data/spec/gherkin/shared/bom_group.rb +20 -0
- data/spec/gherkin/shared/doc_string_group.rb +163 -0
- data/spec/gherkin/shared/lexer_group.rb +591 -0
- data/spec/gherkin/shared/row_group.rb +125 -0
- data/spec/gherkin/shared/tags_group.rb +54 -0
- data/spec/gherkin/tag_expression_spec.rb +142 -0
- data/spec/spec_helper.rb +75 -0
- data/tasks/bench/feature_builder.rb +49 -0
- data/tasks/bench/null_listener.rb +4 -0
- data/tasks/bench.rake +184 -0
- data/tasks/compile.rake +120 -0
- data/tasks/cucumber.rake +22 -0
- data/tasks/gems.rake +31 -0
- data/tasks/ikvm.rake +124 -0
- data/tasks/ragel_task.rb +100 -0
- data/tasks/release.rake +49 -0
- data/tasks/rspec.rake +8 -0
- data/tasks/yard/default/layout/html/bubble_32x32.png +0 -0
- data/tasks/yard/default/layout/html/bubble_48x48.png +0 -0
- data/tasks/yard/default/layout/html/footer.erb +5 -0
- data/tasks/yard/default/layout/html/index.erb +1 -0
- data/tasks/yard/default/layout/html/layout.erb +25 -0
- data/tasks/yard/default/layout/html/logo.erb +1 -0
- data/tasks/yard/default/layout/html/setup.rb +4 -0
- data/tasks/yard.rake +7 -0
- metadata +412 -0
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'gherkin'
|
4
|
+
require 'gherkin/formatter/pretty_formatter'
|
5
|
+
require 'gherkin/formatter/json_formatter'
|
6
|
+
require 'gherkin/json_parser'
|
7
|
+
|
8
|
+
module PrettyPlease
|
9
|
+
|
10
|
+
def pretty_machinery(gherkin, feature_path)
|
11
|
+
io = StringIO.new
|
12
|
+
formatter = Gherkin::Formatter::PrettyFormatter.new(io, true, false)
|
13
|
+
parser = Gherkin::Parser::Parser.new(formatter, true)
|
14
|
+
parse(parser, gherkin, feature_path)
|
15
|
+
io.string
|
16
|
+
end
|
17
|
+
|
18
|
+
def json_machinery(gherkin, feature_path)
|
19
|
+
json = StringIO.new
|
20
|
+
json_formatter = Gherkin::Formatter::JSONFormatter.new(json)
|
21
|
+
gherkin_parser = Gherkin::Parser::Parser.new(json_formatter, true)
|
22
|
+
parse(gherkin_parser, gherkin, feature_path)
|
23
|
+
json_formatter.done
|
24
|
+
|
25
|
+
io = StringIO.new
|
26
|
+
pretty_formatter = Gherkin::Formatter::PrettyFormatter.new(io, true, false)
|
27
|
+
json_parser = Gherkin::JSONParser.new(pretty_formatter, pretty_formatter)
|
28
|
+
json_parser.parse(json.string)
|
29
|
+
|
30
|
+
io.string
|
31
|
+
end
|
32
|
+
|
33
|
+
def parse(parser, gherkin, feature_path)
|
34
|
+
begin
|
35
|
+
parser.parse(gherkin, feature_path, 0)
|
36
|
+
rescue => e
|
37
|
+
if e.message =~ /Lexing error/
|
38
|
+
FileUtils.mkdir "tmp" unless File.directory?("tmp")
|
39
|
+
written_path = "tmp/#{File.basename(feature_path)}"
|
40
|
+
File.open(written_path, "w") {|io| io.write(gherkin)}
|
41
|
+
e.message << "\nSee #{written_path}"
|
42
|
+
end
|
43
|
+
raise e
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
World(PrettyPlease)
|
49
|
+
|
50
|
+
Given /^I have Cucumber's source code next to Gherkin's$/ do
|
51
|
+
@cucumber_home = File.dirname(__FILE__) + '/../../../cucumber'
|
52
|
+
raise "No Cucumber source in #{@cucumber_home}" unless File.file?(@cucumber_home + '/bin/cucumber')
|
53
|
+
end
|
54
|
+
|
55
|
+
Given /^I find all of the \.feature files$/ do
|
56
|
+
@feature_paths = Dir["#{@cucumber_home}/**/*.feature"].sort
|
57
|
+
end
|
58
|
+
|
59
|
+
When /^I send each prettified original through the "([^"]*)" machinery$/ do |machinery|
|
60
|
+
@error = false
|
61
|
+
@feature_paths.each do |feature_path|
|
62
|
+
begin
|
63
|
+
next if feature_path =~ /iso-8859-1\.feature/
|
64
|
+
original = pretty_machinery(IO.read(feature_path), feature_path)
|
65
|
+
via_machinery = self.__send__("#{machinery}_machinery", original, feature_path)
|
66
|
+
via_machinery.should == original
|
67
|
+
rescue RSpec::Expectations::ExpectationNotMetError => e
|
68
|
+
announce "=========="
|
69
|
+
announce feature_path
|
70
|
+
if(e.message =~ /(@@.*)/m)
|
71
|
+
announce $1
|
72
|
+
@error = true
|
73
|
+
else
|
74
|
+
announce "Identical, except for newlines"
|
75
|
+
end
|
76
|
+
rescue => e
|
77
|
+
e.message << "\nFatal error happened when parsing #{feature_path}."
|
78
|
+
raise e
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
Then /^the machinery output should be identical to the prettified original$/ do
|
84
|
+
raise "Some features didn't make it through the machinery" if @error
|
85
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
Feature: Gherkin Steps parser
|
2
|
+
In order to save time and make my features clearer
|
3
|
+
As a Cucumber developer
|
4
|
+
I want a steps parser to make writing compound steps easier
|
5
|
+
|
6
|
+
Background:
|
7
|
+
Given a "ruby" "steps" parser
|
8
|
+
|
9
|
+
Scenario: Parsing steps
|
10
|
+
Given the following text is parsed:
|
11
|
+
"""
|
12
|
+
Given a one step
|
13
|
+
And a two step
|
14
|
+
\"\"\"
|
15
|
+
Here is a multiline string
|
16
|
+
That follows a step
|
17
|
+
With an argument #{arg}
|
18
|
+
\"\"\"
|
19
|
+
And a one two three step
|
20
|
+
When another step
|
21
|
+
Then there should be a table
|
22
|
+
| one | two | three |
|
23
|
+
| foo | bar | #{arg} |
|
24
|
+
"""
|
25
|
+
Then there should be no parse errors
|
26
|
+
|
27
|
+
Scenario: Trying to parse a full feature with the step parser
|
28
|
+
Given the following text is parsed:
|
29
|
+
"""
|
30
|
+
Feature: A Feature
|
31
|
+
Scenario: Yes, there is one
|
32
|
+
Given I have a step
|
33
|
+
When I execute this step
|
34
|
+
Then something should happen
|
35
|
+
"""
|
36
|
+
Then there should be parse errors on lines 1 and 2
|
37
|
+
|
38
|
+
Scenario: Tags
|
39
|
+
Given the following text is parsed:
|
40
|
+
"""
|
41
|
+
@a_tag
|
42
|
+
Given a step
|
43
|
+
When I trip
|
44
|
+
Then I should sign up for dancing lessons
|
45
|
+
"""
|
46
|
+
Then there should be a parse error on line 1
|
@@ -0,0 +1,42 @@
|
|
1
|
+
if RUBY_VERSION =~ /1.9/
|
2
|
+
Encoding.default_external = Encoding::UTF_8
|
3
|
+
Encoding.default_internal = Encoding::UTF_8
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'bundler'
|
8
|
+
Bundler.setup
|
9
|
+
|
10
|
+
# I'm sure there's a better way than this...
|
11
|
+
%w{ /../../spec /../../lib}.each do |path|
|
12
|
+
$LOAD_PATH << File.expand_path(File.dirname(__FILE__) + path)
|
13
|
+
end
|
14
|
+
require 'gherkin'
|
15
|
+
require 'gherkin/sexp_recorder'
|
16
|
+
require 'gherkin/output_stream_string_io'
|
17
|
+
|
18
|
+
module TransformHelpers
|
19
|
+
def tr_line_number(step_arg)
|
20
|
+
/(\d+)$/.match(step_arg)[0].to_i
|
21
|
+
end
|
22
|
+
|
23
|
+
def tr_line_numbers(step_arg)
|
24
|
+
if step_arg =~ /through/
|
25
|
+
Range.new(*step_arg.scan(/\d+/).collect { |i| i.to_i })
|
26
|
+
else
|
27
|
+
step_arg.scan(/\d+/).collect { |i| i.to_i }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class GherkinWorld
|
33
|
+
include TransformHelpers
|
34
|
+
|
35
|
+
def initialize
|
36
|
+
@formatter = Gherkin::SexpRecorder.new
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
World do
|
41
|
+
GherkinWorld.new
|
42
|
+
end
|
data/gherkin.gemspec
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "bryanl-gherkin"
|
5
|
+
# If the major version is bumped, verify that the change is ok:
|
6
|
+
#
|
7
|
+
# * Comment out the cucumber dependency below
|
8
|
+
# * Uncomment the cucumber location in Gemfile
|
9
|
+
# * Bump cucumber's gherkin dependency to the new version
|
10
|
+
# * bundle update
|
11
|
+
# * bundle exec rake
|
12
|
+
#
|
13
|
+
# Repeat these step for cucumber (swap `cucumber` with `gherkin`).
|
14
|
+
#
|
15
|
+
# When both are building OK, do a `bundle exec rake install` in both cucumber and gherkin projects, revert the changes in the first 2 steps
|
16
|
+
# and release both projects. Do this for both ruby 1.8.7, ruby 1.9.3 and jruby.
|
17
|
+
#
|
18
|
+
s.version = "2.11.1.1"
|
19
|
+
s.authors = ["Mike Sassak", "Gregory Hnatiuk", "Aslak Hellesøy"]
|
20
|
+
s.description = "A fast Gherkin lexer/parser based on the Ragel State Machine Compiler."
|
21
|
+
s.summary = "bryanl's #{s.name}-#{s.version}"
|
22
|
+
s.email = "cukes@googlegroups.com"
|
23
|
+
s.homepage = "http://github.com/cucumber/gherkin"
|
24
|
+
|
25
|
+
s.files = `git ls-files`.split("\n")
|
26
|
+
s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
|
27
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
28
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
29
|
+
s.require_path = "lib"
|
30
|
+
|
31
|
+
s.files -= Dir['ikvm/**/*']
|
32
|
+
s.files -= Dir['java/**/*']
|
33
|
+
s.files -= Dir['js/**/*']
|
34
|
+
s.files -= Dir['ext/**/*']
|
35
|
+
s.files -= Dir['lib/gherkin.jar']
|
36
|
+
s.files -= Dir['lib/**/*.dll']
|
37
|
+
s.files -= Dir['lib/**/*.bundle']
|
38
|
+
s.files -= Dir['lib/**/*.so']
|
39
|
+
|
40
|
+
if ENV['GEM_PLATFORM']
|
41
|
+
puts "GEM_PLATFORM:#{ENV['GEM_PLATFORM']}"
|
42
|
+
end
|
43
|
+
s.platform = ENV['GEM_PLATFORM'] if ENV['GEM_PLATFORM']
|
44
|
+
case s.platform.to_s
|
45
|
+
when /java/
|
46
|
+
s.files += Dir['lib/*.jar']
|
47
|
+
when /mswin|mingw32/
|
48
|
+
s.files += Dir['lib/*/*.so']
|
49
|
+
when /dotnet/
|
50
|
+
s.files += Dir['lib/*.dll']
|
51
|
+
else # MRI or Rubinius
|
52
|
+
s.files += Dir['lib/gherkin/rb_lexer/*.rb']
|
53
|
+
s.files += Dir['ext/**/*.c']
|
54
|
+
s.extensions = Dir['ext/**/extconf.rb']
|
55
|
+
s.add_development_dependency('rake-compiler', '>= 0.8.0')
|
56
|
+
end
|
57
|
+
s.files -= Dir['**/.gitignore']
|
58
|
+
|
59
|
+
s.add_runtime_dependency('json', '>= 1.4.6')
|
60
|
+
|
61
|
+
s.add_development_dependency('cucumber', '>= 1.2.1')
|
62
|
+
s.add_development_dependency('rake', '>= 0.9.2')
|
63
|
+
s.add_development_dependency('bundler', '>= 1.1.0')
|
64
|
+
s.add_development_dependency('rspec', '~> 2.10.0')
|
65
|
+
s.add_development_dependency('rubyzip', '>= 0.9.8')
|
66
|
+
|
67
|
+
unless ENV['RUBY_CC_VERSION'] || defined?(JRUBY_VERSION)
|
68
|
+
s.add_development_dependency('therubyracer', '>= 0.10.1') if ENV['GHERKIN_JS']
|
69
|
+
# For Documentation:
|
70
|
+
s.add_development_dependency('yard', '>= 0.8.0')
|
71
|
+
s.add_development_dependency('rdiscount', '>= 1.6.8')
|
72
|
+
end
|
73
|
+
|
74
|
+
# Only needed by Cucumber. Remove when Cucumber no longer needs those.
|
75
|
+
s.add_development_dependency('term-ansicolor', '>= 1.0.6')
|
76
|
+
s.add_development_dependency('builder', '>= 2.1.2')
|
77
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
mkdir -p /usr/local/mingw
|
4
|
+
cd /usr/local/mingw
|
5
|
+
# Don't attempt any of the newer versions - they don't work (gcc 4.7.0)
|
6
|
+
wget http://downloads.sourceforge.net/project/mingw-w64/Toolchains%20targetting%20Win32/Automated%20Builds/mingw-w32-1.0-bin_i686-darwin_20110819.tar.bz2
|
7
|
+
tar xvfj mingw-w32-1.0-bin_i686-darwin_20110819.tar.bz2
|
data/js/.npmignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
example
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rbconfig'
|
2
|
+
|
3
|
+
module Gherkin
|
4
|
+
module CLexer
|
5
|
+
def self.[](i18n_underscored_iso_code)
|
6
|
+
begin
|
7
|
+
prefix = RbConfig::CONFIG['arch'] =~ /mswin|mingw/ ? "#{RbConfig::CONFIG['MAJOR']}.#{RbConfig::CONFIG['MINOR']}/" : ''
|
8
|
+
lib = "#{prefix}gherkin_lexer_#{i18n_underscored_iso_code}"
|
9
|
+
require lib
|
10
|
+
const_get(i18n_underscored_iso_code.capitalize)
|
11
|
+
rescue LoadError => e
|
12
|
+
e.message << %{\nCouldn't load #{lib}\nThe $LOAD_PATH was:\n#{$LOAD_PATH.join("\n")}}
|
13
|
+
raise e
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module Gherkin
|
2
|
+
module Formatter
|
3
|
+
# Defines aliases for ANSI coloured output. Default colours can be overridden by defining
|
4
|
+
# a <tt>GHERKIN_COLORS</tt> variable in your shell, very much like how you can
|
5
|
+
# tweak the familiar POSIX command <tt>ls</tt> with
|
6
|
+
# $LSCOLORS: http://linux-sxs.org/housekeeping/lscolors.html
|
7
|
+
#
|
8
|
+
# The colours that you can change are:
|
9
|
+
#
|
10
|
+
# <tt>undefined</tt>:: defaults to <tt>yellow</tt>
|
11
|
+
# <tt>pending</tt>:: defaults to <tt>yellow</tt>
|
12
|
+
# <tt>pending_arg</tt>:: defaults to <tt>yellow,bold</tt>
|
13
|
+
# <tt>executing</tt>:: defaults to <tt>grey</tt>
|
14
|
+
# <tt>executing_arg</tt>:: defaults to <tt>grey,bold</tt>
|
15
|
+
# <tt>failed</tt>:: defaults to <tt>red</tt>
|
16
|
+
# <tt>failed_arg</tt>:: defaults to <tt>red,bold</tt>
|
17
|
+
# <tt>passed</tt>:: defaults to <tt>green</tt>
|
18
|
+
# <tt>passed_arg</tt>:: defaults to <tt>green,bold</tt>
|
19
|
+
# <tt>outline</tt>:: defaults to <tt>cyan</tt>
|
20
|
+
# <tt>outline_arg</tt>:: defaults to <tt>cyan,bold</tt>
|
21
|
+
# <tt>skipped</tt>:: defaults to <tt>cyan</tt>
|
22
|
+
# <tt>skipped_arg</tt>:: defaults to <tt>cyan,bold</tt>
|
23
|
+
# <tt>comment</tt>:: defaults to <tt>grey</tt>
|
24
|
+
# <tt>tag</tt>:: defaults to <tt>cyan</tt>
|
25
|
+
#
|
26
|
+
# For instance, if your shell has a black background and a green font (like the
|
27
|
+
# "Homebrew" settings for OS X' Terminal.app), you may want to override passed
|
28
|
+
# steps to be white instead of green. Examples:
|
29
|
+
#
|
30
|
+
# export GHERKIN_COLORS="passed=white"
|
31
|
+
# export GHERKIN_COLORS="passed=white,bold:passed_arg=white,bold,underline"
|
32
|
+
#
|
33
|
+
# (If you're on Windows, use SET instead of export).
|
34
|
+
# To see what colours and effects are available, just run this in your shell:
|
35
|
+
#
|
36
|
+
# ruby -e "require 'rubygems'; require 'term/ansicolor'; puts Term::ANSIColor.attributes"
|
37
|
+
#
|
38
|
+
# Although not listed, you can also use <tt>grey</tt>
|
39
|
+
module AnsiEscapes
|
40
|
+
COLORS = {
|
41
|
+
'black' => "\e[30m",
|
42
|
+
'red' => "\e[31m",
|
43
|
+
'green' => "\e[32m",
|
44
|
+
'yellow' => "\e[33m",
|
45
|
+
'blue' => "\e[34m",
|
46
|
+
'magenta' => "\e[35m",
|
47
|
+
'cyan' => "\e[36m",
|
48
|
+
'white' => "\e[37m",
|
49
|
+
'grey' => "\e[90m",
|
50
|
+
'bold' => "\e[1m"
|
51
|
+
}
|
52
|
+
|
53
|
+
ALIASES = Hash.new do |h,k|
|
54
|
+
if k.to_s =~ /(.*)_arg/
|
55
|
+
h[$1] + ',bold'
|
56
|
+
end
|
57
|
+
end.merge({
|
58
|
+
'undefined' => 'yellow',
|
59
|
+
'pending' => 'yellow',
|
60
|
+
'executing' => 'grey',
|
61
|
+
'failed' => 'red',
|
62
|
+
'passed' => 'green',
|
63
|
+
'outline' => 'cyan',
|
64
|
+
'skipped' => 'cyan',
|
65
|
+
'comments' => 'grey',
|
66
|
+
'tag' => 'cyan'
|
67
|
+
})
|
68
|
+
|
69
|
+
if ENV['GHERKIN_COLORS'] # Example: export GHERKIN_COLORS="passed=red:failed=yellow"
|
70
|
+
ENV['GHERKIN_COLORS'].split(':').each do |pair|
|
71
|
+
a = pair.split('=')
|
72
|
+
ALIASES[a[0]] = a[1]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
ALIASES.keys.each do |key|
|
77
|
+
define_method(key) do
|
78
|
+
ALIASES[key].split(',').map{|color| COLORS[color]}.join('')
|
79
|
+
end
|
80
|
+
|
81
|
+
define_method("#{key}_arg") do
|
82
|
+
ALIASES["#{key}_arg"].split(',').map{|color| COLORS[color]}.join('')
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def reset
|
87
|
+
"\e[0m"
|
88
|
+
end
|
89
|
+
|
90
|
+
def up(n)
|
91
|
+
"\e[#{n}A"
|
92
|
+
end
|
93
|
+
|
94
|
+
extend self
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'gherkin/native'
|
2
|
+
require 'gherkin/formatter/hashable'
|
3
|
+
|
4
|
+
module Gherkin
|
5
|
+
module Formatter
|
6
|
+
class Argument < Hashable
|
7
|
+
native_impl('gherkin')
|
8
|
+
attr_reader :offset, :val
|
9
|
+
|
10
|
+
# Creates a new Argument that starts at character offset +offset+ with value +val+
|
11
|
+
def initialize(offset, val)
|
12
|
+
@offset, @val = offset, val
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Gherkin
|
2
|
+
module Formatter
|
3
|
+
module Escaping
|
4
|
+
# Escapes a pipes and backslashes:
|
5
|
+
#
|
6
|
+
# * | becomes \|
|
7
|
+
# * \ becomes \\
|
8
|
+
#
|
9
|
+
# This is used in the pretty formatter.
|
10
|
+
def escape_cell(s)
|
11
|
+
s.gsub(/\\(?!\|)/, "\\\\\\\\").gsub(/\n/, "\\n").gsub(/\|/, "\\|")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'gherkin/tag_expression'
|
2
|
+
require 'gherkin/formatter/regexp_filter'
|
3
|
+
require 'gherkin/formatter/line_filter'
|
4
|
+
require 'gherkin/formatter/tag_filter'
|
5
|
+
require 'gherkin/formatter/model'
|
6
|
+
require 'gherkin/native'
|
7
|
+
|
8
|
+
module Gherkin
|
9
|
+
module Formatter
|
10
|
+
class FilterFormatter
|
11
|
+
native_impl('gherkin')
|
12
|
+
|
13
|
+
def initialize(formatter, filters)
|
14
|
+
@formatter = formatter
|
15
|
+
@filter = detect_filter(filters)
|
16
|
+
|
17
|
+
@feature_tags = []
|
18
|
+
@feature_element_tags = []
|
19
|
+
@examples_tags = []
|
20
|
+
|
21
|
+
@feature_events = []
|
22
|
+
@background_events = []
|
23
|
+
@feature_element_events = []
|
24
|
+
@examples_events = []
|
25
|
+
end
|
26
|
+
|
27
|
+
def uri(uri)
|
28
|
+
@formatter.uri(uri)
|
29
|
+
end
|
30
|
+
|
31
|
+
def feature(feature)
|
32
|
+
@feature_tags = feature.tags
|
33
|
+
@feature_name = feature.name
|
34
|
+
@feature_events = [feature]
|
35
|
+
end
|
36
|
+
|
37
|
+
def background(background)
|
38
|
+
@feature_element_name = background.name
|
39
|
+
@feature_element_range = background.line_range
|
40
|
+
@background_events = [background]
|
41
|
+
end
|
42
|
+
|
43
|
+
def scenario(scenario)
|
44
|
+
replay!
|
45
|
+
@feature_element_tags = scenario.tags
|
46
|
+
@feature_element_name = scenario.name
|
47
|
+
@feature_element_range = scenario.line_range
|
48
|
+
@feature_element_events = [scenario]
|
49
|
+
end
|
50
|
+
|
51
|
+
def scenario_outline(scenario_outline)
|
52
|
+
replay!
|
53
|
+
@feature_element_tags = scenario_outline.tags
|
54
|
+
@feature_element_name = scenario_outline.name
|
55
|
+
@feature_element_range = scenario_outline.line_range
|
56
|
+
@feature_element_events = [scenario_outline]
|
57
|
+
end
|
58
|
+
|
59
|
+
def examples(examples)
|
60
|
+
replay!
|
61
|
+
@examples_tags = examples.tags
|
62
|
+
@examples_name = examples.name
|
63
|
+
|
64
|
+
table_body_range = case(examples.rows.length)
|
65
|
+
when 0 then examples.line_range.last..examples.line_range.last
|
66
|
+
when 1 then examples.rows[0].line..examples.rows[0].line
|
67
|
+
else examples.rows[1].line..examples.rows[-1].line
|
68
|
+
end
|
69
|
+
|
70
|
+
@examples_range = examples.line_range.first..table_body_range.last
|
71
|
+
if(@filter.eval([], [], [table_body_range]))
|
72
|
+
examples.rows = @filter.filter_table_body_rows(examples.rows)
|
73
|
+
end
|
74
|
+
@examples_events = [examples]
|
75
|
+
end
|
76
|
+
|
77
|
+
def step(step)
|
78
|
+
if @feature_element_events.any?
|
79
|
+
@feature_element_events << step
|
80
|
+
else
|
81
|
+
@background_events << step
|
82
|
+
end
|
83
|
+
|
84
|
+
@feature_element_range = @feature_element_range.first..step.line_range.last
|
85
|
+
end
|
86
|
+
|
87
|
+
def eof
|
88
|
+
replay!
|
89
|
+
@formatter.eof
|
90
|
+
end
|
91
|
+
|
92
|
+
def done
|
93
|
+
@formatter.done
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def detect_filter(filters)
|
99
|
+
raise "Inconsistent filters: #{filters.inspect}. Only one type [line,name,tag] can be used at once." if filters.map{|filter| filter.class}.uniq.length > 1
|
100
|
+
case(filters[0])
|
101
|
+
when Fixnum
|
102
|
+
LineFilter.new(filters)
|
103
|
+
when Regexp
|
104
|
+
RegexpFilter.new(filters)
|
105
|
+
when String
|
106
|
+
TagFilter.new(filters)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def replay!
|
111
|
+
feature_element_ok = @filter.eval(
|
112
|
+
(@feature_tags + @feature_element_tags),
|
113
|
+
[@feature_name, @feature_element_name].compact,
|
114
|
+
[@feature_element_range].compact
|
115
|
+
)
|
116
|
+
examples_ok = @filter.eval(
|
117
|
+
(@feature_tags + @feature_element_tags + @examples_tags),
|
118
|
+
[@feature_name, @feature_element_name, @examples_name].compact,
|
119
|
+
[@feature_element_range, @examples_range].compact
|
120
|
+
)
|
121
|
+
|
122
|
+
if feature_element_ok || examples_ok
|
123
|
+
replay_events!(@feature_events)
|
124
|
+
replay_events!(@background_events)
|
125
|
+
replay_events!(@feature_element_events)
|
126
|
+
|
127
|
+
if examples_ok
|
128
|
+
replay_events!(@examples_events)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
@examples_events.clear
|
133
|
+
@examples_tags.clear
|
134
|
+
@examples_name = nil
|
135
|
+
@examples_range = nil
|
136
|
+
end
|
137
|
+
|
138
|
+
def replay_events!(events)
|
139
|
+
events.each do |event|
|
140
|
+
event.replay(@formatter)
|
141
|
+
end
|
142
|
+
events.clear
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Gherkin
|
2
|
+
module Formatter
|
3
|
+
class Hashable
|
4
|
+
def to_hash
|
5
|
+
instance_variables.inject({}) do |hash, ivar|
|
6
|
+
value = instance_variable_get(ivar)
|
7
|
+
value = value.to_hash if value.respond_to?(:to_hash)
|
8
|
+
if Array === value
|
9
|
+
value = value.map do |e|
|
10
|
+
e.respond_to?(:to_hash) ? e.to_hash : e
|
11
|
+
end
|
12
|
+
end
|
13
|
+
hash[ivar[1..-1]] = value unless [[], nil].index(value)
|
14
|
+
hash
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|