有没有办法提供更好的 rspec 测试描述
我已经使用 rspec 一段时间了,最近将样式从
it "should do something cool" do
@something.should work
end
更简洁的样式切换为更简洁的
subject(@something)
it {should work}
样式,虽然在编写测试和在代码中查看它们时我更喜欢更简洁的样式,但我怀念能够为每个测试指定描述的功能,特别是因为相等消息仅显示正在测试的值。因此,在上面的示例中,假设测试通过,使用第一种样式,我会收到一条消息说“它应该做一些很酷的事情”,而第二种样式只会说它已经起作用。
有谁知道有什么方法可以做到这一点?干杯
I have been using rspec for a little while and recently switched style from
it "should do something cool" do
@something.should work
end
to the more concise
subject(@something)
it {should work}
Whilst I much prefer the more concise style when writing the tests and for viewing them in code, I miss being able to specify the description for each test, particularly since the equality messages just display the values that are being tested. So in the example above, assuming the test passes, with the first style, I would get a message saying 'it should do something cool', whereas the second will just say that it has worked.
Does anyone know of a way to do this? Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您对
specify/subject
块的作用有错误的概念。它们并不是要完全替代您所切换的更详细的语法,而是应该在不需要描述时使用。因此,如果您想要描述,只需使用
另外,我个人认为
specify/subject
并不更简洁。对我来说,这距离使用 rspec 读取创建的更像 DSL 的规范方式还有一步之遥,但这可能是个人喜好的问题。I think you got the wrong concept of what the
specify/subject
blocks do. They are not meant to be a complete replacement for the more verbose syntax you switched from, but should be used when there is no need for a desciption.So if you want a desciption, just use
Also, I personally don't think that the
specify/subject
is more concise. For me it's a step away from the more DSL-like way specifications created with rspec read, but that might be a matter of personal preference.