Created
May 25, 2018 03:36
-
-
Save odarbelaeze/035c48c7f2957e0b98e23bec20cab233 to your computer and use it in GitHub Desktop.
Behaviour driven development.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
Author
odarbelaeze
commented
May 25, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment