简体   繁体   English

RSpec:在spec_helper.rb中包含一个自定义帮助程序模块

[英]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.

相关问题 RSpec - 找不到spec / spec_helper.rb - RSpec - Can't find spec/spec_helper.rb 如何将“config.include FactoryBot::Syntax::Methods”添加到 spec_helper.rb 中的 rspec 配置块? - How to add "config.include FactoryBot::Syntax::Methods" to rspec config block in spec_helper.rb? 如何在spec_helper.rb中指定自定义格式化程序? - How do I specify a custom formatter in spec_helper.rb? rspec首先运行哪个? spec_helper.rb或db:test:prepare - Which one does rspec run first? spec_helper.rb or db:test:prepare 无法从Rspec spec_helper.rb文件加载种子数据 - Unable to load seed data from Rspec spec_helper.rb file spec/rails_helper.rb 与 spec/spec_helper.rb 有何不同? 我需要吗? - How is spec/rails_helper.rb different from spec/spec_helper.rb? Do I need it? 在spec_helper.rb中进行哪些更改以运行我的规格? - what changes to be made in spec_helper.rb to run my specs? spec_helper.rb中的“警告:已经初始化的常数” - “warning: already initialized constant” in spec_helper.rb 困惑 - spec_helper.rb:94:在` <top (required)> &#39;:未初始化的常量Shoulda(NameError) - Confused - spec_helper.rb:94:in `<top (required)>': uninitialized constant Shoulda (NameError) 如何在spec_helper.rb中为Capybara Webkit设置ignore_ssl_errors选项 - How to set the ignore_ssl_errors option for Capybara Webkit in spec_helper.rb
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM