我目前正在尝试学习黄瓜以及如何正确使用黄瓜.在搜索最佳实践时,描述了大多数旧方法,我还没有真正找到一个好的指南.
我读到了关于这种方法的新方法,但我对最佳实践存在一些问题.
我读到了关于这种方法的新方法,但我对最佳实践存在一些问题.
以下是我一直在研究的一些基本黄瓜方案.
@H_403_5@Scenario: Unsuccessful login Given a user has an account When the user tries to log in with invalid information Then the user should see an log in error message Scenario: Successful login Given a user has an account When the user logs in Then the user should see an log in success message And the user should see a sign out link Scenario: Successful logout Given a signed in user Then the user logs out And the user should see an log out success message我想知道这是否可以?我有问题,如果我应该把它写成“我访问”或“用户访问”或“他访问”基本上什么是首选?
其次,我想知道我应该如何制定以下内容:
@H_403_5@Scenario: Visit profile of user Given a user And a second user When the user visit the user profile Then the user should see the name of the user Scenario: Visit profile of another user Given a user And a second user When the user visit the second users profile Then the user should see the name of the second user这只是我放在一起的东西,但我觉得这不是最好的方法.
我在步骤定义文件中遇到问题.您将如何定义处理方案的步骤?我想写一些更通用的东西,但也许它真的不可能?我应该有@second_user属性还是你建议的?
谢谢你的协助!
解决方法
I have problems if I should write it as “I visit” or “the user visit” or “he visit” Basically what is preferred?
我认为使用“当用户访问时”这样的内容会更通用,并且更具可读性,因为您不必继续思考“谁是’他’?”如果您正在阅读测试,那么真正重要的是您在所有文件中坚持一些约定,这样您就不会感到困惑.
关于创建@second_user的第二个问题,我认为你不应该这样做,因为这个用户并不完全是你的场景的一部分,因为它是一个数据设置,我认为处理数据设置的最好方法是使用pickle with cucumber,它基本上允许你在你的黄瓜中创建模型,而不必将它们作为变量保存,有一个great cast on RailsCast可以解释很多.
所以我会用泡菜做这个
@H_403_5@Scenario: Visit profile of another user Given a user exists with name: "Mike",username: "mike" And a signed in user When the user visits the profile of "mike" Then the user should see 'Mike'然后你可以定义
@H_403_5@When /^the user visits the profile of (.+)$/ do |username| visit("/#{username}") # I am assuming here usernames are unique and the profile url is "/:username" end