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
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add expect_syntax_error spec helper
amomchilov committed Jul 30, 2024
commit 80f1817ec850f44a80f7d10fafb79d45c184fab8
4 changes: 4 additions & 0 deletions spec_helper.rb
Original file line number Diff line number Diff line change
@@ -36,3 +36,7 @@ def report_on_exception=(value)
ARGV.unshift $0
MSpecRun.main
end

def expect_syntax_error(ruby_src)
Copy link
Contributor 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.

-> { eval(ruby_src) }.should raise_error(SyntaxError)
end