Ruby on Rails Chapter 3: Test Driven Development

Share This Post

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.

More To Explore

C360 The Ad Truth Is Out There

Truth in Advertising

The year was 1909. The US Army bought the first military aircraft from the Wright Brothers, Sigmund Freud lectured in NYC, and the Manhattan Bridge

Contact Us

  • This field is for validation purposes and should be left unchanged.

Chaney Given

Chaney is a talented and accomplished designer and illustrator, who has expanded his skill set to include motion graphics and video editing. With nearly a decade of experience, his client work includes Waterstep, Baptist Health, the Archdiocese of Louisville Catholic Schools, First Harrison Bank, and many more