RSpec:描述、上下文、特征、场景? [英] RSpec: describe, context, feature, scenario?

查看:54
本文介绍了RSpec:描述、上下文、特征、场景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

describecontextfeaturescenario:这四种和我什么时候使用每个?

describe, context, feature, scenario: What is the difference(s) among the four and when do I use each one?

推荐答案

contextdescribe 的别名,因此它们在功能上是等效的.您可以互换使用它们,唯一的区别是您的规范文件的读取方式.例如,测试输出没有区别.RSpec 书说:

The context is an alias for describe, so they are functionally equivalent. You can use them interchangeably, the only difference is how your spec file reads. There is no difference in test output for example. The RSpec book says:

我们倾向于使用 describe() 表示事物,使用 context() 表示上下文".

"We tend to use describe() for things and context() for context".

我个人喜欢使用describe,但我明白为什么人们更喜欢context.

Personally I like to use describe, but I can see why people prefer context.

featurescenario 是 Capybara 的一部分,而不是 RSpec,旨在用于验收测试.feature相当于describe/contextscenario相当于it/<代码>示例.

feature and scenario are a part of Capybara, and not RSpec, and are meant to be used for acceptance tests. feature is equivalent to describe / context, and scenario equivalent to it / example.

如果您使用 Capybara 编写验收测试,请使用 feature/scenario 语法,如果不使用 describe/it 语法.

If you're writing acceptance tests with Capybara, use the feature / scenario syntax, if not use describe / it syntax.

这篇关于RSpec:描述、上下文、特征、场景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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