- Author
-
Hendrik Volkmer - hvolkmer (at) imedo.de
- Copyright
-
Copyright © 2008-2010 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.
-
Rails > 2.0.2
-
sqlite3 - www.sqlite.org/
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.11.gem
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 in $HOME/.dry_plugin_test_helper/2.3/ (for Rails 2.3) 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.
If you have more then one Rails version installed, you can specify the version to use using the :rails_version Option like this:
PluginTestEnvironment.initialize_environment(File.dirname(__FILE__), :rails_version => '2.3.3')
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)