Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RSpec: Include a custom helper module in spec_helper.rb

I am trying to include a custom helper module in all my feature tests. I have tried creating the module in spec_helper.rb, but I get the following error:

uninitialized constant FeatureHelper (NameError)

Here is my spec_helper.rb as it currently is:

# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rspec'
include Warden::Test::Helpers

module FeautreHelper
  def login
    shop = create(:shop)
    user = create(:user)
    login_as user, scope: :user
    user
  end
end

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }

RSpec.configure do |config|
  config.include FactoryGirl::Syntax::Methods
  config.include FeatureHelper, type: :feature
...
...

( The error is from line 23 config.include FeatureHelper, type: :feature )

Why is my FeatureHelper module not being detected, and what can I do to ensure that it is?

like image 616
Marco Prins Avatar asked Jan 27 '26 05:01

Marco Prins


1 Answers

The module you defined does not match that which you are trying to include.

You have the module named FeautreHelper, but are trying to include FeatureHelper. Notice that there is a typo in the module name - the u is in the wrong spot.

The module should be renamed:

module FeatureHelper
  def login
    shop = create(:shop)
    user = create(:user)
    login_as user, scope: :user
    user
  end
end
like image 118
Justin Ko Avatar answered Jan 29 '26 21:01

Justin Ko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!