Skip to main content
made more concise + fixed grammar
Source Link
user34636
user34636

I'm writing a utility that validates fields on a web site. I decided I'd giveto try my hand at Behaviour Driven Development (BDD) a try. The validator utilises rules"rules" to determine if a value the user providedfield is valid.

Three different types of rules are used to validate fieldsexist:

  1. RegexRule (fieldA field conforms to specific pattern(s))
  2. RequireRule (valueA value is present)
  3. EqualityRule (fieldA field's value equals another field'sanother's value).

A rule is tested against a value, and if. If the value does not conform to the nature of the rule, a flag is set, marking which marks the rule as erroneous. Upon callingCalling getError() on an erroneous rule, returns a string is returned detailingthat details the error. Furthermore, and the rule is reset (no longer erroneous).

Is this the correct manner of implementing BDD on this class? If not, I'd greatly appreciate advice on how I could improve on this.

I'm writing a utility that validates fields on a web site. I decided I'd give Behaviour Driven Development (BDD) a try. The validator utilises rules to determine if a value the user provided is valid.

Three different types of rules are used to validate fields:

  1. RegexRule (field conforms to specific pattern(s))
  2. RequireRule (value is present)
  3. EqualityRule (field value equals another field's value).

A rule is tested against a value, and if the value does not conform to the nature of the rule, a flag is set, marking the rule as erroneous. Upon calling getError() on an erroneous rule, a string is returned detailing the error, and the rule is reset (no longer erroneous).

Is this the correct manner of implementing BDD on this class? If not, I'd greatly appreciate advice on how I could improve on this.

I'm writing a utility that validates fields. I decided to try my hand at Behaviour Driven Development (BDD). The validator utilises "rules" to determine if field is valid.

Three different types of rules exist:

  1. RegexRule A field conforms to specific pattern(s)
  2. RequireRule A value is present
  3. EqualityRule A field's value equals another's value

A rule is tested against a value. If the value does not conform to the rule, a flag is set which marks the rule as erroneous. Calling getError() on an erroneous rule returns a string that details the error. Furthermore, the rule is reset (no longer erroneous).

Is this the correct manner of implementing BDD on this class? I'd greatly appreciate advice on how I could improve on this.

edited tags
Link
konijn
  • 34.4k
  • 5
  • 71
  • 267
Add OP's comment
Source Link
Wayne Conrad
  • 3.3k
  • 1
  • 18
  • 38

The test framework is Mocha.

The test framework is Mocha.

added 1 characters in body
Source Link
user34636
user34636
Loading
added link and removed a single quotation mark from code
Source Link
ChrisWue
  • 20.6k
  • 4
  • 43
  • 107
Loading
added 4 characters in body
Source Link
user34636
user34636
Loading
added 4 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238
Loading
Source Link
user34636
user34636
Loading