我对Cucumber并不陌生,并且在这种情况的最后一步遇到了麻烦:
Scenario:
Given I am on the sign up page
When I create an account
Then a new list should be created for my account at the same time
我的模特:
User has_one :list, dependent: :destroy
List belongs_to :user
我的步骤定义(第3步没有任何内容)
Given(/^I am on the sign up page$/) do
visit new_user_registration_path
end
When(/^I create an account$/) do
fill_in 'Username', with: 'Test'
fill_in 'Email', with: '[email protected]'
fill_in 'Password', with: 'abc12345'
fill_in 'Password confirmation', with: 'abc12345'
click_button 'Submit sign up'
end
Then(/^a new list should be created for me at the same time$/) do
pending
end
我的步骤定义应该如何寻找最后一步?我基本上只是想确保在创建新用户之后,同时创建其关联的列表。
我看过pickle gem,但是我还是很新,也不确定在pickle_steps.rb文件中是否有相关的步骤。
谢谢!
所以我把这个贴到了r / bdd上,有人的评论给了我一个尤里卡的时刻:
使用Cucumber,我不应该使用与程序的如此精细的级别相关的步骤。当前的场景是通过开发者的眼光看待应用程序,而应该通过用户的眼光看待它。
这是使用更好观点的重写:
Scenario:
Given I am on the sign up page
When I create an account
Then I should be able to visit my list page
黄瓜只应关注是否我能到达那里。此时最好将其放到RSpec之类的东西中,以弄清楚我如何到达那里的细节(即对象在做什么而不是它们的行为)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句