1

我有两个模型:具有以下关联的用户汽车:

User has_many Car
Car belongs to User

我正在创建一个用于编辑汽车的功能,这是我目前所拥有的:

Feature: Edit car for a user 
  In order to edit cars of my user
  As a user
  I should be able to edit existing users related to my account

Scenario: User is signed in and edits an education with valid attributes 
  Given I am logged in as a user
  And I have the following cars related to my account
  Then I want to edit a car...

我实施的唯一步骤是这一步:

Given /^I am logged in as a user$/ do
  @user = FactoryGirl.create(:user)
  user_sign_in
end


def user_sign_in
 visit '/users/sign_in'
 fill_in "Email", :with => @user[:email]
 fill_in "Password", :with => @user[:password]
 click_button "Go"
end

我基本上看不到如何创建与该用户关联的汽车,以及如何测试我是否能够编辑其中一辆汽车?

4

1 回答 1

0

然后应该只对 Cucumber 的 wiki 进行输出测试。您应该将其转换为何时。

我是黄瓜的新手,但我认为你应该做这样的事情(黄瓜喜欢精确的例子):

Given I am logged in
And I have "Ferrari" related to my account
When I edit "Ferrari"
Then "Ferrari" should be modified.

或任何其他车型。

在您的给定中,您设置了变量。由于您没有测试您网站的身份验证功能,您可以简单地使用您的 User 类方法登录用户。它会加快你的测试。步骤应如下所示:

鉴于我已登录 - >登录用户

我有...... - > @car = Car.create!(你的参数)

当... -> 这应该修改@car

visit car_edit_path(your car id)
Fill....
Sumbmit

然后 -> 验证 @car 是否被修改

在此期间,您使用模型方法修改汽车,然后验证汽车是否已更改。

于 2012-06-17T03:35:33.073 回答