Switching from acceptance to unit

After writing some high level acceptance tests for the magic system I started thinking around how to make them pass. Stub for casting is as follows:

@when('{caster} casts {spell_and_target}')
def impl(context, caster, spell_and_target):
    assert False

It will take care of steps “Simon casts magic missile on Uglak” and “Simon casts healing wind”. Implementing the functionality required to make these steps to work is quite a lot, probably most of the magic system would be required. I decided to start breaking the functionality into parts and write the parts using tests to guide me.

Casting a spell is an action and I already have a working system that can be used to create actions. So the first step is to add method to Character class to create and execute a spell casting action and in order to do so, I wrote a test:

def test_spell_casting_executes_action(self):
    Casting a spell should activate the action
    magic_factory = MagicFactory()
    action = mock()

    action_factory = (ActionFactoryBuilder()
    caster = (CharacterBuilder()
    caster.cast(direction = 1, 
                spell_name = 'healing wind', 
                action_factory = action_factory)


The method that I added to Character class is short:

def cast(self, direction, spell_name, action_factory):
    Cast a spell
    action = action_factory.get_action(
                                                   direction = direction, 
                                                   spell_name = spell_name))

In addition to this I added MagicFactory and SpellCastingParameters. Details of those are not important, since they are mostly stubs at this point of development. Now that the test passes, I can start thinking what goes inside of MagicFactory when get_action – method is called and if MagicFactory is a good name to begin with.

Code for this steps can be found in commit: https://github.com/tuturto/pyherc/commit/55798b9d8bab28216298c76f05b6e0e8a4f23dda


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s