RSpec: describe, context, feature, scenario?

Mike Glaz picture Mike Glaz · Jul 25, 2012 · Viewed 25.6k times · Source

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

Answer

Sam Peacey picture Sam Peacey · Jul 26, 2012

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.