包括助手不起作用 [英] Include helper not works
本文介绍了包括助手不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正尝试在测试中包括一些帮助程序,但我无法使其正常运行. 我收到以下错误:
I'm trying to include some helpers to my test but I can't make that it works. I got the following error:
/home/edu/.rvm/rubies/ruby-1.9.3-p392/bin/ruby -S rspec ./spec/features/customers_spec.rb ./spec/features/login_spec.rb ./spec/features/products_spec.rb ./spec/features/suppliers_spec.rb
/home/edu/Desktop/rails_proyects/gg/spec/support/features.rb:2:in `block in <top (required)>': uninitialized constant MyHelp (NameError)
from /home/edu/.rvm/gems/ruby-1.9.3-p392@gg/gems/rspec-core-2.14.6/lib/rspec/core.rb:120:in `configure'
from /home/edu/Desktop/rails_proyects/gg/spec/support/features.rb:1:in `<top (required)>'
我有这个:
# spec/support/features/session_helper.rb
module MyHelp
module SessionHelpers
...
def sign_in
...
end
end
end
# spec/support/features.rb
RSpec.configure do |config|
config.include MyHelp::SessionHelpers, type: :feature
end
我在这里使用它:
# spec/features/login_spec.rb
require 'spec_helper'
feature "Login" do
scenario "with valid credentials" do
user = create(:user)
sign_in user.email, user.password
page.should have_content(I18n.t('layouts.header.exit', locale: 'es'))
end
end
我正在使用:
rspec (2.14.1)
rspec-core (2.14.6, 2.14.5)
rspec-expectations (2.14.3, 2.14.2)
rspec-mocks (2.14.4, 2.14.3)
rspec-rails (2.14.0)
ruby 1.9.3p392
rails 3.2.13
有人可以帮我吗? 谢谢.
Can someone help me with this? thank you.
推荐答案
在您尝试在spec/support/features.rb
require Rails.root.join('spec/support/features/session_helper')
此外,最好的做法是让您的类/模块与文件名匹配,因此文件应该是复数形式,或者助手是单数形式.
Also, it's best practice to have your class/module match the file name, so either the file should be pluralized, or the helper singularized.
这篇关于包括助手不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文