How to test Rails 3 Engines with Cucumber & Rspec?

前端 未结 3 1637
小鲜肉
小鲜肉 2021-02-01 06:22

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

3条回答
  •  失恋的感觉
    2021-02-01 06:50

    A bit late to the party, but here is my strategy:

    1. Generating the rails plugin in 3.2:

      rails plugin new blog --mountable --full
      

      This creates test/dummy, containing the dummy rails app

    2. Add the specs to spec

    3. Move the dummy folder to spec (and optionally get rid of the other testfiles)

    4. Adapt specs/spec_helper.rb so it includes

      require File.expand_path("../.../config/environment", __FILE__)
      

      instead of

      require File.expand_path("../dummy/config/environment", __FILE__)
      
    5. Execute rails g cucumber:install. It will generate features folder a.o.

    6. Add

      ENV["RAILS_ROOT"] ||= File.expand_path(File.dirname(__FILE__) + '/../../spec/dummy')
      

      before

      require 'cucumber/rails'
      

      in features/support/env.rb

    Now you have features and spec in the root of you project, while the dummy rails app is neatly tucked away under spec/dummy

提交回复
热议问题