我正在尝试在我的所有功能测试中包含一个自定义帮助程序模块。我尝试在 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,类型::feature
)
为什么我的 FeatureHelper
模块没有被检测到,我该怎么做才能确保它被检测到?
最佳答案
您定义的模块与您尝试包含的模块不匹配。
您有名为 FeautreHelper
的模块,但正试图包含 FeatureHelper
。请注意,模块名称中有一个拼写错误 - u
在错误的位置。
模块应该重命名:
module FeatureHelper
def login
shop = create(:shop)
user = create(:user)
login_as user, scope: :user
user
end
end
关于ruby-on-rails - RSpec:在 spec_helper.rb 中包含自定义帮助程序模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24382645/