如何分解 RSpec 中的超长规格?

编程入门 行业动态 更新时间:2024-10-21 23:18:07
本文介绍了如何分解 RSpec 中的超长规格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

有没有一种方法可以将模型的规格分解为某种层次结构?我们的几个模型的规格已经超过 5000 行,这降低了它们的可维护性.

Is there a way in which you can break specs up for a model into some sort of hierarchy? The specs for a couple of our models have gone over 5000 lines and this is reducing their maintainability.

我知道在理想的世界中,模型不会复杂到需要这种规模的测试,但这些模型实际上是 Python 科学库(Series 和 DataFrame)中 Pandas 对象的 Ruby 实现,因此不幸的是,我们受到了这一点的约束.

I know that in an ideal world models would not be complex enough to require tests of this size, but these models effectively are Ruby implementations of pandas objects from Python scientific libraries (Series and DataFrame) so we are unfortunately bound by this.

我希望能够通过逻辑操作拆分测试.这可能吗?理想情况下,我还希望使用单个命令运行模型的所有规范.

I would like to be able to split the tests up by logical operations. Is this possible? I would ideally also like to run all the specs for a model with a single command.

推荐答案

这当然是可能的.我从来不需要随意分解模型规范,因为我总是能够分解模型然后测试各个部分,但例如,我经常不得不分解验收规范.

It is certainly possible. I've never had to arbitrarily break up a model spec, because I've always been able to break up the model and then test the pieces, but I've often had to break up acceptance specs, for example.

如果你的 Series 类有一堆关于算术的方法、一堆关于棒球的方法、一堆关于电视的方法和一堆关于布线的方法,你可以像这样分解规范

If your Series class had a bunch of methods about arithmetic, a bunch about baseball, a bunch about television and a bunch about wiring, you could break up the specs like so

spec/models/series/
  arithmetic_spec.rb
  baseball_spec.rb
  television_spec.rb
  wiring_spec.rb

并使用

rspec spec/models/series

这篇关于如何分解 RSpec 中的超长规格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 07:40:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1405908.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分解   规格   RSpec

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!