Rspec无法加载支持文件

时间:2018-02-20 01:13:58

标签: ruby-on-rails rspec rspec-rails

我无法让rspec加载支持文件,尝试过:

config.include SessionHelper, :type => :controller

在spec_helper文件中,哪个给了我

NameError: uninitialized constant SessionsSpecHelper

添加:

Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }

给我:

NoMethodError: undefined method `join' for nil:NilClass

添加:

require 'support/session_helpers.rb'

没有差异

支持/ session_helper.rb:

module SessionHelpers
def sign_up_with(email, password)
  visit sign_up_path
  fill_in 'Email', with: email
  fill_in 'Password', with: password
  click_button 'Sign up'
end

def sign_in
  user = create(:user)
  visit sign_in_path
  fill_in 'Email', with: user.email
  fill_in 'Password', with: user.password
  click_button 'Sign in'
end
end

1 个答案:

答案 0 :(得分:1)

您是否注意到错误config.include SessionsHelper, :type => :controller 有会话

,而您的模块module SessionHelpers有会话