Skip to content

Instantly share code, notes, and snippets.

@odarbelaeze
Created May 25, 2018 03:36
Show Gist options
  • Save odarbelaeze/035c48c7f2957e0b98e23bec20cab233 to your computer and use it in GitHub Desktop.
Save odarbelaeze/035c48c7f2957e0b98e23bec20cab233 to your computer and use it in GitHub Desktop.
Behaviour driven development.
Feature: Fight of flight
In order to increase the ninja survival rate
As a ninja commander
I want my ninjas to decide whether to take on an
oponent based on their skill levels
Scenario: Weaker opponent
Given the ninja has a third level black-belt
When attacked by a samurai
Then the ninja should engage the opponent
Scenario: Stronger opponent
Given the ninja has a third level black-belt
When attacked by Chuck Norris
Then the ninja should run for his life
Scenario: Unknown opponent
Given the ninja has a third level black-belt
When attacked by an an enemy he can't gauge
Then the ninja should remain idle
from grappa import should
from behave import given, when, then
class Ninja(object):
def __init__(self):
self.status = 'idle'
def face_oponent(self, opponent):
if opponent == 'samurai':
self.status = 'engaging'
if opponent == 'Chuck Norris':
self.status = 'running for dear life'
@given(u'the ninja has a third level black-belt')
def ninja_with_level(context):
context.ninja = Ninja()
@when(u'attacked by a samurai')
def attacked_by_sammuray(context):
context.ninja.face_oponent('samurai')
@then(u'the ninja should engage the opponent')
def decides_to_engage(context):
context.ninja.status | should.be.equal.to('engaging')
@when(u'attacked by Chuck Norris')
def attacked_by_chuck(context):
context.ninja.face_oponent('Chuck Norris')
@then(u'the ninja should run for his life')
def decides_to_run(context):
context.ninja.status | should.be.equal.to('running for dear life')
@when(u'attacked by an an enemy he can\'t gauge')
def attacked_by_misterious_opponent(context):
context.ninja.face_oponent('Mistery oponent')
@then(u'the ninja should remain idle')
def decides_to_remain_idle(context):
context.ninja.status | should.be.equal.to('idle')
@odarbelaeze
Copy link
Author

Feature: Fight of flight # features/fight_or_flight.feature:1
  In order to increase the ninja survival rate
  As a ninja commander
  I want my ninjas to decide whether to take on an
  oponent based on their skill levels
  Scenario: Weaker opponent                      # features/fight_or_flight.feature:8
    Given the ninja has a third level black-belt # features/steps/ninja.py:16 0.000s
    When attacked by a samurai                   # features/steps/ninja.py:21 0.000s
    Then the ninja should engage the opponent    # features/steps/ninja.py:26 0.000s

  Scenario: Stronger opponent                    # features/fight_or_flight.feature:13
    Given the ninja has a third level black-belt # features/steps/ninja.py:16 0.000s
    When attacked by Chuck Norris                # features/steps/ninja.py:31 0.000s
    Then the ninja  should run for his life      # features/steps/ninja.py:36 0.000s

  Scenario: Unknown opponent                     # features/fight_or_flight.feature:18
    Given the ninja has a third level black-belt # features/steps/ninja.py:16 0.000s
    When attacked by an an enemy he can't gauge  # features/steps/ninja.py:41 0.000s
    Then the ninja should remain idle            # features/steps/ninja.py:46 0.000s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment