dry_plugin_test
- Author
-
Hendrik Volkmer - hvolkmer (at) imedo.de
- Copyright
-
Copyright © 2008 imedo GmbH
- Licence
-
MIT
- Git
- Bugs
-
No dedicated bug tracker yet - Email us or just send pull requests
Makes your plugin tests dry and isolates plugin tests from you real app.
Dependencies
-
Rails 2.0.2 (should work also with 1.2)
-
sqlite3 - www.sqlite.org/
Installation
The easiest way to install this gem is directly via the github gem repository:
$ sudo gem install imedo-dry_plugin_test_helper -s http://gems.github.com
Or
download the source code and build the gem yourself
$ git clone git://github.com/imedo/dry_plugin_test_helper.git
$ cd dry_plugin_test_helper
$ rake
$ sudo gem install pkg/dry_plugin_test_helper-0.0.4.gem
Usage
In your plugin test helper use these lines:
require 'rubygems'
require 'dry_plugin_test_helper'
PluginTestEnvironment.initialize_environment(File.dirname(__FILE__))
This sets up the test environment which means you have a stub rails app with you plugin loaded and also the following models:
-
Article: belongs_to :author, has_many :comments
-
Author: has_many :articles
-
Comment: belongs_to :articles, belongs_to :user
-
User: has_many :comments
The models will be added to a sqlite in memory database for fast testing.
You can add your own models using a migration in your test directory like this:
PluginTestEnvironment::Migration.setup do
create_table "animals", :force => true do |t|
t.column "name", :string
t.column "age", :integer
end
end
The database is automatically filled with the standard fixtures supplied by the gem. If you want to use your own fixtures (e.g. if you use additionals models) create them in the test/fixtures directory of your plugin. Note that the standard fixtures won’t get loaded if you use your own so you might have to add fixtures for the standard models if you need them.
If you don’t want the standard models (= database tables and fixtures) you can initialize the test environment like this:
PluginTestEnvironment.initialize_environment(File.dirname(__FILE__), :use_standard_migration => false)
TODO
-
support for RSpec and other testing frameworks (might already work - haven’t tried it)
-
Automatic Rails version discovery
-
Clean up / strip down rails env to bare minimum