1 Bootstrap the test environment
Make sure you perform all of the following steps from within your extension’s directory.
In your extension’s Gemfile uncomment or add the following line
$ bundle install
Now we will configure our test environment by preparing a dummy refinerycms app
Add the following lines to your extension’s Rakefile
ENGINE_PATH = File.dirname(__FILE__) APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__) load 'rails/tasks/engine.rake' if File.exists?(APP_RAKEFILE) require "refinerycms-testing" Refinery::Testing::Railtie.load_tasks Refinery::Testing::Railtie.load_dummy_tasks(ENGINE_PATH)
And run the dummy application generator:
$ bundle exec rake refinery:testing:dummy_app
To succesfully run rake tasks within your project you may need to add the refinerycms-testing gem to your application’s Gemfile, too.
2 Running the tests with Rake
$ bundle exec rake spec
This will run the rspec specs.
This is the most simple way to execute the test suite and useful for a one time run.
3 Running the tests with Guard
We recommend using Guard if you like to develop using TDD. Guard will watch your project for changes in files. If a change is made to a spec or a file that is tested against, it will re-run only the necessary specs. This is a faster way to get feedback during your TDD cycles.
At your extension’s root directory run:
$ bundle exec guard start
Larger Rails apps, particularly on Ruby 1.9.2, may take several seconds (or more) to start up. If that’s the case, you might also want to use Spork, which loads a single instance of the Rails environment and forks it to run tests, for even faster feedback cycles.