Gregory Moeck presentations github twitter feed

This is a part of an ongoing series on BDD in Sproutcore. You can find the index for the series here

Step 2 - Viewing the count of tasks

The next feature of the sample todos application that I'd like to implement is the count of todos on the bottom of the page. In order to do this, I'm going to need some more integration tests (apps/todos/tests/integration/viewing_count_of_task.js):

This fails with the following errors:

This is telling me that the summary view does not exist yet, so I create it:

Which then changes the error message to be the following:

This tells me that the summary view doesn't have the binding that I want it to have, so I bind it's value to the controller with a function that does not exist yet, but that I wish it had:

Once I do that, Sproutcore again yields no error, but I know that there is no function countSummary on the tasksController, so I write a failing unit test for that function (app/todos/tests/controllers/tasks.js):

Which gives the following failure:

Which is telling me that I haven't implemented countSummary on the controller, so I implement it:

Which changes the failure to:

Which I then make pass by modifying tasksController:

This makes all the tests pass, which means it's time to clean up the display:

Quick Note

What I'm about to do could(or maybe even should) really be put off until we were adding tasks, but since adding tasks is a bit more complicated, I'm going to show it here for the benefit of the beginner.

End Quick Note

Now, we want that summary to update when there are tasks, so I add an integration test:

In order to accomplish that, I add a unit test for the controller:

In order to make that pass, I change the tasksController to be:

Now, there is one more case that I want to cover, and that is when is more than one task, so I add an integration test:

This fails with the following message:

In order to make that pass, I add the following unit test:

I use the simplest way I can think of to implement that:

And all my tests are passing. However, that countSummary function on the controller isn't really as clean as I would like, so I refactor it to be:

And all tests are passing, and when I browse to look at the page, it seems to work as intended when i manually add items into the store.

Step 3- Adding a task

blog comments powered by Disqus