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

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 authored Aug 19, 2024
2 parents ff04d47 + 6dba8fa commit 900a1d0
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)

Enhancements:

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 900a1d0

Please sign in to comment.