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: 1295
        
ruby-on-rails
|ruby-on-rails3
|ruby-on-rails-plugins
|ruby-on-rails-gems
|rails-engines
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/featuresas 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/fixturesand 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