Skip to content

Fix tests to expect a non-match, not an error #2728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 1 addition & 6 deletions spec/rspec/rails/matchers/be_a_new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,7 @@ def new_record?; true; end

context "matcher is wrong type" do
it "fails" do
expect {
expect(record).to be_a_new(record.class).with(
foo: a_hash_including({ no_foo: "foo" }))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we just use a different "wrong type" of matcher here and keep the example as is? Like be_within/cover/contain_exactly.
At the same time, this example won't break after your rspec-expectations fix.

}.to raise_error { |e|
expect(e.message).to eq("no implicit conversion of Hash into String").or eq("can't convert Hash into String")
}
expect(record).not_to be_a_new(record.class).with(foo: a_hash_including({ no_foo: "foo" }))
end
end
end
Expand Down