How to use report_unused_steps method of Spinach Package

Best Spinach_ruby code snippet using Spinach.report_unused_steps


Source:auditor.rb Github


Full Screen

...23 result = audit_file(file)24 clean &&= result # set to false if any result is false25 end26 # At the end, report any unused steps27 report_unused_steps28 # If the audit was clean, make sure the user knows29 puts "\nAudit clean - no missing steps.".colorize(:light_green) if clean30 true31 end32 private33 def audit_file(file)34 puts "\nAuditing: ".colorize(:magenta) + file.colorize(:light_magenta)35 # Find the feature definition and its associated step defs class36 feature, step_defs_class = get_feature_and_defs(file)37 return step_file_missing if step_defs_class.nil?38 step_defs = step_defs_class.new39 unused_step_names = step_names_for_class(step_defs_class)40 missing_steps = {}41 feature.each_step do |step|42 # Audit the step43 missing_steps[] = step if step_missing?(step, step_defs)44 # Having audited the step, remove it from the list of unused steps45 unused_step_names.delete step.name46 end47 # If there are any steps left at the end, let's mark them as unused48 store_unused_steps(unused_step_names, step_defs)49 # And then generate a report of missing steps50 return true if missing_steps.empty?51 report_missing_steps(missing_steps.values)52 false53 end54 # Get the feature and its definitions from the appropriate files55 def get_feature_and_defs(file)56 feature = Parser.open_file(file).parse57 [feature, Spinach.find_step_definitions(]58 end59 # Process a step from the feature file using the given step_defs.60 # If it is missing, return true. Otherwise, add it to the used_steps for61 # the report at the end and return false.62 def step_missing?(step, step_defs)63 method_name = Spinach::Support.underscore step.name64 return true unless step_defs.respond_to?(method_name)65 # Remember that we have used this step66 used_steps << step_defs.step_location_for(':')67 false68 end69 # Store any unused step names for the report at the end of the audit70 def store_unused_steps(names, step_defs)71 names.each do |name|72 location = step_defs.step_location_for(name).join(':')73 unused_steps[location] = name74 end75 end76 # Print a message alerting the user that there is no step file for this77 # feature78 def step_file_missing79 puts 'Step file missing: please run --generate first!'80 .colorize(:light_red)81 false82 end83 # Get the step names for all steps in the given class, including those in84 # common modules85 def step_names_for_class(klass)86 { |a| a.respond_to?(:steps) ? a.steps : [] }.flatten87 end88 # Produce a report of unused steps that were not found anywhere in the audit89 def report_unused_steps90 # Remove any unused_steps that were in common modules and used91 # in another feature92 used_steps.each { |location| unused_steps.delete location }93 unused_steps.each do |location, name|94 puts "\n" + "Unused step: #{location} ".colorize(:yellow) +95 "'#{name}'".colorize(:light_yellow)96 end97 end98 # Print a report of the missing step objects provided99 def report_missing_steps(steps)100 puts "\nMissing steps:".colorize(:light_cyan)101 steps.each do |step|102 puts^/, ' ')103 .colorize(:cyan)...

Full Screen

Full Screen


Using AI Code Generation


Full Screen

1Spinach.hooks.on_tag("unused") do2Spinach.hooks.on_tag("unused") do3, js_errors: false)4 def path_to(page_name)5World(NavigationHelpers)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:


You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Spinach_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?