Sha256: c04cda3b3f57c2b434fc30c70aa33a7ed7bbe2b852f0b38cf8f4017bcad8b5ce
Contents?: true
Size: 1.6 KB
Versions: 4
Compression:
Stored size: 1.6 KB
Contents
module CukeModeler # A class modeling a step's doc string. class DocString < Model include Parsing include Parsed include Sourceable # The content type associated with the doc string attr_accessor :content_type # The content of the doc string attr_accessor :content # Creates a new DocString object and, if *source_text* is provided, populates # the object. def initialize(source_text = nil) super(source_text) if source_text parsed_doc_string_data = parse_source(source_text) populate_docstring(self, parsed_doc_string_data) end end # Returns a string representation of this model. For a doc string model, # this will be Gherkin text that is equivalent to the doc string being modeled. def to_s text = "\"\"\"#{content_type_output_string}\n" text << content_output_string text << '"""' end private def parse_source(source_text) base_file_string = "# language: #{Parsing.dialect}\n#{dialect_feature_keyword}:\n#{dialect_scenario_keyword}:\n#{dialect_step_keyword} step\n" source_text = base_file_string + source_text parsed_file = Parsing::parse_text(source_text, 'cuke_modeler_stand_alone_doc_string.feature') parsed_file['feature']['elements'].first['steps'].first['doc_string'] end def content_type_output_string content_type ? " #{content_type}" : '' end def content_output_string (content.nil? || content.empty?) ? '' : content.gsub('"""', '\"\"\"') + "\n" end end end
Version data entries
4 entries across 4 versions & 1 rubygems