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

Commit 21fc0d6

Browse files
committed
Merge pull request #1479 from nevinera/nev--1478--include-with-no-args-should-fail
Require an argument for the Include matcher
1 parent 22aa855 commit 21fc0d6

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Bug Fixes:
77
(Eric Mueller, #1455)
88
* Use `RSpec.warning` for an expectation warning rather than `Kernel.warn`. (Jon Rowe, #1472)
99
* Prevent mismatched use of block and value matchers in compound expectations. (Phil Pirozhkov, #1476)
10+
* Raise an error when passing no arguments to the `include` matcher. (Eric Mueller, #1479)
1011

1112
### 3.13.1 / 2024-06-13
1213
[Full Changelog](http://github.com/rspec/rspec-expectations/compare/v3.13.0...v3.13.1)

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() is not supported, please supply an 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)