Module: Clearance::Testing::Matchers

Defined in:
lib/clearance/testing/deny_access_matcher.rb

Overview

Provides matchers to be used in your controller specs. These are typically exposed to your controller specs by requiring clearance/rspec or clearance/test_unit as appropriate in your rails_helper.rb or test_helper.rb files.

Instance Method Summary collapse

Instance Method Details

#deny_access(opts = {}) ⇒ Object

The deny_access matcher is used to assert that a request is denied access by clearance.

Options Hash (opts):

  • :flash (String)

    The expected flash notice message. Defaults to nil, which means the flash will not be checked.

  • :redirect (String)

    The expected redirect url. Defaults to '/' if signed in or the sign_in_url if signed out.

    class PostsController < ActionController::Base
      before_action :require_login
    
      def index
        @posts = Post.all
      end
    end
    
    describe PostsController do
      describe "#index" do
        it "denies access to users not signed in" do
          get :index
    
          expect(controller).to deny_access
        end
      end
    end
    


33
34
35
# File 'lib/clearance/testing/deny_access_matcher.rb', line 33

def deny_access(opts = {})
  DenyAccessMatcher.new(self, opts)
end