Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 910
Allyl Isocyanate Avatar asked Jul 14 '14 23:07

Allyl Isocyanate


2 Answers

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

like image 186
The Brofessor Avatar answered Oct 18 '22 04:10

The Brofessor


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

like image 43
Owen Sims Avatar answered Oct 18 '22 04:10

Owen Sims