1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
module RSpec
module Mocks
module ArgumentMatchers
RSpec.describe ArrayIncludingMatcher do
it "describes itself properly" do
expect(ArrayIncludingMatcher.new([1, 2, 3]).description).to eq "array_including(1, 2, 3)"
end
it "describes passed matchers" do
description = array_including(fake_matcher(Object.new)).description
expect(description).to include(MatcherHelpers.fake_matcher_description)
end
context "passing" do
it "matches the same array" do
expect(array_including([1, 2, 3])).to be === [1, 2, 3]
end
it "matches the same array, specified without square brackets" do
expect(array_including(1, 2, 3)).to be === [1, 2, 3]
end
it "matches the same array, specified without square brackets" do
expect(array_including(1, 2, 3)).to be === [1, 2, 3]
end
it "matches the same array, which includes nested arrays" do
expect(array_including([1, 2], 3, 4)).to be === [[1, 2], 3, 4]
end
it "works with duplicates in expected" do
expect(array_including(1, 1, 2, 3)).to be === [1, 2, 3]
end
it "works with duplicates in actual" do
expect(array_including(1, 2, 3)).to be === [1, 1, 2, 3]
end
it "is composable with other matchers" do
klass = Class.new
dbl = double
expect(dbl).to receive(:a_message).with(3, array_including(instance_of(klass)))
dbl.a_message(3, [1, klass.new, 4])
end
# regression check
it "is composable when nested" do
expect(array_including(1, array_including(2, 3), 4)).to be === [1, [2, 3], 4]
expect([[1, 2], 3, 4]).to match array_including(array_including(1, 2), 3, 4)
expect([1,[1,2]]).to match array_including(1, array_including(1,2))
end
end
context "failing" do
it "fails when not all the entries in the expected are present" do
expect(array_including(1, 2, 3, 4, 5)).not_to be === [1, 2]
end
it "fails when passed a composed matcher is pased and not satisfied" do
with_unfulfilled_double do |dbl|
expect {
klass = Class.new
expect(dbl).to receive(:a_message).with(3, array_including(instance_of(klass)))
dbl.a_message(3, [1, 4])
}.to fail_with(/expected: \(3, array_including\(an_instance_of\(\)\)\)/)
end
end
end
end
end
end
end
|