2010-01-21 94 views
1

我想要更熟悉一些Rails/ActiveRecord。在試圖這樣做時,我試圖使用Cucumber來幫助進行一些「發現」測試。關於Cucumber/Pickle的問題

我有以下

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 

任何人都可以點我在正確的方向(或者,如果我需要發佈更多的代碼)?

感謝,

+0

你能張貼你的步驟/模型請。 – jonnii 2010-01-21 23:06:04

+0

已添加。感謝您的期待 – Joe 2010-01-22 00:28:09

回答

0

你估計類可以是這樣的:

class Estimate ... 
    belongs_to :task 
end 

它會推斷出表名和FK和假設你一直在關注的軌道數據庫成語它應該都可以工作。

至於你的黃瓜的步驟,我從來沒有用過的泡菜,所以我不知道發生了什麼事情與這一點,但如果那是失敗的步驟是:

Then the task "task" should have 3 estimates #this one fails 

這可能是相關的我上面概述的變化(也許它對錶名稱做了一些奇怪的事情)。