Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在Rspec中配置登录帮助程序_Ruby On Rails_Rspec_Capybara - Fatal编程技术网

Ruby on rails 在Rspec中配置登录帮助程序

Ruby on rails 在Rspec中配置登录帮助程序,ruby-on-rails,rspec,capybara,Ruby On Rails,Rspec,Capybara,我正在创建一个助手登录到我的Rspec测试 在我的spec_helper.rb上,我有: RSpec.configure do |config| #adding a login method for all tests config.include Helpers::Authentication, type: :feature end 在我的文件夹->spec/support/helpers/authentication.rb中 module Helpers module

我正在创建一个助手登录到我的Rspec测试

在我的spec_helper.rb上,我有:

 RSpec.configure do |config|
   #adding a login method for all tests
   config.include Helpers::Authentication, type: :feature
 end
在我的文件夹->spec/support/helpers/authentication.rb中

module Helpers
  module Authentication
    def sign_in_as(user)
       visit 'spud/user_session/new'
       fill_in 'Login', with: ''
       fill_in 'Password', with: ''
       click_on 'Login'
    end
  end
end
当我运行rspec时,会出现以下错误:

spec_helper.rb:46:in `block in <top (required)>': uninitialized constant Helpers (NameError)
spec\u helper.rb:46:in'block-in':未初始化的常量helper(NameError)
第46行正好是“config.include Helpers::Authentication,type::feature”


我错过了什么

问题是我添加了

RSpec.configure do |config|
   #adding a login method for all tests
   config.include Helpers::Authentication, type: :feature
 end
在spec_helper.rb上


我刚刚将其更改为文件rails_helper.rb,它可以工作

在哪里/如何加载该helper文件?我没有得到答案Sergio。spec_helper.rb位于Rspec通过defaultNo创建的spec文件夹中。不,我指的是auth helper。仅仅把代码放进某个文件不会有多大作用。必须加载该文件才能使新模块可用。噢。好啊我猜spec文件夹中的所有内容都已加载。如何将spec/support/helpers文件夹添加到配置中?通常,人们会在spec\u helper/rails\u helper的顶部附近放置类似的内容:
Dir[rails.root.join('spec/support/***.rb')。每个{f |都需要依赖性f}
。这将加载规范/支持的所有内容。