Skip to content

Commit

Permalink
Merge pull request #1479 from nevinera/nev--1478--include-with-no-arg…
Browse files Browse the repository at this point in the history
…s-should-fail

Require an argument for the Include matcher
  • Loading branch information
JonRowe committed Aug 20, 2024
1 parent 22aa855 commit 21fc0d6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Bug Fixes:
(Eric Mueller, #1455)
* Use `RSpec.warning` for an expectation warning rather than `Kernel.warn`. (Jon Rowe, #1472)
* Prevent mismatched use of block and value matchers in compound expectations. (Phil Pirozhkov, #1476)
* Raise an error when passing no arguments to the `include` matcher. (Eric Mueller, #1479)

### 3.13.1 / 2024-06-13
[Full Changelog](http://github.com/rspec/rspec-expectations/compare/v3.13.0...v3.13.1)
Expand Down
1 change: 1 addition & 0 deletions lib/rspec/matchers/built_in/include.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Include < BaseMatcher # rubocop:disable Metrics/ClassLength

# @api private
def initialize(*expecteds)
raise(ArgumentError, 'include() is not supported, please supply an argument') if expecteds.empty?
@expecteds = expecteds
end

Expand Down
6 changes: 6 additions & 0 deletions spec/rspec/matchers/built_in/include_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ def hash.send; :sent; end
end
end

describe "expect(...).to include(with_no_args)" do
it "fails correctly" do
expect { expect([1, 2, 3]).to include }.to raise_error(ArgumentError)
end
end

describe "expect(...).to include(with_one_arg)" do
it_behaves_like "an RSpec value matcher", :valid_value => [1, 2], :invalid_value => [1] do
let(:matcher) { include(2) }
Expand Down

0 comments on commit 21fc0d6

Please sign in to comment.