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

Require an argument for the Include matcher - #1479

Merged
JonRowe merged 3 commits into
rspec:mainfrom
nevinera:nev--1478--include-with-no-args-should-fail
Aug 19, 2024
Merged

JonRowe merged 3 commits into
rspec:mainfrom
nevinera:nev--1478--include-with-no-args-should-fail

Conversation

@nevinera

Copy link
Copy Markdown
Contributor

Resolves #1478

Purpose

There are some edge-case ways you can try to invoke this matcher that end up parsing as an argument-less call and a separate expression; this will stop that from happening.

Implementation

Treat instantiation of the Include matcher with no arguments as an ArgumentError.

Note

This might count as a breaking change - while it seems like something nobody would ever want to do, the case where this can happen legitimately comes up when the caller is taking an array to splat into the include matcher, and ignoring the empty case because it currently passes.

There are some edge-case ways you can try to invoke this matcher that
end up parsing as an argument-less call and a separate expression; this
will stop that from happening.
@juanca

juanca commented Aug 18, 2024

Copy link
Copy Markdown

Thanks for making the PR! Looks good to me 🫠

@pirj pirj left a comment

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.

Thank you!

@pirj

pirj commented Aug 19, 2024

Copy link
Copy Markdown
Member

@JonRowe we’re thinking about making this a warning, to follow how we did with raise_error(nil). What is your take on this?

@JonRowe
JonRowe merged commit 900a1d0 into rspec:main Aug 19, 2024
@JonRowe

JonRowe commented Aug 19, 2024

Copy link
Copy Markdown
Member

I'm happier with as an error, its a bug in the matcher due to implementation that should never have worked. I actually played around with this a bit improving the error and there are other things that can break (like the description) when there are no expected.

@JonRowe

JonRowe commented Aug 19, 2024

Copy link
Copy Markdown
Member

Thank you @nevinera

JonRowe added a commit that referenced this pull request Aug 20, 2024
…s-should-fail

Require an argument for the Include matcher
@JonRowe

JonRowe commented Aug 20, 2024

Copy link
Copy Markdown
Member

Released in 3.13.2

jrmhaig added a commit to ministryofjustice/Claim-for-Crown-Court-Defence that referenced this pull request Aug 23, 2024
Version 3.13.2 of the rspec-expectations gems updates the `include` matcher to
raise an exception if no arguments are passed. See rspec/rspec-expectations#1479

The `expected_interim_fees_for` helper is meant to return an array of expected
options in a case type selection to be used in the `include` matcher. However,
in some cases `nil` is returned resulting in no arguments resulting in an
exception. This was masking failures as the test was checking that the list
included items in an empty array and was therefore always passing.

It turns out that an update to `govuk-form-builder` from some time ago changed
the id of select boxes and so the list of options being tested was always
empty. This should have immediately resulted in a a failure but it was missed
due to the bug in `expected_interim_fees_for`.
@matthew-puku

Copy link
Copy Markdown

Thanks for this! Caught a few include(*empty_array) cases in our test suite.

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.

to include() should fail

5 participants