How to test Rails 3 Engines with Cucumber & Rspec?

Posted by cowboycoded on Stack Overflow See other posts from Stack Overflow or by cowboycoded
Published on 2010-12-07T19:51:26Z Indexed on 2011/01/10 20:54 UTC
Read the original article Hit count: 1161

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:

  1. Add a rails test app to the root of the gem (myengine) by running: rails new /myengine/rails_app

  2. Add Cucumber to /myengine/rails_app/features as you would in a normal Rails app

  3. Require the Rails Engine Gem (using :path=>"/myengine") in /myengine/rails_app/Gemfile

  4. Add spec to the root directory of the gem: /myengine/spec

  5. 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.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby-on-rails3