[英]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:
我尝试在spec_helper.rb中创建模块,但是我收到以下错误:
uninitialized constant FeatureHelper (NameError)
Here is my spec_helper.rb as it currently is: 这是我的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
...
...
( The error is from line 23 config.include FeatureHelper, type: :feature
) (错误来自第23行
config.include FeatureHelper, type: :feature
)
Why is my FeatureHelper
module not being detected, and what can I do to ensure that it is? 为什么我的
FeatureHelper
模块没有被检测到,我该怎么做才能确保它?
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
. 您有名为
FeautreHelper
的模块,但正在尝试包含FeatureHelper
。 Notice that there is a typo in the module name - the u
is in the wrong spot. 请注意,模块名称中存在拼写错误 -
u
位于错误的位置。
The module should be renamed: 该模块应重命名:
module FeatureHelper
def login
shop = create(:shop)
user = create(:user)
login_as user, scope: :user
user
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.