class CukeModeler::Rule
A class modeling a rule in a Cucumber suite.
Attributes
The Background
object contained by the Rule
The keyword for the rule
Public Class Methods
Creates a new Rule
object and, if source_text is provided, populates the object.
@example
Rule.new Rule.new("Rule:\nThis is a rule")
@param source_text [String] The Gherkin text that will be used to populate the model @raise [ArgumentError] If source_text is not a String @return [Rule] A new Rule
instance
CukeModeler::Model::new
# File lib/cuke_modeler/models/rule.rb, line 34 def initialize(source_text = nil) @tags = [] @tests = [] super end
Public Instance Methods
Returns true if the rule contains a background, false otherwise.
@example
rule.background?
@return [Boolean] Whether the rule contains a background
# File lib/cuke_modeler/models/rule.rb, line 47 def background? !@background.nil? end
Returns the model objects that are children of this model. For a Rule
model, these would be any associated Background
, Scenario
, Outline
, or Tag
models.
@example
rule.children
@return [Array<Background, Scenario
, Outline
, Tag>] A collection of child models
# File lib/cuke_modeler/models/rule.rb, line 81 def children models = tests + tags models << background if background models end
See ‘Object#inspect`. Returns some basic information about the object, including its class, object ID, and its most meaningful attribute. For a Rule
model, this will be the name of the rule. If verbose is true, provides default Ruby inspection behavior instead.
@example
rule.inspect rule.inspect(verbose: true)
@param verbose [Boolean] Whether or not to return the full details of
the object. Defaults to false.
@return [String] A string representation of this model
CukeModeler::Model#inspect
# File lib/cuke_modeler/models/rule.rb, line 120 def inspect(verbose: false) return super if verbose "#{super.chop} @name: #{@name.inspect}>" end
Returns the outline models contained in the rule.
@example
rule.outlines
@return [Array<Outline>] Child Outline
models
# File lib/cuke_modeler/models/rule.rb, line 69 def outlines @tests.select { |test| test.is_a? Outline } end
Returns the scenario models contained in the rule.
@example
rule.scenarios
@return [Array<Scenario>] Child Scenario
models
# File lib/cuke_modeler/models/rule.rb, line 59 def scenarios @tests.select { |test| test.is_a? Scenario } end
Returns a string representation of this model. For a Rule
model, this will be Gherkin text that is equivalent to the rule being modeled.
@example
rule.to_s
@return [String] A string representation of this model
# File lib/cuke_modeler/models/rule.rb, line 95 def to_s text = '' text << "#{tag_output_string}\n" unless tags.empty? text << "#{@keyword}:#{name_output_string}" text << "\n#{description_output_string}" unless no_description_to_output? text << "\n\n#{background_output_string}" if background text << "\n\n#{tests_output_string}" unless tests.empty? text end
Private Instance Methods
# File lib/cuke_modeler/models/rule.rb, line 149 def background_output_string test_output_string(background) end
# File lib/cuke_modeler/models/rule.rb, line 139 def populate_model(parsed_rule_data) populate_parsing_data(parsed_rule_data) populate_source_location(parsed_rule_data) populate_keyword(parsed_rule_data) populate_name(parsed_rule_data) populate_description(parsed_rule_data) populate_tags(parsed_rule_data) populate_children(parsed_rule_data) end
# File lib/cuke_modeler/models/rule.rb, line 130 def process_source(source_text) base_file_string = "# language: #{Parsing.dialect}\n#{dialect_feature_keyword}: Fake feature to parse\n" source_text = base_file_string + source_text parsed_file = Parsing.parse_text(source_text, 'cuke_modeler_stand_alone_rule.feature') parsed_file['feature']['elements'].first end
# File lib/cuke_modeler/models/rule.rb, line 157 def test_output_string(model) model.to_s.split("\n").collect { |line| line.empty? ? '' : " #{line}" }.join("\n") end
# File lib/cuke_modeler/models/rule.rb, line 153 def tests_output_string tests.collect { |test| test_output_string(test) }.join("\n\n") end