Skip to content
Robert Cochran edited this page Jun 17, 2014 · 2 revisions

###Customizing Rules

Currently rules can only be customized through inline use of cuke_sniffer.

Rules are identified by the RULES hash build up at run time from the rules_config file and are identified by a symbol name for the rule. If you want to do anything to a rule you must first identify this symbol.

Rules have various components and all can be changed with enough knowledge. All rules will have the following keys that can be altered: :enabled, :phrase, :score, :targets, and :reason. It is best to leave targets alone at this time.

#####Turning off a rule If you want to turn off a rule you can either delete the rule from the hash or set its :enabled status to false.

CukeSniffer::RuleConfig::RULES[:numbers_in_description][:enabled] = false

#####Changing a phrase

CukeSniffer::RuleConfig::RULES[:background_with_no_scenarios][:phrase] = "Found a bad feature, background with no scenarios"

#####Changing a score (custom)

CukeSniffer::RuleConfig::RULES[:asterisk_step][:score] = 3000

#####Changing a score (stock)

CukeSniffer::RuleConfig::RULES[:asterisk_step][:score] = CukeSniffer::RuleConfig::FATAL

#####Changing a reason Sometimes it might be necessary to change the reason for a rule to better suit your particular needs.

Ex: Original rule is too generic for the sake of number in the description. I want to target story card numbers specifically.

:numbers_in_description => {

        :enabled => true,

        :phrase => "{class} has numbers in the description.",

        :score => WARNING,

        :targets => ["Feature", "Scenario", "Background"],

        :reason => "!(object.name =~ /\\d+/).nil?"

    }

rule[:reason] = lambda {|object, rule, type| object.name =~ /\Story\-\d+/}
rule[:phrase] = "{class} has a reference to a story card in the description"

You can also edit your source or use a gem extension to add/use your own rules! If you do let us know so we can consider putting it in the gem!

Clone this wiki locally