← All Articles

Rspec - How to test a controller has included concerns

In Rails 4, developers were encouraged to move shared functionality into concerns and keep controllers as 'clean' as possible.

This is a short snippet to confirm the correct concerns are included in your controller. In this example, the test verifies the CommonRedirects concern is included.

 


describe PagesController do

  describe 'includes the correct concerns' do
    it { expect(controller.class.ancestors.include?(CommonRedirects)).to eq(true) }
  end

  # The rest of the controller test
end

Made with JoyBird