RSpec: describe, context, feature, scenario?

前端 未结 3 1879
广开言路
广开言路 2020-12-22 21:04

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

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-22 21:25

    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:

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

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

    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.

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

提交回复
热议问题