How to test Rails 3 Engines with Cucumber & Rspec?
- by cowboycoded
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 rails 3 app is necessary. Here is what I am currently doing:
Add a rails test app to the root of the gem (myengine) by running: rails new /myengine/rails_app
Add Cucumber to /myengine/rails_app/features as you would in a normal Rails app
Require the Rails Engine Gem (using :path=>"/myengine") in /myengine/rails_app/Gemfile
Add spec to the root directory of the gem: /myengine/spec
Include the fixtures in /myengine/spec/fixtures and I add the following to my cuc env.rb:
env.rb:
Fixtures.reset_cache
fixtures_folder = File.join(Rails.root, 'spec', 'fixtures')
fixtures = Dir[File.join(fixtures_folder, '*.yml')].map {|f| File.basename(f, '.yml') }
Fixtures.create_fixtures(fixtures_folder, fixtures)
Do you see any problems with setting it up like this? The tests run fine, but I am a bit hesitant to put the features inside the test rails app. I originally tried putting the features in the root of the gem and I created the test rails app inside features/support, but for some reason my engine would not initialize when I ran the tests, even though I could see the app loading everything else when cuc ran.
If anyone is working with Rails Engines and is using cuc and rspec for testing, I would be interested to hear your setup.