A blog about the problems I've encountered while being a Ruby on Rails developer, and how I've solved them.
Showing posts with label Controller Spec. Show all posts
Showing posts with label Controller Spec. Show all posts
Monday, March 9, 2015
Testing with a Dummy Controller in a Rails Engine
If you have a controller in your dummy app (spec/dummy/app/controllers/dummy_controller.rb) for your Rails engine, you might need to access the list of routes within your spec code. You can do this, surprisingly, with Rails.application.routes.routes!
Thursday, February 19, 2015
Using self.included to Include Dependencies
As part of a project I'm working on, I created a mountable engine for extracting all authentication concerns for the app. I created a TestHelper module that includes methods for mocking various aspects required for authentication. These methods require Devise::TestHelpers to function properly, and my goal was for the calling app to not know or care about this dependency. To solve this, I used self.included to automatically include the helper when necessary (in my case, only in controller specs).
Here is the code:
Here is the code:
def self.included(receiver)
if defined?(receiver.metadata) && receiver.metadata[:type] == :controller
receiver.send :include, Devise::TestHelpers
end
end
Subscribe to:
Posts (Atom)