title: Ruby on Rails: How to do a spec test for a policy
body: <p>I'm using Rails 4.2.6 and Ruby 2.3.1</p>
  
  <p>I'm trying to create a spec test for a policy, which is called in my situation base_policy. I need to test if the policies are respected.</p>
  
  <p>My base_policy:</p>
  
  <pre><code>class Study::BasePolicy &lt; ApplicationPolicy
    def default?
      @user.has_edit_access?
    end
  
    def  terminology_toggle?
      @user.has_edit_access?
    end
  end
  </code></pre>
  
  <p>I tried to do the spec but is not working good and giving errors as </p>
  
  <pre><code>Study::BasePolicy for read access allows access
       Failure/Error: let (:base) {Base.new}
  
     NameError:
         uninitialized constant Base
  </code></pre>
  
  <p>My spec file as follows:</p>
  
  <pre><code>require 'rails_helper'
  
  describe Study::BasePolicy do
    include UserAccountHelpers
    include PermissionsHelpers
  
    subject {described_class.new(user, base)}
    let (:base) {Base.new}
  
    before :each do
      ua_create
    end
  
    after :each do
      ua_destroy
    end
  
    context "for read access" do
      let (:user) {@user_r}
  
      it "allows access" do
        allow_list [:detail]
      end
  
      it "deny access" do
        deny_list [:edit, :update, :default, :terminology_toggle]
      end
    end
  
    context "for edit access" do
      let (:user) {@user_e}
  
      it "allows access" do
        allow_list [:edit, :update, :default, :terminology_toggle]
      end
    end
  
    context "for system admin access" do
      let (:user) {@user_sa}
  
      it "allows access" do
        allow_list [:edit, :update, :default, :terminology_toggle]
      end
    end
  end
  </code></pre>
  
  <p>I would like to understand a good way to test this policy as my knowledge in the testing in rails is limited.</p>