lib/cuke_modeler/models/rule.rb in cuke_modeler-3.3.0 vs lib/cuke_modeler/models/rule.rb in cuke_modeler-3.4.0
- old
+ new
@@ -26,21 +26,23 @@
def initialize(source_text = nil)
@tests = []
super(source_text)
- if source_text
- parsed_rule_data = parse_source(source_text)
- populate_rule(self, parsed_rule_data)
- end
+ return unless source_text
+
+ parsed_rule_data = parse_source(source_text)
+ populate_rule(self, parsed_rule_data)
end
# Returns *true* if the rule contains a background, *false* otherwise.
- def has_background?
+ def background?
!@background.nil?
end
+ alias has_background? background?
+
# Returns the scenario models contained in the rule.
def scenarios
@tests.select { |test| test.is_a? Scenario }
end
@@ -61,13 +63,13 @@
# this will be Gherkin text that is equivalent to the rule being modeled.
def to_s
text = ''
text << "#{@keyword}:#{name_output_string}"
- text << "\n" + description_output_string unless (description.nil? || description.empty?)
- text << "\n\n" + background_output_string if background
- text << "\n\n" + tests_output_string unless tests.empty?
+ 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
@@ -76,10 +78,10 @@
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 = Parsing.parse_text(source_text, 'cuke_modeler_stand_alone_rule.feature')
parsed_file['feature']['elements'].first
end
def background_output_string