【发布时间】:2016-01-03 10:31:35
【问题描述】:
我正在努力解决 FactoryGirl 的未初始化常量错误
NameError: uninitialized constant Usernotactivated
我的 factory.rb 文件中有以下内容
FactoryGirl.define do
factory :usernotactivated do
name "foonotactiv"
email "foonotactiv@example.com"
password "secretnot"
activated false
end
end
以及我的规范中的以下内容
it "should redirect to activation alert when it signs me in with an inactivated account" do
user = FactoryGirl.build(:usernotactivated)
visit login_path
fill_in 'Email', :with => usernotactivated.email
fill_in 'Password', :with => usernotactivated.password
click_button 'Sign in'
expect(page).to have_content 'your account is not activated'
end
在两个文件 rails_helper.rb 和 spec_helper.rb 我都添加了这些行:
require 'factory_girl_rails'
我也试过
require 'factory_girl'
不知何故,我将“usernotactivated”更改为“user”我没有收到此未初始化的常量错误,但我不确定是否是因为“user”可能是受保护的名称。谁能给我提示我应该在哪里调查这个问题?您能否告诉我 rails_helper 文件(我在所有规范中都需要)和 spec_helper 文件之间的区别?谢谢。
【问题讨论】:
标签: ruby-on-rails rspec