title: How to express business logic as Behavior Driven Development (BDD) scenarios
body: <p>Behavior Driven Development (BDD) scenarios effectively express examples of how a system should behave but after writing hundreds of them I find that they don't comprehensively express business rules.</p>
  <p>For example, in <a href="https://dannorth.net/introducing-bdd/" rel="nofollow noreferrer">Dan North's introduction to BDD</a>, it shows how to express scenarios for a bank's handling of a customer's request for cash.  Although it shows examples of what should happen if the customer's account is above or below an overdraft limit, the scenarios <em>do not actually define the business rule</em>.</p>
  <p><strong>Scenario 1: Account is in credit</strong></p>
  <pre><code>Given the account is in credit
    And the card is valid
    And the dispenser contains cash
  When the customer requests cash
  Then ensure the account is debited
    And ensure cash is dispensed
    And ensure the card is returned
  </code></pre>
  <p><strong>Scenario 2: Account is overdrawn past the overdraft limit</strong></p>
  <pre><code>Given the account is overdrawn
    And the card is valid
  When the customer requests cash
  Then ensure a rejection message is displayed
    And ensure cash is not dispensed
    And ensure the card is returned
  </code></pre>
  <p>What <em>is</em> the overdraft limit???  Writing BDD scenarios this way does not effectively express the business rules.  How can BDD scenarios be used to express business logic?</p>
  <p>I've been trying to express business logic in BDD scenarios by using <a href="https://cucumber.io/docs/gherkin/reference/#scenario-outline" rel="nofollow noreferrer">BDD's &quot;scenario outlines&quot; as defined by Gherkin</a>.  In the scenario title I focus on the user action and then specify what the response should depend on.  I succinctly state the business rule, for example that the overdraft limit is $1000.  Here's how it looks:</p>
  <p><strong>Scenario: Request cash should not overdraw past the overdraft limit of $1000</strong></p>
  <pre><code>Given the account is in &lt;account_state&gt;
    And the card is valid
    And the dispenser contains cash
  When the customer requests cash
  Then ensure &lt;customer_response&gt;
    And ensure cash is &lt;cash_response&gt;
    And ensure the card is returned
  
  Examples:
  | account_state | customer_response                | cash_response |
  | in credit     | the account is debited           | dispensed     |
  | overdrawn     | a rejection message is displayed | not dispensed |
  </code></pre>
  <p>In <a href="https://stackoverflow.com/questions/1408553/specification-pattern-vs-spec-in-bdd">Specification Pattern vs Spec in BDD</a> it talks about expressing business logic but expresses some confusion about it.  Maybe it's saying the business logic should be expressed using Domain Driven Design (DDD) and that examples should be expressed as BDD scenarios for acceptance criteria.  But I don't know DDD and would prefer to see how BDD scenarios can simply be written differently to express business logic.</p>
  <p>Is there a better way to express the full business as BDD scenarios?  We don't want mere examples; we want the rule.  By analogy, in math you can express points on a curve or you express the equation that fits all those points.  We want the equation, not the points.</p>