0
votes

Im creating a helper login to my Rspec tests.

On my spec_helper.rb I have:

 RSpec.configure do |config|
   #adding a login method for all tests
   config.include Helpers::Authentication, type: :feature
 end

And in my folder -> spec/support/helpers/authentication.rb

module Helpers
  module Authentication
    def sign_in_as(user)
       visit 'spud/user_session/new'
       fill_in 'Login', with: ''
       fill_in 'Password', with: ''
       click_on 'Login'
    end
  end
end

When I run rspec it gives me this error:

spec_helper.rb:46:in `block in <top (required)>': uninitialized constant Helpers (NameError)

The line 46 its exactly the "config.include Helpers::Authentication, type: :feature"

What Im missing here?

1
Where/how do you load that helper file?Sergio Tulentsev
I dont get the answer Sergio. The spec_helper.rb is inside the spec folder created by Rspec by defaultFernando Maymone
No-no, I meant the auth helper. Just putting code in some file won't do much. Something has to load that file, to make the new module available.Sergio Tulentsev
Oh. Ok. I guess that everything that was inside the spec folder were loaded. How can I add the spec/support/helpers folders to the config?Fernando Maymone
Normally, people put something like this somewhere near the top of their spec_helper/rails_helper: Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require_dependency f }. This loads everything from spec/support.Sergio Tulentsev

1 Answers

0
votes

The problem is that I was adding the

RSpec.configure do |config|
   #adding a login method for all tests
   config.include Helpers::Authentication, type: :feature
 end

on the spec_helper.rb

I just changed it to the file rails_helper.rb and it works