我应该将 RSpec 匹配器的哪种 gem 与 Mongoid 一起使用?

发布于 2024-10-20 03:19:32 字数 613 浏览 3 评论 0原文

似乎有两个 gem 提供了与 Mongoid 一起使用的 RSpec 匹配器。

哪个是更好的选择,为什么?

MONGOID-RSPEC
Evan Sagge 的 mongoid-rspec gem 为 Mongoid 提供了 RSpec 匹配器。包括关联、选项、验证和字段的匹配器。
http://github.com/evansagge/mongoid-rspec

REMARKABLE-MONGOID
Brian Cardarella 的非凡的 mongoid gem 为 Mongoid 提供了 RSpec 匹配器。它包含仅适用于 Mongoid 的匹配器,以及来自 Remarkable::ActiveModel 的所有验证匹配器。
http://github.com/bcardarella/remarkable_mongoid

It seems there are two gems that provide RSpec matchers to use with Mongoid.

Which is a better choice and why?

MONGOID-RSPEC
Evan Sagge's mongoid-rspec gem provides RSpec matchers for Mongoid. Includes matchers for associations, options, validations, and fields.
http://github.com/evansagge/mongoid-rspec

REMARKABLE-MONGOID
Brian Cardarella's remarkable-mongoid gem provides RSpec matchers for Mongoid. It contains matchers just for Mongoid, plus all validation matchers fromRemarkable::ActiveModel.
http://github.com/bcardarella/remarkable_mongoid

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

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

发布评论

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

评论(2

一向肩并 2024-10-27 03:19:32

就我个人而言,我认为您不应该使用其中任何一个。指定您期望从代码中获得的行为,而不是实现,这样您的规范就会更有意义。

如果您决定从 Mongoid 切换到 MongoMapper 会发生什么?还是回到ActiveRecord?您必须扔掉大部分测试套件并重新编写它。

所有这些库所做的就是指导您进行开发驱动测试,这与 BDD/TDD 完全对立。

Personally, I don't think you should be using either. Specify the behaviour you expect from your code, not the implementation and your specs will be that much more meaningful.

What happens if you decide to switch from Mongoid to MongoMapper? Or back to ActiveRecord? You have to throw out the majority of your test suite and re-write it.

All those libraries do is direct you to do Development-Driven Testing, which is the complete antithesis of BDD/TDD.

聚集的泪 2024-10-27 03:19:32

不幸的是,卓越的 mongoid 的优点也是它的缺点。这个想法是使用 Remarkable ActiveModel 匹配器作为验证器。这需要 Remarkable 4.0 的 alpha 版本。虽然 Remarkable 是一个质量非常高的库,但自去年 6 月以来就没有再被触及过。这是我的库的一个大问题,主要依赖项已经超过 8 个月没有离开 alpha 版了!我联系了几位开发人员,但从未收到任何回复。

至于这两个库哪个更好,快速浏览一下 README 似乎 mongoid-rspec 有更多功能。然而,我从未使用过它,也无法谈论任何使用它的经验。

话虽这么说,说实话(尽管我写了其中一个库),我认为两者都是胡说八道。不幸的是,应该开始这种无用的验证和关联测试方式,每个人都纷纷效仿。 (包括我自己)在几乎所有情况下,编写测试只是编写实际代码的重复工作。你根本就没有真正测试任何东西。最好的情况是可以对它们进行健全性检查。最坏的情况是,它们完全是浪费时间。

我建议在测试套件的不同部分断言行为。

remarkable-mongoid's advantage is also, unfortunately, its disadvantage. The idea was to use the Remarkable ActiveModel matchers for the validators. This requires the alpha version of Remarkable 4.0. While Remarkable is a library of very high quality it also hasn't been touched since last June. This is a huge issue with my library, the main dependency hasn't left alpha in over 8 months! I pinged several of the devs and never heard back from any of them.

As for which of the two libraries is better, a quick look at the README it seems like mongoid-rspec has more features. However, I have never used it and cannot speak about any experience with it.

All this being said, to be perfectly honest (even though I wrote one of the libraries) I think both are pretty bullshit. Unfortunately Shoulda started this useless style of testing of validations and associations and everybody has followed suit. (myself included) In pretty much every case writing the test is just a duplication of effort of writing the actual code. You're not really testing anything at all. At the very best they can be seen a sanity check. At worst they are a complete waste of time.

I suggest asserting the behavior in different parts of the test suite.

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