I apologize if this question is slightly subjective... I am trying to figure out the best way to test Rails 3 Engines with Cucumber & Rspec. In order to test the engine a r
I'll explain how I did it using as example the following gem: https://github.com/skozlov/netzke-core
The testing application. It is in netzke-core/test/rails_app
. This app can be run independently, so I can also use it for manual testing or for playing around with new features if I like.
In order for the testing app to load the gem itself, I have the following in application.rb
:
$:.unshift File.expand_path('../../../../lib', __FILE__)
require 'netzke-core'
Cucumber features. They are in netzke-core/features
. In env.rb
I have:
require File.expand_path(File.dirname(__FILE__) + '/../../test/rails_app/config/environment')
... which will load the testing application before executing the features.
Specs. These are in netzke-core/spec
. In spec_helper.rb
I have the following:
require File.expand_path("../../test/rails_app/config/environment", __FILE__)
... which will load the testing application before running the specs.
Running tests. This setup lets me run the tests from the root of the gem:
cucumber features
and
rspec spec
Factory Girl. Not for this particular gem, but I'm normally using factory_girl instead of fixtures (see, for example, a similar setup in https://github.com/skozlov/netzke-basepack).