[rspec-users] rspec_plugin generator

Pat Maddox pergesu at gmail.com
Wed Apr 4 00:07:29 EDT 2007


I've created a couple plugins lately, and have been using RSpec
instead of Test::Unit for them, so I wrote up this little generator.
Also does some isolated database testing if you want as an added
bonus.  Basic info:




Rails gives us a generator to create plugins with ./script/generate
plugin. It creates all the stub files, including some tests for you.
What if you want to use RSpec instead of Test::Unit though?

./script/generate rspec_plugin

Yep, it's super basic, it just does all the same stuff as the regular
plugin generator does, except it creates RSpec stubs for you.

There is one added bonus though, and that's that you can set up an
individual database for your plugin.

./script/generate rspec_plugin my_plugin --with-database

This will create a schema.rb file where you can create the schema for
your plugin specs, a database.yml file to configure the database
connection, and set up some helpful stuff in spec_helper.rb Nice for
quickly getting a plugin going with tests isolated against its own
database.

The database stuff is based on code from Chapter 8 of Rails Plugins:
Extending Rails Beyond the Core by James Adam. If you're writing a
plugin, check it out, you'll definitely learn a few tricks.

./script/plugin install svn://evang.eli.st/public/plugins/rspec_plugin


More information about the rspec-users mailing list