Sha256: 8d7c6da706a2a7576fbeb5273824a1c875e23215552207adce3ccc11e3fb0a55
Contents?: true
Size: 871 Bytes
Versions: 5
Compression:
Stored size: 871 Bytes
Contents
describe "arrays" do Spec::Matchers.define :contain_same_elements_as do |expected| match do |actual| if actual.size == expected.size a, e = actual.dup, expected.dup until e.empty? do if i = a.index(e.pop) then a.delete_at(i) end end a.empty? else false end end end describe "can be matched by their contents disregarding order" do subject { [1,2,2,3] } it { should contain_same_elements_as([1,2,2,3]) } it { should contain_same_elements_as([2,3,2,1]) } it { should_not contain_same_elements_as([3,3,2,1]) } end describe "fail the match with different contents" do subject { [1,2,3] } it { should_not contain_same_elements_as([2,3,4])} it { should_not contain_same_elements_as([1,2,2,3])} it { should_not contain_same_elements_as([1,2])} end end
Version data entries
5 entries across 5 versions & 3 rubygems