mikker / passwordless

🗝 Authentication for your Rails app without the icky-ness of passwords
MIT License
1.26k stars 87 forks source link

LoadError: cannot load such file -- passwordless/test_helpers #93

Closed amirasaad closed 3 years ago

amirasaad commented 3 years ago

I got this issue while running rspec

rails_helper.rb:

require 'spec_helper'

ENV['RAILS_ENV'] ||= 'test'

require File.expand_path('../config/environment', __dir__)

# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'rspec/rails'
require "passwordless/test_helpers"
rickychilcott commented 3 years ago

I don't think @mikker got a chance to cut a copy of the latest gem with the password helpers. Until he gets a chance to do that,

gem 'passwordless', git: "https://github.com/mikker/passwordless.git", branch: "master" should be in your Gemfile and it will work.

amirasaad commented 3 years ago

Thanks for the prompt response I will try that

amirasaad commented 3 years ago

Sorry for disturbing I added the gem as above but got this error, should I also include the helper?


  1) User can create a post after login can create post
     Failure/Error: passwordless_sign_in @user

     NoMethodError:
       undefined method `passwordless_sign_in' for #<RSpec::ExampleGroups::UserCanCreateAPostAfterLogin:0x000055934ff2c190>
     # ./spec/features/posts_spec.rb:7:in `block (2 levels) in <main>'
rickychilcott commented 3 years ago

https://github.com/mikker/passwordless/blob/master/lib/passwordless/test_helpers.rb#L39-L41 includes it for feature specs if they are tagged tests. Are you using explicit or inferred spec tags?

What happens if you add the following to your rspec config?

config.include ::Passwordless::TestHelpers::SystemTestCase

amirasaad commented 3 years ago

It works thanks, should it be mentioned in docs?

mikker commented 3 years ago

Nah, I should rather get my act together and get a release out 😊

Thanks for helping out @rickychilcott!

rickychilcott commented 3 years ago

I don't think the gem dependency should be documented, but I wonder about the test helpers only being available in certain spec types

@amirasaad -- Check out https://relishapp.com/rspec/rspec-rails/docs/directory-structure and specifically the config.infer_spec_type_from_file_location! option.

It's not on by default, I don't think, but it's really helpful to limit dependencies. If you look at https://github.com/mikker/passwordless/blob/master/lib/passwordless/test_helpers.rb, you can see that have different behavior for the same method depending on whether it's a controller test or a feature test. So it kinda depends on what you want.

I could see us adding mention of our reliance on test metadata (and this issue). Mind taking a stab at a doc PR @amirasaad?

amirasaad commented 3 years ago

I could see us adding mention of our reliance on test metadata (and this issue). Mind taking a stab at a doc PR @amirasaad?

@rickychilcott not at all

amirasaad commented 3 years ago

Yeah, what wasn't obvious for me that I noticed config.include ::Passwordless::TestHelpers::SystemTestCase is included as a system in https://github.com/mikker/passwordless/blob/master/lib/passwordless/test_helpers.rb but I had to include it again Thanks for the clarification @rickychilcott

arrowcircle commented 2 years ago

Any plans on releasing new version to rubygems? Without this it's hard to use passwordless in integration tests.

arronmabrey commented 2 years ago

Just trying this gem out and hitting this same issue