Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed : “NameError: constant Object::User not defined” error message when you run the single spec file #58

Merged
merged 1 commit into from
May 16, 2017

Conversation

shozawa
Copy link
Contributor

@shozawa shozawa commented Apr 29, 2017

Symptoms

I ran the single file test

rspec spec/controllers/controller_spec.rb

And got the error below:

NameError:
  constant Object::User not defined

# ./lib/sorcery/test_helpers/internal.rb:70:in `remove_const'
# ./lib/sorcery/test_helpers/internal.rb:70:in `reload_user_class'
# ./lib/sorcery/test_helpers/internal/rails.rb:14:in `sorcery_reload!'
# ./spec/controllers/controller_http_basic_auth_spec.rb:8:in `block (3 levels) in <top (required)>'

Cause

If you call remove_const before the first constant reference, a name error occurs.
Because constant autoloading in Rails is implemented with Module#const_missing.

Resolution

I Changed reload_user_class to refer ‘User’ constant before reload.

@chhlga
Copy link
Contributor

chhlga commented May 3, 2017

Good catch! I've tested and got same behaviour. Solution looks correct and oblivious. lgtm

@Ch4s3 Ch4s3 merged commit c4ebcd2 into Sorcery:master May 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants