19 May 2015

Rspec - How to test a controller has included concerns

<p>A short Rspec snippet to verify the correct concerns have been included in a controller.</p>

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

© 2026 Michael Cho