1

我对 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: 'test@example.com'
  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 文件中是否有相关步骤。

谢谢!

4

1 回答 1

1

所以我把这个发布到 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 之类的东西中来计算我如何到达那里的细节(即对象在做什么而不是它们的行为方式)。

于 2013-10-19T17:44:42.070 回答