class CukeModeler::Rule

A class modeling a rule in a Cucumber suite.

Attributes

background[RW]

The Background object contained by the Rule

keyword[RW]

The keyword for the rule

tests[RW]

The Scenario and Outline objects contained by the Rule

Public Class Methods

new(source_text = nil) click to toggle source

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

Calls superclass method CukeModeler::Model::new
# File lib/cuke_modeler/models/rule.rb, line 34
def initialize(source_text = nil)
  @tags = []
  @tests = []

  super
end

Public Instance Methods

background?() click to toggle source

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
Also aliased as: has_background?
children() click to toggle source

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
has_background?()
Alias for: background?
inspect(verbose: false) click to toggle source

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

Calls superclass method 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
outlines() click to toggle source

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
scenarios() click to toggle source

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
to_s() click to toggle source

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

background_output_string() click to toggle source
# File lib/cuke_modeler/models/rule.rb, line 149
def background_output_string
  test_output_string(background)
end
populate_model(parsed_rule_data) click to toggle source
# 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
process_source(source_text) click to toggle source
# 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
test_output_string(model) click to toggle source
# 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
tests_output_string() click to toggle source
# File lib/cuke_modeler/models/rule.rb, line 153
def tests_output_string
  tests.collect { |test| test_output_string(test) }.join("\n\n")
end