Part 4
This is part 4 of the increasingly mis-named Getting started with Ispec and Ioke trilogy. Last time we discussed the let keyword and I started working on the template object which represented the template to be parsed into a document.
Previously I used ISpec to assert that we could evaluate on cells on Bag. I wanted to start off this time by proving to myself that I could just as easily use activatable cells on Bag as well.
it("should evaluate method on bag",
bag = Bag mimic
bag bread = method("butter")
evaluator = Evaluator mimic(bag)
evaluator evaluate(bread) should == "butter"
)As you can see, this time instead of assigning a string to a cell on the property bag an evaluating it, I instead assigned a method which returned a string to a cell and evaluated it. Sure enough it worked without any changes to the code. This creates some interesting possibilities, though I haven’t thought through all of the ramifications at the moment.
Sure enough it worked.
Next I wanted to push the envelope on Evaluator a little bit by defining the method which will do the work of parsing the template and injecting the values from the property bag into it.
describe("parsing",
it("should return the template when the bag is nil",
evaluator = Evaluator mimic(nil)
template = Template mimic
template text = "An extra special template"
document = evaluator combine(template)
document should == "An extra special template"
)
)This is really a small step, and as I get more familiar with TDD and BDD, these seem to the the steps that I’m most comforable with lining up and knocking down when implementing new features. The other part of this is, doing the simplest thing that could possibly work to pass the spec / test. In this case, this is the simplest thing.
Evaluator combine = method ( "Generates a document from a template and bag", template, template text )
From here, I think that the next step is going involve using Ioke’s implementation of Regexp, which I will need to read up on. So I think I will cut this short for today and wait for next time for that topic.
The Code
The code for this example is available on github tagged as start_ispec_4
Tags: ispec