I'm still trying to get my head around testing in Rails. Rails has a bit of a different use of the vocabulary that I'm used to for testing and TDD in .NET and Java. For instance, unit tests in Rails are tests for model objects that include writing to the database. From Pragmatic Programmers' From Agile Web Development with Rails (second edition), "Rails calls things that test models unit tests, things that test a single action in a controller functional tests, and things that test the flow through one or more controllers integration tests."
I've got only the most basic of the basics for writing Rails model objects, so I want to resist going against the natural grain of the Rails idioms just yet. Nonetheless, I really want to use the RSpec framework for Behavior-Driven Design from the get-go rather than get overly-invested in Ruby's built-in Test::Unit framework. This is probably a bit of a risky move since I don't yet know much about either RSpec or Test::Unit. If necessary, I think that I can easily abandon RSpec at this early stage without too much loss.
Getting the RSpec package installed is done with Ruby Gem. If you haven't seen how Ruby packages are installed before, you're in for a real treat. Gem is like ClickOnce, except that it doesn't get under your feet quite so much.
Install the RSpec core at the command prompt:
gem install rspec
RubyForge maintains an index of available gems. The install first looks for the gem locally, and then syncs with the gem index on RubyForge. Based on the source location in the gem index, it then downloads RSpec.
To use RSpec in a Rails project, the RSpec Rails plug-in has to be installed in the project. I created the "revent" project using the rails command line yesterday. The revent project is in C:\projects\revent on my development box. I need to install the plug-in from this location. Because I installed the 0.6.3 version of RSpec, I need to use the 0.6.3 version of the Rspec Rails plug-in. Installing this version to the revent project is done with the following command:
ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/REL_0_6_3/vendor/rspec_on_rails/vendor/plugins/rspec
Complete instructions for installing RSpec and plugging it into a Rails app can be found on the RSpec site at RubyForge: http://rspec.rubyforge.org/tools/rails.html
The installer downloads RSpec directly from it's the Subversion repository on RubyForge. Subversion is tightly integrated with most aspects of Rails and Ruby, from deployment to Rails' continuous integration.
With RSpec (ostensibly) plugged into my apps, I'm ready to try a bit of coding.
Posted
Thu, Aug 31 2006 4:25 AM
by
ScottBellware