a-lights-spec Pub   Share

The implementation of the greeting system

Specifications, like a-lights-spec deal with the actual implementation of the system. You can use $when for actual implementation of the messages or $mock when the implementations are not available. You can have both an implementation and a mock - you'll figure out later on how to disable the mocks in production mode.

Our system will turn the lights on when a guest arrives:

$when:: home.guest_arrived (name)
   lights.on

Then we have a sensor which we check to see if they're truly on:

$when:: lights.on
   lights.check

We can also mock the systems that we don't have access to yet, let's pretend the lights are bright:

0 $mock:: lights.check
   . (lightIntensity="bright")

Chimes

We also have a chimes system: one that can greet guests. Let's configure it to greet only Jane...

$when:: home.guest_arrived (name is "Jane")
   chimes.welcome (name="Jane"="Jane")

Since we don't have the chimes system built yet, we'll just mock it:

0 $mock:: chimes.welcome
   . (greeting=("Greetings, " + name))

You can see how this new $when rule matches only Jane - so other guests will not be notified... something you can test: so why don't you test to see if John is greeted (hint: change Jane to John in the story and see what happens) !


Was this useful?    

By: Razie | 2016-06-17 .. 2026-09-19 | Tags: spec , dsl , home , private


Viewed 4172 times ( | History | Print ) this page.

You need to log in to post a comment!

© Copyright DieselApps, 2012-2026, all rights reserved.