How do I write a Rails 3.1 engine controller test in rspec?

后端 未结 7 2003
北荒
北荒 2020-12-02 12:37

I have written a Rails 3.1 engine with the namespace Posts. Hence, my controllers are found in app/controllers/posts/, my models in app/models/posts, etc. I can test the mod

相关标签:
7条回答
  • 2020-12-02 13:06

    It was already mentioned about adding routes { MyEngine::Engine.routes }, although it's possible to specify this for all controller tests:

    # spec/support/test_helpers/controller_routes.rb
    module TestHelpers
      module ControllerRoutes
        extend ActiveSupport::Concern
    
        included do
          routes { MyEngine::Engine.routes }
        end
    
      end
    end
    
    

    and use in rails_helper.rb:

    RSpec.configure do |config|
      config.include TestHelpers::ControllerRoutes, type: :controller
    end
    
    0 讨论(0)
提交回复
热议问题