[rspec-users] Testing a Rails plugin

Tom Locke tom at hobocentral.net
Thu Jun 21 09:31:42 EDT 2007


Hi

OK it looks like I'm a convert to BDD :-) Well in principle at least  
- let's see how it turns out.

I've just set up a test environment for the Hobo plugin according to  
this guide:

   http://www.pluginaweek.org/2006/11/24/plugin-tip-of-the-week- 
testing-your-plugins-the-right-way/

And then adapted the setup to work with RSpec

In the plugin I now have:

	/spec

	/spec/unit  --  all my specs are here in a hierarchy that mirrors my  
plugin's lib directory

	/spec/rails_root -- a complete Rails app, minus a few things

	/spec/spec.opts

	/spec/spec_helper.rb -- which looks like this:

--------------
ENV['RAILS_ENV'] ||= 'mysql'
require File.dirname(__FILE__) + '/rails_root/config/environment.rb'

# Run the migrations
ActiveRecord::Migrator.migrate("#{RAILS_ROOT}/db/migrate")

require 'spec/rails'

Spec::Runner.configure do |config|
   config.use_transactional_fixtures = true
   config.use_instantiated_fixtures  = false
   config.fixture_path = File.dirname(__FILE__) + "/fixtures/"
   config.before(:each, :behaviour_type => :controller) do
     raise_controller_errors
   end
end
--------------

It all seems to be working, but I haven't kicked the tires to hard yet.

Just thought I'd run this setup by you for comments.

Tom



More information about the rspec-users mailing list