关于黄瓜/泡菜的问题

发布于 2024-08-19 06:19:07 字数 1422 浏览 7 评论 0原文

我正在尝试进一步熟悉 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

携君以终年 2024-08-26 06:19:07

您的估计类可能如下所示:

class Estimate ...
  belongs_to :task
end 

它将推断表名称和 fk,并假设您一直遵循 Rails 数据库习惯用法,那么它应该可以正常工作。

至于你的 cuke 步骤,我从未使用过 pickle,所以我不确定这是怎么回事,但如果失败的步骤是:

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

它可能与我上面概述的更改有关(也许它正在做表名有什么奇怪的吗??)。

Your estimate class can look like this:

class Estimate ...
  belongs_to :task
end 

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:

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

It might be to related to the change I've outlined above (maybe it's doing something weird with the table name??).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文