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 expect_syntax_error spec helper #1188

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

amomchilov
Copy link

@amomchilov amomchilov commented Jul 30, 2024

This was a really common pattern that I needed to repeat several times in #1187.

I noticed it repeated a bunch (69 times), and could be simplified really nicely with this little helper method.

@@ -36,3 +36,7 @@ def report_on_exception=(value)
ARGV.unshift $0
MSpecRun.main
end

def expect_syntax_error(ruby_src)
Copy link
Author

Choose a reason for hiding this comment

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

Is this the correct place to put a helper like this? Or should it go in mspec?

Copy link
Member

@eregon eregon Jul 31, 2024

Choose a reason for hiding this comment

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

It definitely feels like the wrong place.
Adding expect_syntax_error in MSpec feels wrong too, first MSpec never use the term expect and it seems far too specific.
You could define it in some fixtures file under language maybe.
But I'm not sure I see the value of this helper, the current code works fine, it's a bit verbose but it's also consistent with all other matchers for expected exceptions.

Copy link
Member

Choose a reason for hiding this comment

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

IMO duplication in tests is rarely a problem, especially if it's something pretty trivial like this.
It's often even a feature as it makes easier to find out where the error happened and have all the context around vs in N helper methods called around.

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

Successfully merging this pull request may close these issues.

2 participants