RSpec:在spec_helper.rb中包含一个自定义帮助程序模块 [英] RSpec: Include a custom helper module in spec_helper.rb
问题描述
我正在尝试在所有功能测试中包含自定义帮助程序模块。我尝试在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)
这是我的spec_helper.rb,因为它现在是:
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
...
...
(错误来自第23行 config.include FeatureHelper,键入::feature
)
( The error is from line 23 config.include FeatureHelper, type: :feature
)
为什么我的 FeatureHelper
模块没有被检测到,我该怎么做才能确保它被检测到?> p>
Why is my FeatureHelper
module not being detected, and what can I do to ensure that it is?
推荐答案
您定义的模块与您要包含的模块不匹配。
The module you defined does not match that which you are trying to include.
您有一个名为 FeautreHelper
的模块,但是试图包含 FeatureHelper
。请注意,模块名称中有一个错字- u
的位置错误。
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.
模块应该被重命名:
module FeatureHelper
def login
shop = create(:shop)
user = create(:user)
login_as user, scope: :user
user
end
end
这篇关于RSpec:在spec_helper.rb中包含一个自定义帮助程序模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!