我正在尝试更熟悉 Rails / ActiveRecord。在尝试这样做时,我试图使用 Cucumber 来帮助进行一些“发现”测试。
我有以下
Feature: Describing a task
In order to work with tasks
As a user
I want to be able to know what makes up a task and to improve my understanding of ActiveRecord
Scenario: A task has certain core fields
Given the following tasks exist
| id | name |
| 1 | some task |
And the following estimates exist
| task_id | hours | explanation |
| 1 | 8 | initial estimate |
| 1 | 6 | better undertsanding of task |
| 1 | 16 | no control over inputs to create task |
| 2 | 22 | for other task |
Then a task: "task" should exist with name: "some task" #this works
Then the estimate "estimate" should exist with explanation: "initial estimate" #this works
Then the estimate "estimate" should be one of task: "task"'s estimates #this works
Then the task "task" should have 3 estimates #this one fails
编辑
我没有自定义步骤 - 尝试使用开箱即用的黄瓜和泡菜(只是为了限制我的困惑)。
模型是
class Estimate < ActiveRecord::Base
belongs_to :Task, :class_name => "Task", :foreign_key => "Task_id"
end
和
class Task < ActiveRecord::Base
has_many :estimates
end
谁能指出我正确的方向(或者如果我需要发布更多代码)?
谢谢,
乔