我正在使用Devise进行用户身份验证,并且具有以下失败的Cucumber方案:
Scenario: Log in to the system
Given a user called "test" with a password of "secret"
And I am not logged in # Just visits /users/sign_out
When I go to the log in page
And I fill in "user_username" with "test"
And I fill in "user_password" with "secret"
And I press "Sign in"
Then I should see "Signed in successfully."
如果我在最后粘贴“然后显示页面”,我会显示一个空白登录表单的页面。
以下(非常相似)测试有效:
Scenario: Fail to log in with invalid credentials
Given a user called "test" with a password of "secret"
And I am not logged in
When I go to the log in page
And I fill in "user_username" with "test"
And I fill in "user_password" with "invalid password"
And I press "Sign in"
Then I should see "Invalid email or password."
...所以我假设在成功验证Cucumber没有关注之后登录会进行重定向(当我在浏览器中手动执行时,FWIW所有工作都有效)...任何人都可以告诉我如何通过测试?
谢谢, 灰
编辑:这是失败的最后一步“预期#has_content?(”成功签名。“)返回true,得到错误”错误(...唉...之前应该提到过!)
答案 0 :(得分:1)
是id字段user_username
还是user_email
或其他什么?
当我进入登录页面时,该怎么办?你确定你去那里?
答案 1 :(得分:1)
修正了它!我刚用测试环境加载了我的服务器并重现了问题。
我正在使用带有config.ldap_create_user = true的ldap_authenticatable。在第一次登录时,如果用户帐户不存在(在新擦除的测试数据库中不存在),则会创建该用户帐户,但是这会重定向回登录页面而不是遵循根路由。后续登录执行预期的行为。因此,以下测试通过:
Scenario: Log in to the system
Given a user called "test" with a password of "secret"
And I am not logged in
When I go to the log in page
And I fill in "user_username" with "test"
And I fill in "user_password" with "secret"
And I press "Sign in"
And I fill in "user_username" with "test"
And I fill in "user_password" with "secret"
And I press "Sign in"
Then I should see "Signed in successfully."
非常感谢pjammer的橡皮鸭!