从无到有:如何删除“帖子”? (即先测试)

发布于 2024-09-30 12:32:37 字数 246 浏览 3 评论 0原文

有人愿意分享他们使用 Cucumber 并从空的 Rails 应用程序开始的 BDD/TDD 方法的工作流程吗?我正在尝试学习如何构建我的设计方法,以便首先通过黄瓜编写测试。

一个示例场景:

Post 模型有一个标题和一个正文——没有关系或任何花哨的东西,是通过 Rails 生成脚本生成的。

我希望得到一个答案,可以为那些刚接触测试(又名 ME)并且不确定先编写测试然后编码时采取哪些步骤的人提供启发。

谢谢。

Would anyone care to share their workflow for a BDD/TDD approach using Cucumber and starting with an empty rails app? I am trying to learn how to pattern my design approach for writing tests first via cucumber.

An example scenario:

A Post model has a title and a body -- no relationships or anything fancy and is generated via the rails generate script.

What i'm hoping for is an answer that might shed light for people who are new to testing (aka ME) and not sure what steps one takes when writing a test first, then coding.

thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

两相知 2024-10-07 12:32:37

我对 Ruby 还很陌生,所以请原谅任何听起来像 C# 或 Java 的东西。

首先,不要使用 TDD Rails。 Rails 已经具有非常好的测试覆盖率。您可以假设它有效。如果使用 Rails 为您提供了您所需要的网站,那么恭喜您!你完成了。

否则,我会开始为您希望有所不同的行为编写场景(使用 Cucumber),首先关注最有价值的行为。 这是我写的一篇博客文章,它可能会帮助您想象如何有效。

一旦你有了一个描述一些不存在的行为的场景,你就可以开始进行 TDD(使用 RSpec),首先创建网页,然后从最接近页面的外部层开始工作,从控制器开始并分解协作类,如以及何时需要它们。一旦您的场景和单元测试通过,就开始进行下一件它不做和应该做的事情。

希望这有帮助!从您给出的“帖子”示例中我知道您可能已经完成了;但是,我怀疑您还想用它做更多的事情。为此写一个场景,祝你好运!

I'm fairly new to Ruby, so please forgive anything which sounds C# or Java-esque.

First off, don't TDD Rails. Rails already has perfectly good test coverage. You can assume that it works. If using Rails gives you exactly the website that you need, congrats! You're done.

Otherwise, I'd start writing scenarios (with Cucumber) for the behaviour that you would like to be different, focusing on the most valuable behaviour first. Here's a blog post I wrote which might help you imagine how that works.

Once you have a scenario which describes some non-existent behaviour, you can start doing TDD (with RSpec), creating the web page first, then working from the outside layers closest to the page, starting with the controller and breaking out collaborating classes as and when they're needed. Once your scenario and your unit-tests pass, move onto the next thing that it doesn't do and should.

Hope this helps! I know from the example you give with "Posts" you're probably done already; however, I suspect that there's something more you want to do with it. Write a scenario for that, and good luck!

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