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
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.
Calls superclass method
CukeModeler::Model::new
# File lib/cuke_modeler/models/rule.rb, line 26 def initialize(source_text = nil) @tags = [] @tests = [] super(source_text) return unless source_text parsed_rule_data = parse_source(source_text) populate_rule(self, parsed_rule_data) end
Public Instance Methods
background?()
click to toggle source
Returns true if the rule contains a background, false otherwise.
# File lib/cuke_modeler/models/rule.rb, line 39 def background? !@background.nil? end
Also aliased as: has_background?
children()
click to toggle source
Returns the model objects that belong to this model.
# File lib/cuke_modeler/models/rule.rb, line 56 def children models = tests + tags models << background if background models end
outlines()
click to toggle source
Returns the outline models contained in the rule.
# File lib/cuke_modeler/models/rule.rb, line 51 def outlines @tests.select { |test| test.is_a? Outline } end
scenarios()
click to toggle source
Returns the scenario models contained in the rule.
# File lib/cuke_modeler/models/rule.rb, line 46 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.
# File lib/cuke_modeler/models/rule.rb, line 68 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 94 def background_output_string test_output_string(background) end
parse_source(source_text)
click to toggle source
rubocop:enable Metrics/AbcSize
# File lib/cuke_modeler/models/rule.rb, line 85 def parse_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 102 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 98 def tests_output_string tests.collect { |test| test_output_string(test) }.join("\n\n") end