diff --git a/CHANGELOG.md b/CHANGELOG.md index e174558f9..1020b98f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,11 +8,7 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt ## [Unreleased] ### Added -- [PHP] update dependency messages up to v26 ([#268](https://github.com/cucumber/gherkin/pull/268)) -- [JavaScript] update dependency messages up to v26 ([#268](https://github.com/cucumber/gherkin/pull/268)) -- [JavaScript] update dependency messages up to at least v19.1.4 ([#268](https://github.com/cucumber/gherkin/pull/268)) -- [Java] update dependency messages up to v26 ([#269](https://github.com/cucumber/gherkin/pull/269)) -- [Ruby] update dependency messages up to v26 ([#267](https://github.com/cucumber/gherkin/pull/267)) +- [PHP, Java, Ruby, JavaScript] update dependency messages up to v26 ### Changed - [.NET] Drop unsupported frameworks. Now supported target frameworks are .NET 8, .NET Standard 2.0 ([#265](https://github.com/cucumber/gherkin/pull/265)) @@ -21,6 +17,7 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt - [.NET] Adopt c# 10 ImplicitUsings - [.NET] Replace TinyJson to System.Text.Json - [.NET] Enable warnings as errors +- [Ruby] Initial rubocop autofixes (Mainly to style) ([#266](https://github.com/cucumber/gherkin/pull/266)) ## [29.0.0] - 2024-08-12 ### Added diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 72cddccac..021397fbd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,7 +34,7 @@ docker run --rm --interactive --tty --volume ".:/app" berp-env *Or* install on your system * .NET 5.0 (to run `berp` to generate parsers) -* `berp` (install with `dotnet tool update Berp --version 1.3.0 --tool-path /usr/bin` ) +* `berp` (install with `dotnet tool update Berp --version 1.4.0 --tool-path /usr/bin` ) * `make` * `diff` @@ -47,7 +47,7 @@ make generate ## Adding or updating an i18n language -1) Edit `gherkin-langauges.json`. +1) Edit `gherkin-languages.json`. 2) Distribute the changes to the different parser implementations: diff --git a/ruby/.rubocop.yml b/ruby/.rubocop.yml index 6a64fcbb2..c13fb8562 100644 --- a/ruby/.rubocop.yml +++ b/ruby/.rubocop.yml @@ -11,3 +11,7 @@ AllCops: # Display cop name / style guide references DisplayCopNames: true DisplayStyleGuide: true + +# TODO: [LH] - Investigate this in terms of it not being fixed in rubocop? +Naming/MethodName: + Enabled: false diff --git a/ruby/.rubocop_todo.yml b/ruby/.rubocop_todo.yml index 7da3223d8..6f52c1a6e 100644 --- a/ruby/.rubocop_todo.yml +++ b/ruby/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2024-07-18 10:25:13 UTC using RuboCop version 1.26.1. +# on 2024-09-10 17:08:57 UTC using RuboCop version 1.26.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -9,40 +9,20 @@ # TODO: We need to scan this file VERY carefully as the majority of items here WON'T be fixable as we want to keep # a similar style with each language implementation to ensure fixing bugs is easy # Pass 0 - July 2024 - 26 files inspected, 3031 offenses detected, 2667 offenses auto-correctable +# Pass 1 - August 2024 (Fix up a load of Style autofix cops) - 27 files inspected, 2691 offenses detected, 2356 offenses auto-correctable +# Pass 2 - September 2024 (Reconciled issues) - 27 files inspected, 2823 offenses detected, 2491 offenses auto-correctable -# Offense count: 6 -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: with_first_argument, with_fixed_indentation -Layout/ArgumentAlignment: - Exclude: - - 'lib/gherkin/token_formatter_builder.rb' - -# Offense count: 2 -# This cop supports safe auto-correction (--auto-correct). -Layout/ClosingParenthesisIndentation: - Exclude: - - 'lib/gherkin.rb' - -# Offense count: 80 +# Offense count: 63 # This cop supports safe auto-correction (--auto-correct). Layout/EmptyLineAfterGuardClause: Exclude: - - 'lib/gherkin/ast_builder.rb' - - 'lib/gherkin/dialect.rb' - 'lib/gherkin/parser.rb' - - 'lib/gherkin/pickles/compiler.rb' - - 'lib/gherkin/query.rb' - - 'lib/gherkin/stream/parser_message_stream.rb' - - 'lib/gherkin/token_matcher.rb' - - 'spec/gherkin/query_spec.rb' -# Offense count: 2 +# Offense count: 1 # This cop supports safe auto-correction (--auto-correct). Layout/EmptyLineAfterMagicComment: Exclude: - 'Gemfile' - - 'spec/gherkin/dialect_spec.rb' # Offense count: 51 # This cop supports safe auto-correction (--auto-correct). @@ -58,22 +38,6 @@ Layout/EmptyLines: - 'lib/gherkin/parser.rb' - 'spec/gherkin/stream/parser_message_stream_spec.rb' -# Offense count: 1 -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: around, only_before -Layout/EmptyLinesAroundAccessModifier: - Exclude: - - 'lib/gherkin/token_formatter_builder.rb' - -# Offense count: 1 -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: AllowAliasSyntax, AllowedMethods. -# AllowedMethods: alias_method, public, protected, private -Layout/EmptyLinesAroundAttributeAccessor: - Exclude: - - 'lib/gherkin/gherkin_line.rb' - # Offense count: 1 # This cop supports safe auto-correction (--auto-correct). # Configuration parameters: EnforcedStyle. @@ -82,15 +46,13 @@ Layout/EmptyLinesAroundBlockBody: Exclude: - 'lib/gherkin/pickles/compiler.rb' -# Offense count: 3 +# Offense count: 1 # This cop supports safe auto-correction (--auto-correct). # Configuration parameters: EnforcedStyle. # SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only Layout/EmptyLinesAroundClassBody: Exclude: - 'lib/gherkin/parser.rb' - - 'lib/gherkin/token_formatter_builder.rb' - - 'lib/gherkin/token_scanner.rb' # Offense count: 1 # This cop supports safe auto-correction (--auto-correct). @@ -100,43 +62,6 @@ Layout/EmptyLinesAroundModuleBody: Exclude: - 'lib/gherkin/parser.rb' -# Offense count: 1 -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment. -Layout/ExtraSpacing: - Exclude: - - 'lib/gherkin/errors.rb' - -# Offense count: 4 -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: consistent, consistent_relative_to_receiver, special_for_inner_method_call, special_for_inner_method_call_in_parentheses -Layout/FirstArgumentIndentation: - Exclude: - - 'lib/gherkin.rb' - - 'lib/gherkin/ast_builder.rb' - -# Offense count: 6 -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: IndentationWidth. -# SupportedStyles: special_inside_parentheses, consistent, align_brackets -Layout/FirstArrayElementIndentation: - EnforcedStyle: consistent - -# Offense count: 58 -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: Width, IgnoredPatterns. -Layout/IndentationWidth: - Exclude: - - 'lib/gherkin/parser.rb' - -# Offense count: 1 -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: AllowDoxygenCommentStyle, AllowGemfileRubyComment. -Layout/LeadingCommentSpace: - Exclude: - - 'lib/gherkin/token_matcher.rb' - # Offense count: 6 # This cop supports safe auto-correction (--auto-correct). # Configuration parameters: EnforcedStyle, IndentationWidth. @@ -145,62 +70,29 @@ Layout/MultilineOperationIndentation: Exclude: - 'lib/gherkin/token_matcher.rb' -# Offense count: 3 +# Offense count: 2 # This cop supports safe auto-correction (--auto-correct). Layout/SpaceAfterComma: Exclude: - - 'bin/gherkin' - 'bin/gherkin-generate-tokens' - 'lib/gherkin/gherkin_line.rb' -# Offense count: 4 +# Offense count: 1 # This cop supports safe auto-correction (--auto-correct). # Configuration parameters: EnforcedStyle. # SupportedStyles: space, no_space Layout/SpaceAroundEqualsInParameterDefault: Exclude: - - 'lib/gherkin.rb' - 'lib/gherkin/parser.rb' -# Offense count: 1 -# This cop supports safe auto-correction (--auto-correct). -Layout/SpaceAroundKeyword: - Exclude: - - 'lib/gherkin/token_scanner.rb' - -# Offense count: 8 +# Offense count: 4 # This cop supports safe auto-correction (--auto-correct). # Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator. # SupportedStylesForExponentOperator: space, no_space Layout/SpaceAroundOperators: Exclude: - - 'bin/gherkin' - - 'bin/gherkin-generate-tokens' - - 'lib/gherkin/errors.rb' - - 'lib/gherkin/gherkin_line.rb' - 'lib/gherkin/parser.rb' -# Offense count: 3 -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. -# SupportedStyles: space, no_space -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceInsideBlockBraces: - Exclude: - - 'lib/gherkin/pickles/compiler.rb' - - 'lib/gherkin/token_formatter_builder.rb' - -# Offense count: 10 -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. -# SupportedStyles: space, no_space, compact -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceInsideHashLiteralBraces: - Exclude: - - 'lib/gherkin/errors.rb' - - 'lib/gherkin/token_scanner.rb' - - 'spec/gherkin/gherkin_spec.rb' - # Offense count: 14 # This cop supports safe auto-correction (--auto-correct). # Configuration parameters: EnforcedStyle. @@ -209,21 +101,6 @@ Layout/SpaceInsideParens: Exclude: - 'lib/gherkin/parser.rb' -# Offense count: 1 -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: final_newline, final_blank_line -Layout/TrailingEmptyLines: - Exclude: - - 'spec/gherkin/gherkin_line_spec.rb' - -# Offense count: 2 -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: AllowInHeredoc. -Layout/TrailingWhitespace: - Exclude: - - 'lib/gherkin/parser.rb' - # Offense count: 1 # Configuration parameters: AllowSafeAssignment. Lint/AssignmentInCondition: @@ -235,11 +112,6 @@ Lint/ImplicitStringConcatenation: Exclude: - 'spec/gherkin/query_spec.rb' -# Offense count: 1 -Lint/IneffectiveAccessModifier: - Exclude: - - 'lib/gherkin.rb' - # Offense count: 4 Lint/LiteralAsCondition: Exclude: @@ -251,27 +123,14 @@ Lint/Loop: Exclude: - 'lib/gherkin/parser.rb' -# Offense count: 1 -Lint/NonLocalExitFromIterator: - Exclude: - - 'spec/gherkin/query_spec.rb' - -# Offense count: 4 +# Offense count: 3 # This cop supports safe auto-correction (--auto-correct). # Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods. Lint/UnusedMethodArgument: Exclude: - - 'bin/gherkin' - 'lib/gherkin/ast_builder.rb' - 'lib/gherkin/errors.rb' -# Offense count: 1 -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: ContextCreatingMethods, MethodCreatingMethods. -Lint/UselessAccessModifier: - Exclude: - - 'lib/gherkin.rb' - # Offense count: 2 Lint/UselessAssignment: Exclude: @@ -281,13 +140,13 @@ Lint/UselessAssignment: # Offense count: 59 # Configuration parameters: IgnoredMethods, CountRepeatedAttributes. Metrics/AbcSize: - Max: 121 + Max: 120 # Offense count: 8 # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. # IgnoredMethods: refine Metrics/BlockLength: - Max: 162 + Max: 165 # Offense count: 1 # Configuration parameters: CountBlocks. @@ -307,7 +166,7 @@ Metrics/CyclomaticComplexity: # Offense count: 71 # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. Metrics/MethodLength: - Max: 142 + Max: 141 # Offense count: 5 # Configuration parameters: CountKeywordArgs. @@ -327,26 +186,12 @@ Naming/AccessorMethodName: - 'lib/gherkin/parser.rb' - 'lib/gherkin/token_formatter_builder.rb' -# Offense count: 29 -# Configuration parameters: IgnoredPatterns. -# SupportedStyles: snake_case, camelCase -Naming/MethodName: - EnforcedStyle: snake_case - -# Offense count: 3 +# Offense count: 2 # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. # AllowedNames: at, by, db, id, in, io, ip, of, on, os, pp, to Naming/MethodParameterName: Exclude: - 'lib/gherkin/parser.rb' - - 'lib/gherkin/stream/parser_message_stream.rb' - -# Offense count: 2 -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: PreferredName. -Naming/RescuedExceptionsVariableName: - Exclude: - - 'lib/gherkin/stream/parser_message_stream.rb' # Offense count: 4 # Configuration parameters: EnforcedStyle, AllowedIdentifiers. @@ -382,14 +227,6 @@ Style/CaseLikeIf: - 'lib/gherkin/gherkin_line.rb' - 'lib/gherkin/token_matcher.rb' -# Offense count: 1 -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions. -# SupportedStyles: assign_to_condition, assign_inside_condition -Style/ConditionalAssignment: - Exclude: - - 'bin/gherkin' - # Offense count: 1 # This cop supports safe auto-correction (--auto-correct). Style/DefWithParentheses: @@ -414,20 +251,6 @@ Style/Documentation: - 'lib/gherkin/token_formatter_builder.rb' - 'lib/gherkin/token_matcher.rb' -# Offense count: 2 -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: compact, expanded -Style/EmptyMethod: - Exclude: - - 'lib/gherkin/token_formatter_builder.rb' - -# Offense count: 1 -# This cop supports safe auto-correction (--auto-correct). -Style/Encoding: - Exclude: - - 'spec/gherkin/dialect_spec.rb' - # Offense count: 1 # This cop supports safe auto-correction (--auto-correct). Style/ExpandPathArguments: @@ -448,35 +271,19 @@ Style/FormatString: Style/FormatStringToken: EnforcedStyle: unannotated -# Offense count: 25 +# Offense count: 26 # This cop supports safe auto-correction (--auto-correct). # Configuration parameters: EnforcedStyle. # SupportedStyles: always, always_true, never Style/FrozenStringLiteralComment: Enabled: false -# Offense count: 3 -# This cop supports safe auto-correction (--auto-correct). -Style/GlobalStdStream: - Exclude: - - 'bin/gherkin' - -# Offense count: 6 -# This cop supports safe auto-correction (--auto-correct). -Style/IfUnlessModifier: - Exclude: - - 'lib/gherkin/ast_builder.rb' - - 'lib/gherkin/gherkin_line.rb' - - 'lib/gherkin/pickles/compiler.rb' - - 'lib/gherkin/token_matcher.rb' - -# Offense count: 2 +# Offense count: 1 # This cop supports safe auto-correction (--auto-correct). # Configuration parameters: IgnoredMethods. Style/MethodCallWithoutArgsParentheses: Exclude: - 'lib/gherkin/parser.rb' - - 'lib/gherkin/token_matcher.rb' # Offense count: 3 # This cop supports safe auto-correction (--auto-correct). @@ -492,20 +299,6 @@ Style/MutableConstant: Exclude: - 'lib/gherkin/parser.rb' -# Offense count: 1 -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: both, prefix, postfix -Style/NegatedIf: - Exclude: - - 'lib/gherkin/token_matcher.rb' - -# Offense count: 1 -# This cop supports safe auto-correction (--auto-correct). -Style/Not: - Exclude: - - 'lib/gherkin/token_matcher.rb' - # Offense count: 3 # This cop supports unsafe auto-correction (--auto-correct-all). # Configuration parameters: EnforcedStyle, IgnoredMethods. @@ -522,12 +315,6 @@ Style/ParenthesesAroundCondition: Exclude: - 'lib/gherkin/parser.rb' -# Offense count: 1 -# This cop supports safe auto-correction (--auto-correct). -Style/PerlBackrefs: - Exclude: - - 'lib/gherkin/token_matcher.rb' - # Offense count: 3 # This cop supports unsafe auto-correction (--auto-correct-all). # Configuration parameters: EnforcedStyle. @@ -557,14 +344,12 @@ Style/RedundantRegexpEscape: Exclude: - 'spec/gherkin/stream/parser_message_stream_spec.rb' -# Offense count: 69 +# Offense count: 66 # This cop supports safe auto-correction (--auto-correct). # Configuration parameters: AllowMultipleReturnValues. Style/RedundantReturn: Exclude: - - 'lib/gherkin/ast_builder.rb' - 'lib/gherkin/parser.rb' - - 'lib/gherkin/token_matcher.rb' # Offense count: 1 # This cop supports safe auto-correction (--auto-correct). @@ -620,25 +405,17 @@ Style/StringConcatenation: - 'lib/gherkin/gherkin_line.rb' - 'lib/gherkin/pickles/compiler.rb' -# Offense count: 435 +# Offense count: 411 # This cop supports safe auto-correction (--auto-correct). # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. # SupportedStyles: single_quotes, double_quotes Style/StringLiterals: Exclude: - - 'Gemfile' - - 'bin/gherkin' - - 'bin/gherkin-generate-tokens' - - 'lib/gherkin/ast_builder.rb' - - 'lib/gherkin/dialect.rb' - 'lib/gherkin/parser.rb' - 'lib/gherkin/stream/parser_message_stream.rb' - 'lib/gherkin/token.rb' - 'lib/gherkin/token_formatter_builder.rb' - 'lib/gherkin/token_matcher.rb' - - 'spec/gherkin/gherkin_line_spec.rb' - - 'spec/gherkin/gherkin_spec.rb' - - 'spec/gherkin/query_spec.rb' - 'spec/gherkin/stream/parser_message_stream_spec.rb' # Offense count: 2 @@ -681,7 +458,7 @@ Style/TrailingCommaInArguments: Exclude: - 'lib/gherkin/ast_builder.rb' -# Offense count: 5 +# Offense count: 2 # This cop supports safe auto-correction (--auto-correct). # Configuration parameters: EnforcedStyleForMultiline. # SupportedStylesForMultiline: comma, consistent_comma, no_comma @@ -689,16 +466,14 @@ Style/TrailingCommaInArrayLiteral: Exclude: - 'lib/gherkin/parser.rb' - 'lib/gherkin/query.rb' - - 'spec/gherkin/query_spec.rb' -# Offense count: 2 +# Offense count: 1 # This cop supports safe auto-correction (--auto-correct). # Configuration parameters: EnforcedStyleForMultiline. # SupportedStylesForMultiline: comma, consistent_comma, no_comma Style/TrailingCommaInHashLiteral: Exclude: - 'lib/gherkin/pickles/compiler.rb' - - 'spec/gherkin/stream/parser_message_stream_spec.rb' # Offense count: 1 # This cop supports unsafe auto-correction (--auto-correct-all). @@ -706,7 +481,7 @@ Style/ZeroLengthPredicate: Exclude: - 'lib/gherkin/gherkin_line.rb' -# Offense count: 123 +# Offense count: 124 # This cop supports safe auto-correction (--auto-correct). # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https diff --git a/ruby/Gemfile b/ruby/Gemfile index aadb3470e..e5ad85c8d 100644 --- a/ruby/Gemfile +++ b/ruby/Gemfile @@ -1,4 +1,4 @@ # frozen_string_literal: true -source "https://rubygems.org" +source 'https://rubygems.org' gemspec diff --git a/ruby/bin/gherkin b/ruby/bin/gherkin index 6eda6f822..5f279838c 100755 --- a/ruby/bin/gherkin +++ b/ruby/bin/gherkin @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -$LOAD_PATH.unshift(File.join(File.dirname(__FILE__),"../lib")) +$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '../lib')) require 'optparse' require 'json' @@ -29,18 +29,19 @@ OptionParser.new do |opts| end end.parse! -def process_messages(messages, options) +def process_messages(messages, _options) messages.each do |message| - STDOUT.write(message.to_json) - STDOUT.write("\n") + $stdout.write(message.to_json) + $stdout.write("\n") end end -if ARGV.empty? - # Read from STDIN - messages = Cucumber::Messages::Helpers::NdjsonToMessageEnumerator.new(STDIN) -else - messages = Gherkin.from_paths(ARGV, options) -end +messages = + if ARGV.empty? + # Read from $stdin + Cucumber::Messages::Helpers::NdjsonToMessageEnumerator.new($stdin) + else + Gherkin.from_paths(ARGV, options) + end process_messages(messages, options) diff --git a/ruby/bin/gherkin-generate-tokens b/ruby/bin/gherkin-generate-tokens index 5392ebbeb..e1a7fb843 100755 --- a/ruby/bin/gherkin-generate-tokens +++ b/ruby/bin/gherkin-generate-tokens @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -$LOAD_PATH.unshift(File.join(File.dirname(__FILE__),"../lib")) +$LOAD_PATH.unshift(File.join(File.dirname(__FILE__),'../lib')) require 'gherkin/parser' require 'gherkin/token_formatter_builder' diff --git a/ruby/gherkin-ruby.razor b/ruby/gherkin-ruby.razor index d99ba0732..272ffec55 100644 --- a/ruby/gherkin-ruby.razor +++ b/ruby/gherkin-ruby.razor @@ -1,16 +1,16 @@ @using Berp; -@helper CallProduction(ProductionRule production) +@helper CallProduction(ProductionRule production, string extraIndent) { switch(production.Type) { case ProductionRuleType.Start: - @: start_rule(context, :@production.RuleName); + @:@(extraIndent) start_rule(context, :@production.RuleName); break; case ProductionRuleType.End: - @: end_rule(context, :@production.RuleName); + @:@(extraIndent) end_rule(context, :@production.RuleName); break; case ProductionRuleType.Process: - @: build(context, token); + @:@(extraIndent) build(context, token); break; } } @@ -149,15 +149,17 @@ module Gherkin @foreach(var transition in state.Transitions) { @:if @MatchToken(transition.TokenType) + var extraIndent = ""; if (transition.LookAheadHint != null) { + extraIndent = " "; @:@("if lookahead_")@(transition.LookAheadHint.Id)(context, token) } foreach(var production in transition.Productions) { - @CallProduction(production) + @CallProduction(production, extraIndent) } - @:return @transition.TargetState + @:@(extraIndent)return @transition.TargetState if (transition.LookAheadHint != null) { @:end @@ -171,7 +173,7 @@ module Gherkin @foreach(var lookAheadHint in Model.RuleSet.LookAheadHints) { - + def lookahead_@(lookAheadHint.Id)(context, currentToken) currentToken.detach token = nil @@ -194,7 +196,7 @@ module Gherkin return match end - + } private diff --git a/ruby/lib/gherkin.rb b/ruby/lib/gherkin.rb index 8bd27896e..0432c4d25 100644 --- a/ruby/lib/gherkin.rb +++ b/ruby/lib/gherkin.rb @@ -7,28 +7,26 @@ module Gherkin include_pickles: true }.freeze - def self.from_paths(paths, options={}) + def self.from_paths(paths, options = {}) Stream::ParserMessageStream.new( - paths, - [], - options + paths, + [], + options ).messages end - def self.from_sources(sources, options={}) + def self.from_sources(sources, options = {}) Stream::ParserMessageStream.new( - [], - sources, - options + [], + sources, + options ).messages end - def self.from_source(uri, data, options={}) + def self.from_source(uri, data, options = {}) from_sources([encode_source_message(uri, data)], options) end - private - def self.encode_source_message(uri, data) Cucumber::Messages::Source.new( uri: uri, diff --git a/ruby/lib/gherkin/ast_builder.rb b/ruby/lib/gherkin/ast_builder.rb index ddeac9974..9a48f06b8 100644 --- a/ruby/lib/gherkin/ast_builder.rb +++ b/ruby/lib/gherkin/ast_builder.rb @@ -24,10 +24,12 @@ def end_rule(rule_type) def build(token) if token.matched_type == :Comment - @comments.push(Cucumber::Messages::Comment.new( - location: get_location(token, 0), - text: token.matched_text - )) + @comments.push( + Cucumber::Messages::Comment.new( + location: get_location(token, 0), + text: token.matched_text + ) + ) else current_node.add(token.matched_type, token) end @@ -56,11 +58,13 @@ def get_tags(node) tags_node.get_tokens(:TagLine).each do |token| token.matched_items.each do |tag_item| - tags.push(Cucumber::Messages::Tag.new( - location: get_location(token, tag_item.column), - name: tag_item.text, - id: @id_generator.new_id - )) + tags.push( + Cucumber::Messages::Tag.new( + location: get_location(token, tag_item.column), + name: tag_item.text, + id: @id_generator.new_id + ) + ) end end @@ -81,11 +85,10 @@ def get_table_rows(node) def ensure_cell_count(rows) return if rows.empty? + cell_count = rows[0].cells.length rows.each do |row| - if row.cells.length != cell_count - raise AstBuilderException.new("inconsistent cell count within the table", row.location.to_h) - end + raise AstBuilderException.new('inconsistent cell count within the table', row.location.to_h) if row.cells.length != cell_count end end @@ -196,14 +199,16 @@ def transform_node(node) line_tokens = node.get_tokens(:Other) # Trim trailing empty lines last_non_empty = line_tokens.rindex { |token| !token.line.trimmed_line_text.empty? } - description = line_tokens[0..last_non_empty].map { |token| token.matched_text }.join("\n") - return description + line_tokens[0..last_non_empty].map { |token| token.matched_text }.join("\n") + when :Feature header = node.get_single(:FeatureHeader) return unless header + tags = get_tags(header) feature_line = header.get_token(:FeatureLine) return unless feature_line + children = [] background = node.get_single(:Background) children.push(Cucumber::Messages::FeatureChild.new(background: background)) if background @@ -228,8 +233,10 @@ def transform_node(node) when :Rule header = node.get_single(:RuleHeader) return unless header + rule_line = header.get_token(:RuleLine) return unless rule_line + tags = get_tags(header) children = [] background = node.get_single(:Background) @@ -255,7 +262,7 @@ def transform_node(node) feature: feature ) else - return node + node end end end diff --git a/ruby/lib/gherkin/dialect.rb b/ruby/lib/gherkin/dialect.rb index 3ffb010ec..0be8dc1b9 100644 --- a/ruby/lib/gherkin/dialect.rb +++ b/ruby/lib/gherkin/dialect.rb @@ -2,13 +2,14 @@ require 'json' module Gherkin - DIALECT_FILE_PATH = File.expand_path("gherkin-languages.json", File.dirname(__FILE__)) + DIALECT_FILE_PATH = File.expand_path('gherkin-languages.json', File.dirname(__FILE__)) DIALECTS = JSON.parse File.open(DIALECT_FILE_PATH, 'r:UTF-8').read class Dialect def self.for(name) spec = DIALECTS[name] return nil unless spec + new(spec) end diff --git a/ruby/lib/gherkin/errors.rb b/ruby/lib/gherkin/errors.rb index 3b6e435ee..3710b5bd0 100644 --- a/ruby/lib/gherkin/errors.rb +++ b/ruby/lib/gherkin/errors.rb @@ -33,7 +33,7 @@ class UnexpectedTokenException < ParserException def initialize(received_token, expected_token_types, state_comment) message = "expected: #{expected_token_types.join(", ")}, got '#{received_token.token_value.strip}'" column = received_token.location[:column] - location = (column.nil? || column.zero?) ? {line: received_token.location[:line], column: received_token.line.indent + 1} : received_token.location + location = (column.nil? || column.zero?) ? { line: received_token.location[:line], column: received_token.line.indent + 1 } : received_token.location super(message, location) end end diff --git a/ruby/lib/gherkin/gherkin_line.rb b/ruby/lib/gherkin/gherkin_line.rb index 8eacb16fc..6c41dcaa2 100644 --- a/ruby/lib/gherkin/gherkin_line.rb +++ b/ruby/lib/gherkin/gherkin_line.rb @@ -1,6 +1,7 @@ module Gherkin class GherkinLine attr_reader :indent, :trimmed_line_text + def initialize(line_text, line_number) @line_text = line_text @line_number = line_number @@ -13,7 +14,7 @@ def start_with?(prefix) end def start_with_title_keyword?(keyword) - start_with?(keyword+':') # The C# impl is more complicated. Find out why. + start_with?(keyword + ':') # The C# impl is more complicated. Find out why. end def get_rest_trimmed(length) @@ -89,9 +90,7 @@ def tags tags = [] items.each { |untrimmed| item = untrimmed.strip - if item.length == 0 - next - end + next if item.length == 0 unless item =~ /^\S+$/ location = { line: @line_number, column: column } diff --git a/ruby/lib/gherkin/parser.rb b/ruby/lib/gherkin/parser.rb index 67c36b0bd..1a58d14f4 100644 --- a/ruby/lib/gherkin/parser.rb +++ b/ruby/lib/gherkin/parser.rb @@ -446,11 +446,11 @@ def match_token_at_3(token, context) end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :FeatureHeader); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 11 + end_rule(context, :FeatureHeader); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 11 end end if match_TagLine(context, token) @@ -512,12 +512,12 @@ def match_token_at_4(token, context) end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :Description); - end_rule(context, :FeatureHeader); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 11 + end_rule(context, :Description); + end_rule(context, :FeatureHeader); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 11 end end if match_TagLine(context, token) @@ -578,11 +578,11 @@ def match_token_at_5(token, context) end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :FeatureHeader); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 11 + end_rule(context, :FeatureHeader); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 11 end end if match_TagLine(context, token) @@ -643,11 +643,11 @@ def match_token_at_6(token, context) end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :Background); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 11 + end_rule(context, :Background); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 11 end end if match_TagLine(context, token) @@ -708,12 +708,12 @@ def match_token_at_7(token, context) end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :Description); - end_rule(context, :Background); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 11 + end_rule(context, :Description); + end_rule(context, :Background); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 11 end end if match_TagLine(context, token) @@ -773,11 +773,11 @@ def match_token_at_8(token, context) end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :Background); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 11 + end_rule(context, :Background); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 11 end end if match_TagLine(context, token) @@ -842,12 +842,12 @@ def match_token_at_9(token, context) end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :Step); - end_rule(context, :Background); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 11 + end_rule(context, :Step); + end_rule(context, :Background); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 11 end end if match_TagLine(context, token) @@ -915,13 +915,13 @@ def match_token_at_10(token, context) end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :DataTable); - end_rule(context, :Step); - end_rule(context, :Background); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 11 + end_rule(context, :DataTable); + end_rule(context, :Step); + end_rule(context, :Background); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 11 end end if match_TagLine(context, token) @@ -1022,20 +1022,20 @@ def match_token_at_12(token, context) end if match_TagLine(context, token) if lookahead_1(context, token) - start_rule(context, :ExamplesDefinition); - start_rule(context, :Tags); - build(context, token); - return 17 + start_rule(context, :ExamplesDefinition); + start_rule(context, :Tags); + build(context, token); + return 17 end end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :Scenario); - end_rule(context, :ScenarioDefinition); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 11 + end_rule(context, :Scenario); + end_rule(context, :ScenarioDefinition); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 11 end end if match_TagLine(context, token) @@ -1106,22 +1106,22 @@ def match_token_at_13(token, context) end if match_TagLine(context, token) if lookahead_1(context, token) - end_rule(context, :Description); - start_rule(context, :ExamplesDefinition); - start_rule(context, :Tags); - build(context, token); - return 17 + end_rule(context, :Description); + start_rule(context, :ExamplesDefinition); + start_rule(context, :Tags); + build(context, token); + return 17 end end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :Description); - end_rule(context, :Scenario); - end_rule(context, :ScenarioDefinition); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 11 + end_rule(context, :Description); + end_rule(context, :Scenario); + end_rule(context, :ScenarioDefinition); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 11 end end if match_TagLine(context, token) @@ -1192,20 +1192,20 @@ def match_token_at_14(token, context) end if match_TagLine(context, token) if lookahead_1(context, token) - start_rule(context, :ExamplesDefinition); - start_rule(context, :Tags); - build(context, token); - return 17 + start_rule(context, :ExamplesDefinition); + start_rule(context, :Tags); + build(context, token); + return 17 end end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :Scenario); - end_rule(context, :ScenarioDefinition); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 11 + end_rule(context, :Scenario); + end_rule(context, :ScenarioDefinition); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 11 end end if match_TagLine(context, token) @@ -1280,22 +1280,22 @@ def match_token_at_15(token, context) end if match_TagLine(context, token) if lookahead_1(context, token) - end_rule(context, :Step); - start_rule(context, :ExamplesDefinition); - start_rule(context, :Tags); - build(context, token); - return 17 + end_rule(context, :Step); + start_rule(context, :ExamplesDefinition); + start_rule(context, :Tags); + build(context, token); + return 17 end end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :Step); - end_rule(context, :Scenario); - end_rule(context, :ScenarioDefinition); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 11 + end_rule(context, :Step); + end_rule(context, :Scenario); + end_rule(context, :ScenarioDefinition); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 11 end end if match_TagLine(context, token) @@ -1374,24 +1374,24 @@ def match_token_at_16(token, context) end if match_TagLine(context, token) if lookahead_1(context, token) - end_rule(context, :DataTable); - end_rule(context, :Step); - start_rule(context, :ExamplesDefinition); - start_rule(context, :Tags); - build(context, token); - return 17 + end_rule(context, :DataTable); + end_rule(context, :Step); + start_rule(context, :ExamplesDefinition); + start_rule(context, :Tags); + build(context, token); + return 17 end end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :DataTable); - end_rule(context, :Step); - end_rule(context, :Scenario); - end_rule(context, :ScenarioDefinition); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 11 + end_rule(context, :DataTable); + end_rule(context, :Step); + end_rule(context, :Scenario); + end_rule(context, :ScenarioDefinition); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 11 end end if match_TagLine(context, token) @@ -1505,24 +1505,24 @@ def match_token_at_18(token, context) end if match_TagLine(context, token) if lookahead_1(context, token) - end_rule(context, :Examples); - end_rule(context, :ExamplesDefinition); - start_rule(context, :ExamplesDefinition); - start_rule(context, :Tags); - build(context, token); - return 17 + end_rule(context, :Examples); + end_rule(context, :ExamplesDefinition); + start_rule(context, :ExamplesDefinition); + start_rule(context, :Tags); + build(context, token); + return 17 end end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :Examples); - end_rule(context, :ExamplesDefinition); - end_rule(context, :Scenario); - end_rule(context, :ScenarioDefinition); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 11 + end_rule(context, :Examples); + end_rule(context, :ExamplesDefinition); + end_rule(context, :Scenario); + end_rule(context, :ScenarioDefinition); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 11 end end if match_TagLine(context, token) @@ -1603,26 +1603,26 @@ def match_token_at_19(token, context) end if match_TagLine(context, token) if lookahead_1(context, token) - end_rule(context, :Description); - end_rule(context, :Examples); - end_rule(context, :ExamplesDefinition); - start_rule(context, :ExamplesDefinition); - start_rule(context, :Tags); - build(context, token); - return 17 + end_rule(context, :Description); + end_rule(context, :Examples); + end_rule(context, :ExamplesDefinition); + start_rule(context, :ExamplesDefinition); + start_rule(context, :Tags); + build(context, token); + return 17 end end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :Description); - end_rule(context, :Examples); - end_rule(context, :ExamplesDefinition); - end_rule(context, :Scenario); - end_rule(context, :ScenarioDefinition); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 11 + end_rule(context, :Description); + end_rule(context, :Examples); + end_rule(context, :ExamplesDefinition); + end_rule(context, :Scenario); + end_rule(context, :ScenarioDefinition); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 11 end end if match_TagLine(context, token) @@ -1703,24 +1703,24 @@ def match_token_at_20(token, context) end if match_TagLine(context, token) if lookahead_1(context, token) - end_rule(context, :Examples); - end_rule(context, :ExamplesDefinition); - start_rule(context, :ExamplesDefinition); - start_rule(context, :Tags); - build(context, token); - return 17 + end_rule(context, :Examples); + end_rule(context, :ExamplesDefinition); + start_rule(context, :ExamplesDefinition); + start_rule(context, :Tags); + build(context, token); + return 17 end end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :Examples); - end_rule(context, :ExamplesDefinition); - end_rule(context, :Scenario); - end_rule(context, :ScenarioDefinition); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 11 + end_rule(context, :Examples); + end_rule(context, :ExamplesDefinition); + end_rule(context, :Scenario); + end_rule(context, :ScenarioDefinition); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 11 end end if match_TagLine(context, token) @@ -1793,26 +1793,26 @@ def match_token_at_21(token, context) end if match_TagLine(context, token) if lookahead_1(context, token) - end_rule(context, :ExamplesTable); - end_rule(context, :Examples); - end_rule(context, :ExamplesDefinition); - start_rule(context, :ExamplesDefinition); - start_rule(context, :Tags); - build(context, token); - return 17 + end_rule(context, :ExamplesTable); + end_rule(context, :Examples); + end_rule(context, :ExamplesDefinition); + start_rule(context, :ExamplesDefinition); + start_rule(context, :Tags); + build(context, token); + return 17 end end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :ExamplesTable); - end_rule(context, :Examples); - end_rule(context, :ExamplesDefinition); - end_rule(context, :Scenario); - end_rule(context, :ScenarioDefinition); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 11 + end_rule(context, :ExamplesTable); + end_rule(context, :Examples); + end_rule(context, :ExamplesDefinition); + end_rule(context, :Scenario); + end_rule(context, :ScenarioDefinition); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 11 end end if match_TagLine(context, token) @@ -1928,11 +1928,11 @@ def match_token_at_23(token, context) end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :RuleHeader); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 31 + end_rule(context, :RuleHeader); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 31 end end if match_TagLine(context, token) @@ -1997,12 +1997,12 @@ def match_token_at_24(token, context) end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :Description); - end_rule(context, :RuleHeader); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 31 + end_rule(context, :Description); + end_rule(context, :RuleHeader); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 31 end end if match_TagLine(context, token) @@ -2066,11 +2066,11 @@ def match_token_at_25(token, context) end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :RuleHeader); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 31 + end_rule(context, :RuleHeader); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 31 end end if match_TagLine(context, token) @@ -2134,11 +2134,11 @@ def match_token_at_26(token, context) end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :Background); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 31 + end_rule(context, :Background); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 31 end end if match_TagLine(context, token) @@ -2202,12 +2202,12 @@ def match_token_at_27(token, context) end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :Description); - end_rule(context, :Background); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 31 + end_rule(context, :Description); + end_rule(context, :Background); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 31 end end if match_TagLine(context, token) @@ -2270,11 +2270,11 @@ def match_token_at_28(token, context) end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :Background); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 31 + end_rule(context, :Background); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 31 end end if match_TagLine(context, token) @@ -2342,12 +2342,12 @@ def match_token_at_29(token, context) end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :Step); - end_rule(context, :Background); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 31 + end_rule(context, :Step); + end_rule(context, :Background); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 31 end end if match_TagLine(context, token) @@ -2418,13 +2418,13 @@ def match_token_at_30(token, context) end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :DataTable); - end_rule(context, :Step); - end_rule(context, :Background); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 31 + end_rule(context, :DataTable); + end_rule(context, :Step); + end_rule(context, :Background); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 31 end end if match_TagLine(context, token) @@ -2528,20 +2528,20 @@ def match_token_at_32(token, context) end if match_TagLine(context, token) if lookahead_1(context, token) - start_rule(context, :ExamplesDefinition); - start_rule(context, :Tags); - build(context, token); - return 37 + start_rule(context, :ExamplesDefinition); + start_rule(context, :Tags); + build(context, token); + return 37 end end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :Scenario); - end_rule(context, :ScenarioDefinition); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 31 + end_rule(context, :Scenario); + end_rule(context, :ScenarioDefinition); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 31 end end if match_TagLine(context, token) @@ -2615,22 +2615,22 @@ def match_token_at_33(token, context) end if match_TagLine(context, token) if lookahead_1(context, token) - end_rule(context, :Description); - start_rule(context, :ExamplesDefinition); - start_rule(context, :Tags); - build(context, token); - return 37 + end_rule(context, :Description); + start_rule(context, :ExamplesDefinition); + start_rule(context, :Tags); + build(context, token); + return 37 end end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :Description); - end_rule(context, :Scenario); - end_rule(context, :ScenarioDefinition); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 31 + end_rule(context, :Description); + end_rule(context, :Scenario); + end_rule(context, :ScenarioDefinition); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 31 end end if match_TagLine(context, token) @@ -2704,20 +2704,20 @@ def match_token_at_34(token, context) end if match_TagLine(context, token) if lookahead_1(context, token) - start_rule(context, :ExamplesDefinition); - start_rule(context, :Tags); - build(context, token); - return 37 + start_rule(context, :ExamplesDefinition); + start_rule(context, :Tags); + build(context, token); + return 37 end end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :Scenario); - end_rule(context, :ScenarioDefinition); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 31 + end_rule(context, :Scenario); + end_rule(context, :ScenarioDefinition); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 31 end end if match_TagLine(context, token) @@ -2795,22 +2795,22 @@ def match_token_at_35(token, context) end if match_TagLine(context, token) if lookahead_1(context, token) - end_rule(context, :Step); - start_rule(context, :ExamplesDefinition); - start_rule(context, :Tags); - build(context, token); - return 37 + end_rule(context, :Step); + start_rule(context, :ExamplesDefinition); + start_rule(context, :Tags); + build(context, token); + return 37 end end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :Step); - end_rule(context, :Scenario); - end_rule(context, :ScenarioDefinition); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 31 + end_rule(context, :Step); + end_rule(context, :Scenario); + end_rule(context, :ScenarioDefinition); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 31 end end if match_TagLine(context, token) @@ -2892,24 +2892,24 @@ def match_token_at_36(token, context) end if match_TagLine(context, token) if lookahead_1(context, token) - end_rule(context, :DataTable); - end_rule(context, :Step); - start_rule(context, :ExamplesDefinition); - start_rule(context, :Tags); - build(context, token); - return 37 + end_rule(context, :DataTable); + end_rule(context, :Step); + start_rule(context, :ExamplesDefinition); + start_rule(context, :Tags); + build(context, token); + return 37 end end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :DataTable); - end_rule(context, :Step); - end_rule(context, :Scenario); - end_rule(context, :ScenarioDefinition); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 31 + end_rule(context, :DataTable); + end_rule(context, :Step); + end_rule(context, :Scenario); + end_rule(context, :ScenarioDefinition); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 31 end end if match_TagLine(context, token) @@ -3026,24 +3026,24 @@ def match_token_at_38(token, context) end if match_TagLine(context, token) if lookahead_1(context, token) - end_rule(context, :Examples); - end_rule(context, :ExamplesDefinition); - start_rule(context, :ExamplesDefinition); - start_rule(context, :Tags); - build(context, token); - return 37 + end_rule(context, :Examples); + end_rule(context, :ExamplesDefinition); + start_rule(context, :ExamplesDefinition); + start_rule(context, :Tags); + build(context, token); + return 37 end end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :Examples); - end_rule(context, :ExamplesDefinition); - end_rule(context, :Scenario); - end_rule(context, :ScenarioDefinition); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 31 + end_rule(context, :Examples); + end_rule(context, :ExamplesDefinition); + end_rule(context, :Scenario); + end_rule(context, :ScenarioDefinition); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 31 end end if match_TagLine(context, token) @@ -3127,26 +3127,26 @@ def match_token_at_39(token, context) end if match_TagLine(context, token) if lookahead_1(context, token) - end_rule(context, :Description); - end_rule(context, :Examples); - end_rule(context, :ExamplesDefinition); - start_rule(context, :ExamplesDefinition); - start_rule(context, :Tags); - build(context, token); - return 37 + end_rule(context, :Description); + end_rule(context, :Examples); + end_rule(context, :ExamplesDefinition); + start_rule(context, :ExamplesDefinition); + start_rule(context, :Tags); + build(context, token); + return 37 end end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :Description); - end_rule(context, :Examples); - end_rule(context, :ExamplesDefinition); - end_rule(context, :Scenario); - end_rule(context, :ScenarioDefinition); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 31 + end_rule(context, :Description); + end_rule(context, :Examples); + end_rule(context, :ExamplesDefinition); + end_rule(context, :Scenario); + end_rule(context, :ScenarioDefinition); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 31 end end if match_TagLine(context, token) @@ -3230,24 +3230,24 @@ def match_token_at_40(token, context) end if match_TagLine(context, token) if lookahead_1(context, token) - end_rule(context, :Examples); - end_rule(context, :ExamplesDefinition); - start_rule(context, :ExamplesDefinition); - start_rule(context, :Tags); - build(context, token); - return 37 + end_rule(context, :Examples); + end_rule(context, :ExamplesDefinition); + start_rule(context, :ExamplesDefinition); + start_rule(context, :Tags); + build(context, token); + return 37 end end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :Examples); - end_rule(context, :ExamplesDefinition); - end_rule(context, :Scenario); - end_rule(context, :ScenarioDefinition); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 31 + end_rule(context, :Examples); + end_rule(context, :ExamplesDefinition); + end_rule(context, :Scenario); + end_rule(context, :ScenarioDefinition); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 31 end end if match_TagLine(context, token) @@ -3323,26 +3323,26 @@ def match_token_at_41(token, context) end if match_TagLine(context, token) if lookahead_1(context, token) - end_rule(context, :ExamplesTable); - end_rule(context, :Examples); - end_rule(context, :ExamplesDefinition); - start_rule(context, :ExamplesDefinition); - start_rule(context, :Tags); - build(context, token); - return 37 + end_rule(context, :ExamplesTable); + end_rule(context, :Examples); + end_rule(context, :ExamplesDefinition); + start_rule(context, :ExamplesDefinition); + start_rule(context, :Tags); + build(context, token); + return 37 end end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :ExamplesTable); - end_rule(context, :Examples); - end_rule(context, :ExamplesDefinition); - end_rule(context, :Scenario); - end_rule(context, :ScenarioDefinition); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 31 + end_rule(context, :ExamplesTable); + end_rule(context, :Examples); + end_rule(context, :ExamplesDefinition); + end_rule(context, :Scenario); + end_rule(context, :ScenarioDefinition); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 31 end end if match_TagLine(context, token) @@ -3447,24 +3447,24 @@ def match_token_at_44(token, context) end if match_TagLine(context, token) if lookahead_1(context, token) - end_rule(context, :DocString); - end_rule(context, :Step); - start_rule(context, :ExamplesDefinition); - start_rule(context, :Tags); - build(context, token); - return 37 + end_rule(context, :DocString); + end_rule(context, :Step); + start_rule(context, :ExamplesDefinition); + start_rule(context, :Tags); + build(context, token); + return 37 end end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :DocString); - end_rule(context, :Step); - end_rule(context, :Scenario); - end_rule(context, :ScenarioDefinition); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 31 + end_rule(context, :DocString); + end_rule(context, :Step); + end_rule(context, :Scenario); + end_rule(context, :ScenarioDefinition); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 31 end end if match_TagLine(context, token) @@ -3564,13 +3564,13 @@ def match_token_at_46(token, context) end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :DocString); - end_rule(context, :Step); - end_rule(context, :Background); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 31 + end_rule(context, :DocString); + end_rule(context, :Step); + end_rule(context, :Background); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 31 end end if match_TagLine(context, token) @@ -3659,24 +3659,24 @@ def match_token_at_48(token, context) end if match_TagLine(context, token) if lookahead_1(context, token) - end_rule(context, :DocString); - end_rule(context, :Step); - start_rule(context, :ExamplesDefinition); - start_rule(context, :Tags); - build(context, token); - return 17 + end_rule(context, :DocString); + end_rule(context, :Step); + start_rule(context, :ExamplesDefinition); + start_rule(context, :Tags); + build(context, token); + return 17 end end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :DocString); - end_rule(context, :Step); - end_rule(context, :Scenario); - end_rule(context, :ScenarioDefinition); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 11 + end_rule(context, :DocString); + end_rule(context, :Step); + end_rule(context, :Scenario); + end_rule(context, :ScenarioDefinition); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 11 end end if match_TagLine(context, token) @@ -3773,13 +3773,13 @@ def match_token_at_50(token, context) end if match_TagLine(context, token) if lookahead_0(context, token) - end_rule(context, :DocString); - end_rule(context, :Step); - end_rule(context, :Background); - start_rule(context, :ScenarioDefinition); - start_rule(context, :Tags); - build(context, token); - return 11 + end_rule(context, :DocString); + end_rule(context, :Step); + end_rule(context, :Background); + start_rule(context, :ScenarioDefinition); + start_rule(context, :Tags); + build(context, token); + return 11 end end if match_TagLine(context, token) @@ -3850,7 +3850,7 @@ def lookahead_0(context, currentToken) return match end - + def lookahead_1(context, currentToken) currentToken.detach token = nil @@ -3873,7 +3873,7 @@ def lookahead_1(context, currentToken) return match end - + private def handle_ast_error(context, &action) diff --git a/ruby/lib/gherkin/pickles/compiler.rb b/ruby/lib/gherkin/pickles/compiler.rb index 580db6a1a..0f0aaf1bd 100644 --- a/ruby/lib/gherkin/pickles/compiler.rb +++ b/ruby/lib/gherkin/pickles/compiler.rb @@ -11,6 +11,7 @@ def compile(gherkin_document, source) pickles = [] return pickles unless gherkin_document.feature + feature = gherkin_document.feature language = feature.language tags = feature.tags @@ -143,9 +144,7 @@ def pickle_step_props(step, variable_cells, values_row, keyword_type) type: keyword_type, text: interpolate(step.text, variable_cells, value_cells), } - if values_row - props[:ast_node_ids].push(values_row.id) - end + props[:ast_node_ids].push(values_row.id) if values_row if step.data_table data_table = Cucumber::Messages::PickleStepArgument.new( @@ -180,14 +179,12 @@ def pickle_doc_string(doc_string, variable_cells, value_cells) props = { content: interpolate(doc_string.content, variable_cells, value_cells) } - if doc_string.media_type - props[:media_type] = interpolate(doc_string.media_type, variable_cells, value_cells) - end + props[:media_type] = interpolate(doc_string.media_type, variable_cells, value_cells) if doc_string.media_type Cucumber::Messages::PickleDocString.new(**props) end def pickle_tags(tags) - tags.map {|tag| pickle_tag(tag)} + tags.map { |tag| pickle_tag(tag) } end def pickle_tag(tag) diff --git a/ruby/lib/gherkin/query.rb b/ruby/lib/gherkin/query.rb index 12fa8226f..12c78111e 100644 --- a/ruby/lib/gherkin/query.rb +++ b/ruby/lib/gherkin/query.rb @@ -12,11 +12,13 @@ def update(message) def scenario_parent_locations(scenario_node_id) return @scenario_parent_locations[scenario_node_id] if @scenario_parent_locations.has_key?(scenario_node_id) + raise AstNodeNotLocatedException, "No scenario parent locations found for #{scenario_node_id} }. Known: #{@scenario_parent_locations.keys}" end def location(ast_node_id) return @ast_node_locations[ast_node_id] if @ast_node_locations.has_key?(ast_node_id) + raise AstNodeNotLocatedException, "No location found for #{ast_node_id} }. Known: #{@ast_node_locations.keys}" end @@ -24,6 +26,7 @@ def location(ast_node_id) def update_feature(feature) return if feature.nil? + store_nodes_location(feature.tags) feature.children.each do |child| @@ -35,6 +38,7 @@ def update_feature(feature) def update_rule(feature, rule) return if rule.nil? + store_nodes_location(rule.tags) rule.children.each do |child| update_background(rule, child.background) if child.background diff --git a/ruby/lib/gherkin/stream/parser_message_stream.rb b/ruby/lib/gherkin/stream/parser_message_stream.rb index 1d67056bf..15633fcc8 100644 --- a/ruby/lib/gherkin/stream/parser_message_stream.rb +++ b/ruby/lib/gherkin/stream/parser_message_stream.rb @@ -18,30 +18,31 @@ def initialize(paths, sources, options) def messages enumerated = false - Enumerator.new do |y| + Enumerator.new do |yielder| raise DoubleIterationException, "Messages have already been enumerated" if enumerated + enumerated = true sources.each do |source| - y.yield(Cucumber::Messages::Envelope.new(source: source)) if @options[:include_source] + yielder.yield(Cucumber::Messages::Envelope.new(source: source)) if @options[:include_source] begin gherkin_document = nil if @options[:include_gherkin_document] gherkin_document = build_gherkin_document(source) - y.yield(Cucumber::Messages::Envelope.new(gherkin_document: gherkin_document)) + yielder.yield(Cucumber::Messages::Envelope.new(gherkin_document: gherkin_document)) end if @options[:include_pickles] gherkin_document ||= build_gherkin_document(source) pickles = @compiler.compile(gherkin_document, source) pickles.each do |pickle| - y.yield(Cucumber::Messages::Envelope.new(pickle: pickle)) + yielder.yield(Cucumber::Messages::Envelope.new(pickle: pickle)) end end - rescue CompositeParserException => err - yield_parse_errors(y, err.errors, source.uri) - rescue ParserException => err - yield_parse_errors(y, [err], source.uri) + rescue CompositeParserException => e + yield_parse_errors(yielder, e.errors, source.uri) + rescue ParserException => e + yield_parse_errors(yielder, [e], source.uri) end end end @@ -49,7 +50,7 @@ def messages private - def yield_parse_errors(y, errors, uri) + def yield_parse_errors(yielder, errors, uri) errors.each do |err| parse_error = Cucumber::Messages::ParseError.new( source: Cucumber::Messages::SourceReference.new( @@ -61,22 +62,22 @@ def yield_parse_errors(y, errors, uri) ), message: err.message ) - y.yield(Cucumber::Messages::Envelope.new(parse_error: parse_error)) + yielder.yield(Cucumber::Messages::Envelope.new(parse_error: parse_error)) end end def sources - Enumerator.new do |y| + Enumerator.new do |yielder| @paths.each do |path| source = Cucumber::Messages::Source.new( uri: path, data: File.open(path, 'r:UTF-8', &:read), media_type: 'text/x.cucumber.gherkin+plain' ) - y.yield(source) + yielder.yield(source) end @sources.each do |source| - y.yield(source) + yielder.yield(source) end end end diff --git a/ruby/lib/gherkin/token_formatter_builder.rb b/ruby/lib/gherkin/token_formatter_builder.rb index 555369dfb..e2dea56b9 100644 --- a/ruby/lib/gherkin/token_formatter_builder.rb +++ b/ruby/lib/gherkin/token_formatter_builder.rb @@ -5,35 +5,35 @@ def initialize end def reset - @tokens_text = "" + @tokens_text = '' end def build(token) @tokens_text << "#{format_token(token)}\n" end - def start_rule(rule_type) - end + def start_rule(_rule_type); end - def end_rule(rule_type) - end + def end_rule(_rule_type); end def get_result @tokens_text end private + def format_token(token) - return "EOF" if token.eof? + return 'EOF' if token.eof? - sprintf "(%s:%s)%s:%s/%s/%s", + sprintf( + "(%s:%s)%s:%s/%s/%s", token.location[:line], token.location[:column], token.matched_type, token.matched_keyword ? sprintf("(%s)%s", token.matched_keyword_type, token.matched_keyword) : "", token.matched_text, - Array(token.matched_items).map { |i| "#{i.column}:#{i.text}"}.join(',') + Array(token.matched_items).map { |i| "#{i.column}:#{i.text}" }.join(',') + ) end - end end diff --git a/ruby/lib/gherkin/token_matcher.rb b/ruby/lib/gherkin/token_matcher.rb index 4e5280b92..b095121bf 100644 --- a/ruby/lib/gherkin/token_matcher.rb +++ b/ruby/lib/gherkin/token_matcher.rb @@ -48,21 +48,22 @@ def match_ExamplesLine(token) def match_TableRow(token) return false unless token.line.start_with?('|') - # TODO: indent - set_token_matched(token, :TableRow, nil, nil, nil, nil, - token.line.table_cells) + + set_token_matched(token, :TableRow, nil, nil, nil, nil, token.line.table_cells) true end def match_Empty(token) return false unless token.line.empty? + set_token_matched(token, :Empty, nil, nil, 0) true end def match_Comment(token) return false unless token.line.start_with?('#') - text = token.line.get_line_text(0) #take the entire line, including leading space + + text = token.line.get_line_text(0) # take the entire line, including leading space set_token_matched(token, :Comment, text, nil, 0) true end @@ -70,7 +71,7 @@ def match_Comment(token) def match_Language(token) return false unless token.line.trimmed_line_text =~ LANGUAGE_PATTERN - dialect_name = $1 + dialect_name = Regexp.last_match(1) set_token_matched(token, :Language, dialect_name) change_dialect(dialect_name, token.location) @@ -108,6 +109,7 @@ def _match_DocStringSeparator(token, separator, is_open) def match_EOF(token) return false unless token.eof? + set_token_matched(token, :EOF) true end @@ -132,22 +134,18 @@ def match_StepLine(token) title = token.line.get_rest_trimmed(keyword.length) keyword_types = @keyword_types[keyword] keyword_type = keyword_types[0] - if keyword_types.length() > 1 - keyword_type = Cucumber::Messages::StepKeywordType::UNKNOWN - end + keyword_type = Cucumber::Messages::StepKeywordType::UNKNOWN if keyword_types.length > 1 set_token_matched(token, :StepLine, title, keyword, nil, keyword_type) - return true + true end private def add_keyword_type_mappings(keywords, type) keywords.each do |keyword| - if not @keyword_types.has_key?(keyword) - @keyword_types[keyword] = [] - end + @keyword_types[keyword] = [] unless @keyword_types.has_key?(keyword) @keyword_types[keyword] += [type] end end diff --git a/ruby/lib/gherkin/token_scanner.rb b/ruby/lib/gherkin/token_scanner.rb index ac090078b..79df254e6 100644 --- a/ruby/lib/gherkin/token_scanner.rb +++ b/ruby/lib/gherkin/token_scanner.rb @@ -14,7 +14,7 @@ class TokenScanner def initialize(source_or_io) @line_number = 0 - case(source_or_io) + case source_or_io when String @io = StringIO.new(source_or_io) when StringIO, IO @@ -25,7 +25,7 @@ def initialize(source_or_io) end def read - location = {line: @line_number += 1} + location = { line: @line_number += 1 } if @io.nil? || line = @io.gets gherkin_line = line ? GherkinLine.new(line, location[:line]) : nil Token.new(gherkin_line, location) @@ -35,6 +35,5 @@ def read Token.new(nil, location) end end - end end diff --git a/ruby/spec/gherkin/gherkin_line_spec.rb b/ruby/spec/gherkin/gherkin_line_spec.rb index 975fe61d2..56ac2558d 100644 --- a/ruby/spec/gherkin/gherkin_line_spec.rb +++ b/ruby/spec/gherkin/gherkin_line_spec.rb @@ -5,7 +5,7 @@ def tags(line) end it 'allows any non-space characters in a tag' do - expect(tags(" @foo:bar @zap🥒yo")).to eq(['@foo:bar', '@zap🥒yo']) + expect(tags(' @foo:bar @zap🥒yo')).to eq(['@foo:bar', '@zap🥒yo']) end end @@ -19,7 +19,7 @@ def cells_text(line) end it 'trims white spaces after cell content' do - expect(cells_text("|spaces after |")).to eq(['spaces after']) + expect(cells_text('|spaces after |')).to eq(['spaces after']) end it 'trims white spaces around cell content' do @@ -31,7 +31,7 @@ def cells_text(line) end it 'trailing escapes are ignored' do - expect(cells_text("| a |\\")).to eq(['a']) + expect(cells_text('| a |\\')).to eq(['a']) end end end diff --git a/ruby/spec/gherkin/gherkin_spec.rb b/ruby/spec/gherkin/gherkin_spec.rb index 154e4f212..053d53df6 100644 --- a/ruby/spec/gherkin/gherkin_spec.rb +++ b/ruby/spec/gherkin/gherkin_spec.rb @@ -1,40 +1,40 @@ describe Gherkin do - it "can process feature file paths" do + it 'can process feature file paths' do messages = Gherkin.from_paths( - ["../testdata/good/minimal.feature"], - {include_source: true, - include_gherkin_document: true, - include_pickles: true} + ['../testdata/good/minimal.feature'], + { include_source: true, + include_gherkin_document: true, + include_pickles: true } ).to_a expect(messages.length).to eq(3) end - it "can process feature file content" do - data = File.open("../testdata/good/minimal.feature", 'r:UTF-8', &:read) + it 'can process feature file content' do + data = File.open('../testdata/good/minimal.feature', 'r:UTF-8', &:read) messages = Gherkin.from_source( - "uri", + 'uri', data, - {include_source: true, - include_gherkin_document: true, - include_pickles: true} + { include_source: true, + include_gherkin_document: true, + include_pickles: true } ).to_a expect(messages.length).to eq(3) end - it "can set the default dialect for the feature file content" do - data = File.open("../testdata/good/i18n_no.feature", 'r:UTF-8', &:read) + it 'can set the default dialect for the feature file content' do + data = File.open('../testdata/good/i18n_no.feature', 'r:UTF-8', &:read) data_without_language_header = data.split("\n")[1..-1].join("\n") messages = Gherkin.from_source( - "uri", + 'uri', data, - {include_source: true, - include_gherkin_document: true, - include_pickles: true, - default_dialect: "no"} + { include_source: true, + include_gherkin_document: true, + include_pickles: true, + default_dialect: 'no' } ).to_a expect(messages.length).to eq(3) diff --git a/ruby/spec/gherkin/query_spec.rb b/ruby/spec/gherkin/query_spec.rb index b73c0d36b..033156e71 100644 --- a/ruby/spec/gherkin/query_spec.rb +++ b/ruby/spec/gherkin/query_spec.rb @@ -5,7 +5,8 @@ def filter_messages_by_attribute(messages, attribute) messages.map do |message| - return unless message.respond_to?(attribute) + next unless message.respond_to?(attribute) + message.send(attribute) end.compact end @@ -25,7 +26,7 @@ def find_message_by_attribute(messages, attribute) end let(:feature_content) do - """ + ''" @feature-tag Feature: my feature @@ -53,7 +54,7 @@ def find_message_by_attribute(messages, attribute) @ruled-scenario-tag Scenario: a ruled scenario Given a step in the ruled scenario - """ + "'' end describe '#update' do @@ -76,10 +77,13 @@ def find_message_by_attribute(messages, attribute) let(:scenario) { scenarios.first } it 'provides the feature and background locations of a given scenario node id' do - expect(query.scenario_parent_locations(scenario.id)).to eq([ - gherkin_document.feature.location, - background.location, - ]) + expect(query.scenario_parent_locations(scenario.id)) + .to eq( + [ + gherkin_document.feature.location, + background.location + ] + ) end end @@ -89,12 +93,15 @@ def find_message_by_attribute(messages, attribute) let(:scenario) { find_message_by_attribute(rule.children, :scenario) } it 'provides the feature, background, rule, and rule background locations of a given scenario node id' do - expect(query.scenario_parent_locations(scenario.id)).to eq([ - gherkin_document.feature.location, - background.location, - rule.location, - rule_background.location, - ]) + expect(query.scenario_parent_locations(scenario.id)) + .to eq( + [ + gherkin_document.feature.location, + background.location, + rule.location, + rule_background.location + ] + ) end end @@ -102,15 +109,18 @@ def find_message_by_attribute(messages, attribute) let(:scenario) { scenarios.last } it 'provides the feature and background locations of a given scenario outline node id' do - expect(query.scenario_parent_locations(scenario.id)).to eq([ - gherkin_document.feature.location, - background.location, - ]) + expect(query.scenario_parent_locations(scenario.id)) + .to eq( + [ + gherkin_document.feature.location, + background.location + ] + ) end end it 'raises an exception if called with an invalid id' do - expect { query.scenario_parent_locations("BAD") }.to raise_error(Gherkin::AstNodeNotLocatedException) + expect { query.scenario_parent_locations('BAD') }.to raise_error(Gherkin::AstNodeNotLocatedException) end end @@ -125,7 +135,7 @@ def find_message_by_attribute(messages, attribute) let(:scenario) { scenarios.first } it 'raises an exception when the AST node ID is unknown' do - expect { query.location("this-id-may-not-exist-for-real") }.to raise_exception(Gherkin::AstNodeNotLocatedException) + expect { query.location('this-id-may-not-exist-for-real') }.to raise_exception(Gherkin::AstNodeNotLocatedException) end it 'provides the location of a scenario' do diff --git a/ruby/spec/gherkin/stream/parser_message_stream_spec.rb b/ruby/spec/gherkin/stream/parser_message_stream_spec.rb index 5d8e02aea..341edfb9d 100644 --- a/ruby/spec/gherkin/stream/parser_message_stream_spec.rb +++ b/ruby/spec/gherkin/stream/parser_message_stream_spec.rb @@ -17,7 +17,7 @@ module Stream let(:options) { { - include_gherkin_document: true, + include_gherkin_document: true } }