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

Commit bd5d306

Browse files
committed
Require an argument for the Include matcher
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.
1 parent ff04d47 commit bd5d306

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/rspec/matchers/built_in/include.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Include < BaseMatcher # rubocop:disable Metrics/ClassLength
1313

1414
# @api private
1515
def initialize(*expecteds)
16+
raise(ArgumentError, 'Include matcher requires at least one argument') if expecteds.empty?
1617
@expecteds = expecteds
1718
end
1819

spec/rspec/matchers/built_in/include_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ def hash.send; :sent; end
161161
end
162162
end
163163

164+
describe "expect(...).to include(with_no_args)" do
165+
it "fails correctly" do
166+
expect { expect([1, 2, 3]).to include }.to raise_error(ArgumentError)
167+
end
168+
end
169+
164170
describe "expect(...).to include(with_one_arg)" do
165171
it_behaves_like "an RSpec value matcher", :valid_value => [1, 2], :invalid_value => [1] do
166172
let(:matcher) { include(2) }

0 commit comments

Comments
 (0)