关于黄瓜/泡菜的问题
我正在尝试进一步熟悉 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
任何人都可以指出我正确的方向(或者如果我需要发布更多代码)吗?
谢谢,
乔
I'm trying to get a little more familiarity with Rails / ActiveRecord. In trying to do so I am attempting to use Cucumber to help with some "discovery" tests.
I have the following
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
EDIT
I have no custom steps - trying to use use what comes out of the box with cucumber and pickle (just to limit my confusion).
The models are
class Estimate < ActiveRecord::Base
belongs_to :Task, :class_name => "Task", :foreign_key => "Task_id"
end
and
class Task < ActiveRecord::Base
has_many :estimates
end
Can anyone point me in the right direction (or if I need to post more code)?
Thanks,
Joe
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的估计类可能如下所示:
它将推断表名称和 fk,并假设您一直遵循 Rails 数据库习惯用法,那么它应该可以正常工作。
至于你的 cuke 步骤,我从未使用过 pickle,所以我不确定这是怎么回事,但如果失败的步骤是:
它可能与我上面概述的更改有关(也许它正在做表名有什么奇怪的吗??)。
Your estimate class can look like this:
It will infer the table name and the fk and assuming you've been following the rails database idioms it should all just work.
As for your cuke steps, I've never used pickle, so I'm not sure what's going on with that, but if the step that's failing is:
It might be to related to the change I've outlined above (maybe it's doing something weird with the table name??).