我尝试运行测试
describe "CreateFolders" do
describe "GET /projects" do
it "new folder", :js => true do
@user = FactoryGirl.create(:user)
visit projects_path
fill_in('user_Login', :with => @user.email)
fill_in('user_password', :with => @user.password)
click_button('Sign in')
page.should have_content('Logged in')
end
end
我看到了
Failures:
1) CreateFolders GET /projects new folder
Failure/Error: page.should have_content('Logged in')
expected there to be content "Logged in" in "Invalid email or password.\nSign in\nRemember me\nForgot your password?"
# ./spec/requests/create_folders_spec.rb:17:in `block (3 levels) in <top (required)>'
=============================================== =============================== 修订版
FactoryGirl.define do
factory :user do
email Faker::Internet.free_email
password 'password'
Name Faker::Name.first_name
Surname Faker::Name.last_name
Phone Faker::PhoneNumber.phone_number
Login Faker::Name.first_name
company {|user| user.association(:company) }
end
end
答案 0 :(得分:2)
在rails中,有三个数据库集:development db,test db&amp;生产数据库, 您可能正在开发数据库中创建新用户,它应该在测试数据库中创建,因为在您进行测试时,将使用测试数据库。
确保在测试数据库中创建了新用户。
如果您只需要访问需要身份验证的网页,而无需测试登录表单,则可以在Capybara中轻松完成此操作:https://github.com/plataformatec/devise/wiki/How-To:-Test-with-Capybara
我希望这会有所帮助!
答案 1 :(得分:0)
我假设您正在使用Capybara进行测试。尝试将fill_in
更改为标签名称而不是字段名称。例如:
fill_in "Login", :with => @user.email
fill_in "Password", :with => @user.password
这些可能与您的应用不同 - 只需替换您实际调用的字段标签(无论您在转到projects_path时在屏幕上看到什么)。此外,不需要括号。
答案 2 :(得分:-2)
你应该使用黄瓜来实现这个目标
@javascript
Scenario Outline: Show or not dasboard
Given the following user records
| email | password | login |
| admin@mail.com | password | admin |
When I am on the home page
And I fill in "user_email" with "<login>"
And I fill in "user_password" with "<password>"
And I press "Sign in"
Then I should <flash>
Examples:
| login | password | flash |
| admin@mail.com | password | see "Signed in successfully." |