Loading...
Loading...

Ruby on Rails Blog Series

Welcome back to our Ruby on Rails blog series. In this chapter we create some of the more “static” pages of our sample microbloging application. They aren’t truly static as they have some dynamic elements, but their functionality could mainly be accomplished through HTML.

Test Driven Development (TDD)

We are also introduced to RSpec testing in this chapter, which is used throughout the remainder of the tutorial. RSpec is not the default-testing unit that comes with RoR. We use RSpec to create a testing unit that allows us to define what each section of our code is supposed to do. Run the tests, watch it fail, then alter the code until each test passes.  This allows us to be confident that our code is not only working, but also efficient.

Test driven development also will help you adhere to the DRY (don’t repeat yourself) principle of keeping your code modular. The benefits of this are numerous. By writing the test before you write the code you ensure that once the tests pasts you are delivering all the functionality you originally set out to accomplish — assuming you wrote a complete test. Additionally if you go to extend your application in the future you need only to write the tests for the new functionality. You already know that the base functionality is complete — that is why we wrote the tests. Now you once you get the new functionality tests passing you have extended your application without the fear of breaking what you already had working in the past.

I found Test Driven Development (TDD) to be very rewarding. You write a spec for what behavior you expect, watch it fail, alter the code as necessary and watch it pass. This allows you to always feel as if you are accomplishing tasks and moving forward with your code.

Comments(0)

Leave a Comment

five × 5 =