class FuzzyGherkin::Comparitor
Attributes
all_steps[RW]
base_step[RW]
fsm[RW]
similar_steps[RW]
threshold[RW]
Public Class Methods
new(base_step, threshold)
click to toggle source
# File lib/fuzzy_gherkin/comparitor.rb, line 6 def initialize(base_step, threshold) @threshold = threshold.to_f @similar_steps = [] @base_step = base_step @all_steps = [] @fsm = FuzzyStringMatch::JaroWinkler.create(:pure) end
Public Instance Methods
all_feature_files()
click to toggle source
# File lib/fuzzy_gherkin/comparitor.rb, line 14 def all_feature_files Dir['**/*.feature'] end
all_steps_in_files()
click to toggle source
# File lib/fuzzy_gherkin/comparitor.rb, line 18 def all_steps_in_files all_steps = [] all_feature_files.each do |file| scenarios = parse_feature_file(file) scenarios.each do |scenario| all_steps << scenario[:steps].map! { |step| step[:text] } end end all_steps.flatten.uniq end
compare_all_steps_in_files()
click to toggle source
# File lib/fuzzy_gherkin/comparitor.rb, line 29 def compare_all_steps_in_files start_time = Time.now all_steps_in_files.each do |step| compare_step_to_base_step(step) end end_time = Time.now puts "Comparison ended after #{end_time - start_time} seconds!" end
compare_step_to_base_step(comparing_step)
click to toggle source
Compares the given step to the base step
# File lib/fuzzy_gherkin/comparitor.rb, line 47 def compare_step_to_base_step(comparing_step) puts "Comparing base step to: '#{comparing_step}'" distance = @fsm.getDistance(@base_step, comparing_step) puts "distance: #{distance}" # 1.0 is a perfect match. # This means its a repeated step and we can ignore. if distance >= @threshold && distance != 1.0 @similar_steps << "#{(distance * 100).round(2)}% - " + comparing_step else distance end end
parse_feature_file(feature_file)
click to toggle source
Returns background and sceanrios in feature file
# File lib/fuzzy_gherkin/comparitor.rb, line 39 def parse_feature_file(feature_file) parser = Gherkin::Parser.new raise "FAILURE: File not found at #{feature_path}" unless File.file?(feature_file) gherkin_document = parser.parse(File.read(feature_file)) gherkin_document[:feature][:children] end