Skip to content

Commit

Permalink
Revert keyword arguments in ast classes. Fix remaining issues.
Browse files Browse the repository at this point in the history
Revert back to using the ast_builder to be able to distribute the
language and comments from the feature down the tree before the ast
classes are created.
  • Loading branch information
brasmusson committed Jul 6, 2015
1 parent d0f359f commit d2dc089
Show file tree
Hide file tree
Showing 19 changed files with 439 additions and 320 deletions.
9 changes: 3 additions & 6 deletions lib/cucumber/core/ast/background.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ class Background
include HasLocation
include DescribesItself

def initialize(gherkin_statement, language, location, comments, keyword, name, description, raw_steps)
@gherkin_statement = gherkin_statement
@language = language
def initialize(location, comments, keyword, name, description, raw_steps)
@location = location
@comments = comments
@keyword = keyword
Expand All @@ -21,11 +19,10 @@ def initialize(gherkin_statement, language, location, comments, keyword, name, d
@raw_steps = raw_steps
end

attr_reader :language, :description, :raw_steps
private :language, :raw_steps
attr_reader :description, :raw_steps
private :raw_steps

attr_reader :comments, :keyword, :location
attr_reader :gherkin_statement

def children
raw_steps
Expand Down
2 changes: 1 addition & 1 deletion lib/cucumber/core/ast/data_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DataTable
# You don't typically create your own DataTable objects - Cucumber will do
# it internally and pass them to your Step Definitions.
#
def initialize(rows:, location:)
def initialize(rows, location)
raw = ensure_array_of_array(rows)
verify_rows_are_same_length(raw)
@raw = raw.freeze
Expand Down
2 changes: 1 addition & 1 deletion lib/cucumber/core/ast/doc_string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DocString < SimpleDelegator

attr_reader :content_type, :content

def initialize(content:nil, content_type:nil, location: nil)
def initialize(content, content_type, location)
@content = content
@content_type = content_type
@location = location
Expand Down
5 changes: 3 additions & 2 deletions lib/cucumber/core/ast/examples_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ class ExamplesTable
include HasLocation
include DescribesItself

def initialize(location:, tags:, keyword:, name:, description: "", header:, example_rows:)
def initialize(location, comments, tags, keyword, name, description, header, example_rows)
@location = location
@comments = comments
@tags = tags
@keyword = keyword
@name = name
Expand All @@ -21,7 +22,7 @@ def initialize(location:, tags:, keyword:, name:, description: "", header:, exam
@example_rows = example_rows
end

attr_reader :location, :tags, :keyword,
attr_reader :location, :tags, :keyword, :comments,
:header, :example_rows

private
Expand Down
14 changes: 12 additions & 2 deletions lib/cucumber/core/ast/feature.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'cucumber/core/ast/describes_itself'
require 'cucumber/core/ast/names'
require 'cucumber/core/ast/location'
require 'gherkin3/dialect'

module Cucumber
module Core
Expand All @@ -15,7 +16,7 @@ class Feature
:comments, :tags, :keyword, :description,
:feature_elements

def initialize(language:, location:, background: EmptyBackground.new, comments:, tags:, keyword:, name:, description: "", scenario_definitions:)
def initialize(language, location, background, comments, tags, keyword, name, description, scenario_definitions)
@language = language
@location = location
@background = background
Expand All @@ -33,7 +34,7 @@ def children

def short_name
first_line = name.split(/\n/)[0]
if first_line =~ /#{language.keywords('feature')}:(.*)/
if first_line =~ /#{language.feature}:(.*)/
$1.strip
else
first_line
Expand Down Expand Up @@ -64,6 +65,15 @@ def method_missing(*args, &block)
self
end
end

class LanguageDelegator < SimpleDelegator
attr_reader :iso_code

def initialize(iso_code, obj)
super(obj)
@iso_code = iso_code
end
end
end
end
end
3 changes: 0 additions & 3 deletions lib/cucumber/core/ast/location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ class Lines < Struct.new(:data)
attr_reader :line

def initialize(raw_data)
if Cucumber::JRUBY && raw_data.is_a?(::Java::GherkinFormatterModel::Range)
raw_data = Range.new(raw_data.first, raw_data.last)
end
super Array(raw_data).to_set
@line = data.first
end
Expand Down
6 changes: 3 additions & 3 deletions lib/cucumber/core/ast/outline_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class OutlineStep

attr_reader :language, :location, :comments, :keyword, :name, :multiline_arg

def initialize(language, location, comments, keyword, name, multiline_arg)
@language, @location, @comments, @keyword, @name, @multiline_arg = language, location, comments, keyword, name, multiline_arg
def initialize(language, location, comments, keyword, text, multiline_arg)
@language, @location, @comments, @keyword, @name, @multiline_arg = language, location, comments, keyword, text, multiline_arg
end

def to_step(row)
Ast::ExpandedOutlineStep.new(self, gherkin_statement, language, row.location, comments, keyword, row.expand(name), replace_multiline_arg(row))
Ast::ExpandedOutlineStep.new(self, language, row.location, comments, keyword, row.expand(name), replace_multiline_arg(row))
end

def inspect
Expand Down
8 changes: 4 additions & 4 deletions lib/cucumber/core/ast/scenario.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ class Scenario
include HasLocation
include DescribesItself

attr_reader :language, :location, :background,
:tags, :keyword,
attr_reader :location, :background,
:comments, :tags, :keyword,
:description, :raw_steps
private :raw_steps

def initialize(language: "TODO", location:, tags:, keyword:, name:, description: "", steps:)
@language = language
def initialize(location, comments, tags, keyword, name, description, steps)
@location = location
@comments = comments
@tags = tags
@keyword = keyword
@name = name
Expand Down
8 changes: 4 additions & 4 deletions lib/cucumber/core/ast/scenario_outline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ class ScenarioOutline

MissingExamples = Class.new(StandardError)

attr_reader :language, :tags, :keyword,
attr_reader :comments, :tags, :keyword,
:steps, :examples_tables, :line
private :language, :line
private :line

def initialize(language: "TODO", location:, tags:, keyword:, name:, description: "", steps:, examples:)
@language = language
def initialize(location, comments, tags, keyword, name, description, steps, examples)
@location = location
@comments = comments
@tags = tags
@keyword = keyword
@name = name
Expand Down
11 changes: 6 additions & 5 deletions lib/cucumber/core/ast/step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def backtrace_line
end

def actual_keyword(previous_step_keyword = nil)
if [language.keywords('and'), language.keywords('but')].flatten.uniq.include? keyword
if [language.and, language.but].flatten.uniq.include? keyword
if previous_step_keyword.nil?
language.keywords('given').reject{|kw| kw == '* '}[0]
language.given.reject{|kw| kw == '* '}[0]
else
previous_step_keyword
end
Expand All @@ -52,14 +52,15 @@ def description_for_visitors

class ExpandedOutlineStep < Step

def initialize(outline_step, gherkin_statement, language, location, comments, keyword, name, multiline_arg)
@outline_step, @gherkin_statement, @language, @location, @comments, @keyword, @name, @multiline_arg = outline_step, gherkin_statement, language, location, comments, keyword, name, multiline_arg
def initialize(outline_step, language, location, comments, keyword, name, multiline_arg)
@outline_step, @language, @location, @comments, @keyword, @name, @multiline_arg = outline_step, language, location, comments, keyword, name, multiline_arg
end

alias :self_match_locations? :match_locations?

def match_locations?(queried_locations)
self_match_locations?(queried_locations) or @outline_step.match_locations?(queried_locations)
return true if self_match_locations?(queried_locations)
@outline_step.match_locations?(queried_locations)
end

alias :step_backtrace_line :backtrace_line
Expand Down
Loading

0 comments on commit d2dc089

Please sign in to comment.