class CucumberAnalytics::Feature
A class modeling a Cucumber Feature
.
Attributes
background[RW]
The Background
object contained by the Feature
tests[RW]
The TestElement
objects contained by the Feature
Public Class Methods
new(source = nil)
click to toggle source
Creates a new Feature
object and, if source is provided, populates the object.
Calls superclass method
# File lib/cucumber_analytics/feature.rb, line 20 def initialize(source = nil) parsed_feature = process_source(source) super(parsed_feature) @tags = [] @tag_elements = [] @tests = [] build_feature(parsed_feature) if parsed_feature end
Public Instance Methods
contains()
click to toggle source
Returns the immediate child elements of the feature (i.e. its Background
, Scenario
, and Outline
objects.
# File lib/cucumber_analytics/feature.rb, line 73 def contains @background ? [@background] + @tests : @tests end
has_background?()
click to toggle source
Returns true if the feature contains a background, false otherwise.
# File lib/cucumber_analytics/feature.rb, line 33 def has_background? !@background.nil? end
outline_count()
click to toggle source
Returns the number of outlines contained in the feature.
# File lib/cucumber_analytics/feature.rb, line 53 def outline_count outlines.count end
outlines()
click to toggle source
Returns the outlines contained in the feature.
# File lib/cucumber_analytics/feature.rb, line 43 def outlines @tests.select { |test| test.is_a? Outline } end
scenario_count()
click to toggle source
Returns the number of scenarios contained in the feature.
# File lib/cucumber_analytics/feature.rb, line 48 def scenario_count scenarios.count end
scenarios()
click to toggle source
Returns the scenarios contained in the feature.
# File lib/cucumber_analytics/feature.rb, line 38 def scenarios @tests.select { |test| test.is_a? Scenario } end
test_case_count()
click to toggle source
Returns the number of test cases contained in the feature.
# File lib/cucumber_analytics/feature.rb, line 63 def test_case_count scenario_count + outlines.reduce(0) { |outline_sum, outline| outline_sum += outline.examples.reduce(0) { |example_sum, example| example_sum += example.rows.count } } end
test_count()
click to toggle source
Returns the number of tests contained in the feature.
# File lib/cucumber_analytics/feature.rb, line 58 def test_count @tests.count end
to_s()
click to toggle source
Returns gherkin representation of the feature.
# File lib/cucumber_analytics/feature.rb, line 79 def to_s text = '' text << tag_output_string + "\n" unless tags.empty? text << "Feature:#{name_output_string}" text << "\n" + description_output_string unless description_text.empty? 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/cucumber_analytics/feature.rb, line 134 def background_output_string test_element_output_string(background) end
build_feature(parsed_feature)
click to toggle source
# File lib/cucumber_analytics/feature.rb, line 110 def build_feature(parsed_feature) populate_element_tags(parsed_feature) populate_feature_elements(parsed_feature) end
parse_feature(source_text)
click to toggle source
# File lib/cucumber_analytics/feature.rb, line 104 def parse_feature(source_text) parsed_file = Parsing::parse_text(source_text) parsed_file.first end
populate_feature_elements(parsed_feature)
click to toggle source
# File lib/cucumber_analytics/feature.rb, line 115 def populate_feature_elements(parsed_feature) elements = parsed_feature['elements'] if elements elements.each do |element| case element['keyword'] when 'Scenario' @tests << build_child_element(Scenario, element) when 'Scenario Outline' @tests << build_child_element(Outline, element) when 'Background' @background = build_child_element(Background, element) else raise(ArgumentError, "Unknown keyword: #{element['keyword']}") end end end end
process_source(source)
click to toggle source
# File lib/cucumber_analytics/feature.rb, line 95 def process_source(source) case when source.is_a?(String) parse_feature(source) else source end end
test_element_output_string(test_element)
click to toggle source
# File lib/cucumber_analytics/feature.rb, line 142 def test_element_output_string(test_element) test_element.to_s.split("\n").collect { |line| line.empty? ? '' : " #{line}" }.join("\n") end
tests_output_string()
click to toggle source
# File lib/cucumber_analytics/feature.rb, line 138 def tests_output_string tests.collect { |test| test_element_output_string(test) }.join("\n\n") end