7.5. How to Get RSpec-Like Features

RSpec has many very useful features when compared to standard Test::Unit testing. However, converting to RSpec is not trivial, and using both RSpec and Test::Unit in a program is not recommended (although the newest version of RSpec does allow you to run Test::Unit tests inside RSpec). It's awkward to get tools like rcov, rake, and autotest to run both sets of tests (again, this improved in RSpec 1.1). More importantly, it's very hard for team members to remember when to use RSpec and when to use Test::Unit in a system that attempts to use both.

For some RSpec features, though, there are additional plugins or tools that allow the same or similar functionality to be added to the standard Rails tests. This section briefly discusses a few of those options.

7.5.1. Testing Views

There are at least two separate packages that expand Rails automated test features to include separate tests for controllers and views. The good news is that if you've been playing along so far, you've already downloaded one of them: the ZenTest package that was used in Chapter 4 for its autotest functionality. ZenTest has another facet called Test::Rails. The primary purpose of Test::Rails is to augment the existing Rails tests with controller-only and view-only tests. Sounds like it might be a good match.

7.5.1.1. Test::Rails

As I mentioned, you've already downloaded ZenTest but if you haven't been following along, you can quickly catch up with a gem install ZenTest

Get Professional Ruby on Rails™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.