Allyl Isocyanate
Allyl Isocyanate

Reputation: 13626

RSpec.describe vs describe

I'm starting a new Rails project for the first time in a while. When scaffolding a model, Rspec creates describe blocks predicated with "RSpec"

RSpec.describe MyModel do
  ...
end

vs the old style:

describe MyModel do
  ...
end

I've perused the change log but must be missing the rational for the change?

Upvotes: 35

Views: 5946

Answers (2)

The Brofessor
The Brofessor

Reputation: 2391

As of RSpec 3 you can disable the global availability of describe by limiting the domain specific language (dsl).

Prefixing with RSpec.describe ensures tests will still run after implementing the limitation.

Note: you still don't need the prefix, unless you turn off the availability with config.expose_dsl_globally = false

Edit: link to dsl wikipedia

Upvotes: 36

Owen Sims
Owen Sims

Reputation: 373

Via the commit:

In a concerted effort to keep monkey patching to a minimum. The default Rails spec generators should not use the monkey patched version of describe.

Always using only the non-monkey patched RSpec.describe, instead of inspecting the configuration, has the benefits of:

  • not requiring RSpec to be loaded when the generators are run by Rails
  • not introducing extra logic and state to handle the different states
  • Resolve #1048

https://github.com/rspec/rspec-rails/commit/ca0d249858903949052e06884e8e7f9d596cdc79

Upvotes: 34

Related Questions