tl;dr: Upgrade the gem to at least 4.0.1
When you use rspec_rails
in a version < 4 with Rails 6.1 you may encounter an error like this:
Failure/Error:
raise WrongScopeError,
"`#{name}` is not available from within an example (e.g. an " \
"`it` block) or from constructs that run in the scope of an " \
"example (e.g. `before`, `let`, etc). It is only available " \
"on an example group (e.g. a `describe` or `context` block)."
`name` is not available from within an example (e.g. an `it` block) or from constructs that run in the scope
of an example (e.g. `before`, `let`, etc). It is only available on an example group (e.g. a `describe` or `context` block).
I only ran this spec, so I first thought it could be the name
of my Actor
model.
RSpec.describe Actor do
it 'is valid with a name and birthday' do
actor = Actor.new(name: 'Christian Bale', birthday: '31-12-2000')
expect(actor).to be_valid
end
end
But the error came from rspec_rails
itself. I found this
issue
Show archive.org snapshot
on GitHub, which is solved in rspec_rails
4.0.1.
After an upgrade, the error was gone.
Posted by Florian Leinsinger to makandra dev (2021-02-23 08:52)