0

I am trying to include a custom module into an RSpec test. However, I keep getting errors telling me it can't find my module, it says NameError: uninitialized constant AuthHelper.

I have been trying to follow this https://stackoverflow.com/a/68669816/5568244

I didn't know where to put the the module so I created a folder called specs/support/ and a file called auth_helper.rb in it and put module AuthHelper ...etc... end in that

I have tried simply including it in the test

spec/requests/topics_specs.rb

require 'rails_helper'
include AuthHelper

which i expected to be able to just automatically find the module in the support folder but it didn't. Should it? Does RSpec look in specific places?

I also tried to set up the rails_helper.rb file to include it

RSpec.configure do |config|
  config.include(AuthHelper, :type => :request) 
end

This still didn't work.

What am i missing? How should this work?

  • Rails/RSpec doesn't autoload the `spec/support` dir, so you need to require it in your `RSpec.configure` first: `require './spec/support/auth_helper'` – TonyArra Apr 21 '22 at 13:24
  • I have added it in spec-helper.rb but i am getting: `NoMethodError: undefined method \`get_auth' for #` – George Freeman Apr 25 '22 at 08:58
  • In that case, you likely need to use `config.extend(AuthHelper, :type => :request)` since it sounds like you're trying to use your helper methods outside of the examples. – TonyArra Apr 25 '22 at 13:02

0 Answers0