【发布时间】:2011-10-16 16:35:36
【问题描述】:
我使用db/seeds.rb 用两个永远不会改变的用户角色(“Admin”、“User”)填充我的数据库。但是,当我运行测试时,种子数据不会被继承,结果是错误测试。
当我尝试运行 cucumber 时,出现以下错误:
使用默认配置文件...功能:登录以获取访问权限 到网站的受保护部分 一个有效的用户应该能够 登录
场景:用户未注册# features/users/sign_in.feature:6 未注册:角色 (参数错误)
/Users/x/.rvm/gems/ruby-1.9.2-p180/gems/factory_girl-2.0.0.rc4/lib/factory_girl/registry.rb:15:infind'factory_by_name'
/Users/x/.rvm/gems/ruby-1.9.2-p180/gems/factory_girl-2.0.0.rc4/lib/factory_girl.rb:39:in
/Users/x/.rvm/gems/ruby-1.9.2-p180/gems/factory_girl-2.0.0.rc4/lib/factory_girl/syntax/vintage.rb:53:indefault_strategy'Factory'
/Users/x/.rvm/gems/ruby-1.9.2-p180/gems/factory_girl-2.0.0.rc4/lib/factory_girl/syntax/vintage.rb:146:in
/Users/x/rails/ply_rails/features/support/db_setup.rb:6:in '之前' 鉴于我没有登录# 特征/step_definitions/user_steps.rb:36
这是我的设置:
# features/support/db_setup.rb
Before do
# Truncates the DB before each Scenario,
# make sure you've added database_cleaner to your Gemfile.
DatabaseCleaner.clean
Factory(:role, :name => 'Admin')
Factory(:role, :name => 'User')
end
# features/users/sign_in.feature
Feature: Sign in
In order to get access to protected sections of the site
A valid user
Should be able to sign in
Scenario: User is not signed up # THIS IS LINE 6
Given I am not logged in
And no user exists with an email of "user@user.com"
When I go to the sign in page
And I sign in as "user@user.com/password"
Then I should see "Invalid email or password."
And I go to the home page
And I should be signed out
# features/step_definitions/user_steps.rb
Given /^I am a "([^"]*)" named "([^"]*)" with an email "([^"]*)" and password "([^"]*)"$/ do |role, name, email, password|
User.new(:name => name,
:email => email,
:role => Role.find_by_name(role.to_s.camelize),
:password => password,
:password_confirmation => password).save!
end
不知道从哪里开始进行这项工作,感谢您的帮助/时间!
【问题讨论】:
标签: ruby-on-rails ruby testing cucumber factory-bot