Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add custom error in case user forgets to define name with let #455

Merged
merged 1 commit into from
Feb 13, 2022

Conversation

SteveRedka
Copy link
Contributor

If you declare a name parameter, but forget to define it within it or let group, RSpec will raise undescriptive error. Two things can happen:

  1. Usually it will raise NoMethodError. Which is mostly true, but it's very generic and doesn't say anything about the place where this error happened and how to fix it.
undefined method `blog_id' for #<RSpec::ExampleGroups::ApiTrackers::ApiTrackersIdd::Get::Successful:0x000055e89bf1dab8>
  1. Some variables like id can raise WrongScopeError
`id` 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).

The text of this error is just wrong and sends user on wild goose chase.

This pull request adds custom error to remind user to define the missing variable.

@jtannas
Copy link
Collaborator

jtannas commented Feb 12, 2022

I like it! I've definiely chased that wild goose a couple times and this would've saved a ton of time 🦢
This is also applicable to query parameters with required: true if you feel like extending the PR a bit. If not we can just merge as-is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants