nsarno / knock

Seamless JWT authentication for Rails API
MIT License
2.07k stars 253 forks source link

Rspec test - uninitialized constant Knock::AuthToken #121

Open adonespitogo opened 7 years ago

adonespitogo commented 7 years ago

I'm trying to create a helper for test authentication. But I get the error below. Debugger shows Knock only has Engine constant and no AuthToken

[1, 10] in /home/adones/Projects/Rails/unsakini/spec/support/auth_helper.rb
    1: 
    2: module AuthHelper
    3: 
    4:   def auth_headers(user)
    5:      debugger
=>  6:     token = Knock::AuthToken.new(payload: { sub: user.id }).token
    7: 
    8:     {
    9:       'Authorization': "Bearer #{token}"
   10:     }
(byebug) Knock.constants
[:Engine]
(byebug) 
(byebug) Knock::AuthToken
*** NameError Exception: uninitialized constant Knock::AuthToken

nil
(byebug)
aalvrz commented 7 years ago

You probably need to configure it in rails_helper.rb:

require 'support/auth_helper'

# ...

config.include AuthHelper