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

Require an argument for the Include matcher #1479

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading