Skip to content

Commit

Permalink
Decouple implementation from test framework
Browse files Browse the repository at this point in the history
Removing some code that was unintentionally added due to the needs of
the test framework.
  • Loading branch information
enkessler committed May 27, 2020
1 parent bd537a5 commit db24407
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/cuke_modeler/parsing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def parse_text(source_text, filename = 'cuke_modeler_fake_file.feature')
# NOT A PART OF THE PUBLIC API
# The method to use for parsing Gherkin text
def parsing_method(source_text, filename)
messages = Gherkin.from_source(filename, source_text, { :default_dialect => CukeModeler::Parsing.dialect, :include_gherkin_document => true }).to_a.map(&:to_hash)
messages = Gherkin.from_source(filename, source_text, { :include_gherkin_document => true }).to_a.map(&:to_hash)

potential_error_message = messages.find { |message| message[:attachment] }
gherkin_ast_message = messages.find { |message| message[:gherkin_document] }
Expand All @@ -102,7 +102,7 @@ def parsing_method(source_text, filename)
# NOT A PART OF THE PUBLIC API
# The method to use for parsing Gherkin text
def parsing_method(source_text, filename)
messages = Gherkin.from_source(filename, source_text, { :default_dialect => CukeModeler::Parsing.dialect, :include_gherkin_document => true }).to_a.map(&:to_hash)
messages = Gherkin.from_source(filename, source_text, { :include_gherkin_document => true }).to_a.map(&:to_hash)

potential_error_message = messages.find { |message| message[:attachment] }
gherkin_ast_message = messages.find { |message| message[:gherkinDocument] }
Expand All @@ -117,7 +117,7 @@ def parsing_method(source_text, filename)
# NOT A PART OF THE PUBLIC API
# The method to use for parsing Gherkin text
def parsing_method(source_text, filename)
messages = Gherkin::Gherkin.from_source(filename, source_text, { :default_dialect => CukeModeler::Parsing.dialect }).to_a.map(&:to_hash)
messages = Gherkin::Gherkin.from_source(filename, source_text).to_a.map(&:to_hash)

potential_error_message = messages.find { |message| message[:attachment] }
gherkin_ast_message = messages.find { |message| message[:gherkinDocument] }
Expand Down
33 changes: 32 additions & 1 deletion testing/rspec/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,44 @@
gherkin_major_version = Gem.loaded_specs['gherkin'].version.version.match(/^(\d+)\./)[1].to_i

case gherkin_major_version
when 6, 7, 8, 9
when 8, 9
# TODO: choose randomly from Gherkin::DIALECTS once I figure out how to handle encodings...
test_dialect = ['en', 'en-lol', 'en-pirate', 'en-Scouse'].sample
puts "Testing with dialect '#{test_dialect}'..."

CukeModeler::DialectHelper.set_dialect(Gherkin::DIALECTS[test_dialect])
CukeModeler::Parsing.dialect = test_dialect

module Gherkin
class << self
alias_method :original_from_source, :from_source

def from_source(uri, data, options = {})
options[:default_dialect] ||= CukeModeler::Parsing.dialect
original_from_source(uri, data, options)
end
end
end
when 6, 7
# TODO: choose randomly from Gherkin::DIALECTS once I figure out how to handle encodings...
test_dialect = ['en', 'en-lol', 'en-pirate', 'en-Scouse'].sample
puts "Testing with dialect '#{test_dialect}'..."

CukeModeler::DialectHelper.set_dialect(Gherkin::DIALECTS[test_dialect])
CukeModeler::Parsing.dialect = test_dialect

module Gherkin
class Gherkin
class << self
alias_method :original_from_source, :from_source

def from_source(uri, data, options = {})
options[:default_dialect] ||= CukeModeler::Parsing.dialect
original_from_source(uri, data, options)
end
end
end
end
when 3, 4, 5
# TODO: stop using test dialect and just randomize for all version of `gherkin`
dialect_file_path = "#{this_dir}/../../test_languages.json"
Expand Down

0 comments on commit db24407

Please sign in to comment.