Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Warn about bare raise_error#768

Merged
JonRowe merged 9 commits into
masterfrom
warn_about_bare_raise_error
Apr 16, 2015
Merged

Warn about bare raise_error#768
JonRowe merged 9 commits into
masterfrom
warn_about_bare_raise_error

Conversation

@JonRowe

@JonRowe JonRowe commented Apr 12, 2015

Copy link
Copy Markdown
Member

Issues a warning (which can be supressed) when using a bare raise_error call. Fixes #655.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have all our configuration exposed off of RSpec::Expectations.configuration, so it seems odd to have this other config here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was on the fence about where this should live, given it's very specific it seemed slightly odd to have a config option for it, but I'm happy to move the config there.

@myronmarston

Copy link
Copy Markdown
Member

So I'm realizing that this is going a different direction then we did for the issue of expect { }.not_to raise_error(something_specific) being prone to false positives -- there we raise an error. It seems odd to raise for one form that's prone to false positives but warn for another.

I'm also realizing that we may have other places in the future where we realize that a particular use of matcher is prone to false positives and should be discouraged.

Given that, I'm thinking maybe we do the following:

  • Move the config for this off of RaiseError and onto RSpec::Expectations.configuration, as I suggested below.
  • Rename it to warn_about_possible_false_positives and use it for this and for any other future cases where there's a potential false positive situation.
  • Update the raise_error logic for the negative case to align with this -- it should either warn (if the config is set) or allow the potential false positive.

Thoughts?

@JonRowe

JonRowe commented Apr 12, 2015

Copy link
Copy Markdown
Member Author

Yup, agree

@JonRowe JonRowe force-pushed the warn_about_bare_raise_error branch from 37bf1a2 to d500923 Compare April 14, 2015 04:24
@JonRowe

JonRowe commented Apr 14, 2015

Copy link
Copy Markdown
Member Author

This is changed as discussed, I'll tackle changing raise_error for the negative case in a separate PR

@JonRowe JonRowe force-pushed the warn_about_bare_raise_error branch 2 times, most recently from 4d61db2 to f4a9dc6 Compare April 15, 2015 11:14
@JonRowe

JonRowe commented Apr 15, 2015

Copy link
Copy Markdown
Member Author

Woop fixed Rubocop

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these 10 lines could benefit from being extracted into a helper method. It's a lot to have in-lined into matches?.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@JonRowe JonRowe force-pushed the warn_about_bare_raise_error branch 2 times, most recently from a9f339e to a7133e9 Compare April 15, 2015 23:38
@JonRowe

JonRowe commented Apr 16, 2015

Copy link
Copy Markdown
Member Author

This should be good to go now?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suppression of the warning via the config is the point of this example, so it seems like it should be front and center in the example rather then hidden in a shared context. I was expecting the shared context to be used to guarantee the config value is reset back to what it started at, but not to actually make the state change itself.

@myronmarston

Copy link
Copy Markdown
Member

Left a couple comments but they aren't super important. Feel free to merge w/o addressing them.

@JonRowe JonRowe force-pushed the warn_about_bare_raise_error branch from a7133e9 to 9977848 Compare April 16, 2015 06:10
JonRowe added a commit that referenced this pull request Apr 16, 2015
[skip ci]
@myronmarston

Copy link
Copy Markdown
Member

LGTM, merge when green.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suggestion: raise_error matcher should have no default exception type or default to StandardError

2 participants