我正在尝试在所有功能测试中包含自定义帮助程序模块。我尝试在spec_helper.rb中创建模块,但是我收到以下错误:
uninitialized constant FeatureHelper (NameError)
这是我目前的spec_helper.rb:
# 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
...
...
(错误来自第23行config.include FeatureHelper, type: :feature
)
为什么我的FeatureHelper
模块未被检测到,我该怎么做才能确保它?
答案 0 :(得分:9)
您定义的模块与您尝试包含的模块不匹配。
您拥有名为FeautreHelper
的模块,但正在尝试包含FeatureHelper
。请注意,模块名称中存在拼写错误 - u
位于错误的位置。
应该重命名该模块:
module FeatureHelper
def login
shop = create(:shop)
user = create(:user)
login_as user, scope: :user
user
end
end