Ruby on Rails Chapter 3: Test Driven Development

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

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

Creative

Our Top 5 After Effects Expressions

We use After Effects for all of our video graphics. It’s a very versatile tool that allows anyone with a passing understanding of Photoshop or

Contact Us

  • This field is for validation purposes and should be left unchanged.
Photo of Current360 Associate Creative Director Robert Womack

Rob Womack

If there’s anyone who can honestly say, “Been there, done that,” it’s Rob. After traveling the world for seven years in his 20’s, Rob went to LA and started working in film production. Then it was off to New York, where he learned how to program, which eventually brought him back home to Louisville to build websites. At Current360, Rob heads up our in-house production studio, creating all things digital for our clients — videos, commercials, radio spots, and a lot more. 

When he’s at home, Rob likes to create things like homemade kombucha and music.