如何分解 RSpec 中的超长规格? [英] How to break down super long specs in RSpec?

查看:27
本文介绍了如何分解 RSpec 中的超长规格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以将模型的规格分解为某种层次结构?我们的几个模型的规格已经超过 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆