title: Rspec testing a before_create hook
body: <p>I'm trying to test the set_random_token method seen below from my model</p>
  
  <pre><code>class Invitation &lt; ActiveRecord::Base
  
        has_and_belongs_to_many :users
  
        validates :name, presence: true, uniqueness: true
        validates :number_of_uses, presence: true, numericality: true
        validates :token, presence: true, uniqueness: true, format: /\A[0-9A-F]+\z/i
        before_create :set_random_token
  
        private
  
        def set_random_token
          random_hex = SecureRandom.hex(8)
          self.token = random_hex
        end
  
      end
  </code></pre>
  
  <p>Here is the piece in my invitation_spec</p>
  
  <pre><code>it 'verifies that the token is set' do
      @invitation = Invitation.new
      @invitation.save
      expect(@invitation.token).not_to be_empty
  end
  </code></pre>
  
  <p>And here is the error I'm getting</p>
  
  <pre><code>  2) Invitation verifies that the token is set
       Failure/Error: expect(@invitation.token).not_to be_empty
         expected  to respond to `empty?`
       # ./spec/models/invitation_spec.rb:37:in `block (2 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>I'm pretty new to Rails, so I apologize if the answer is extremely obvious. </p>