Sha256: 73a11730a184e37e94af472fcd67e4381563f71b922f35031f24e069186872c1

Contents?: true

Size: 968 Bytes

Versions: 46

Compression:

Stored size: 968 Bytes

Contents

require File.dirname(__FILE__) + '/spec_helper'

describe "arrays" do
  def contain_same_elements_as(expected)
    simple_matcher "array with same elements in any order as #{expected.inspect}" 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

46 entries across 46 versions & 6 rubygems

Version Path
dchelimsky-rspec-1.1.11.1 examples/passing/simple_matcher_example.rb
dchelimsky-rspec-1.1.11.2 examples/passing/simple_matcher_example.rb
dchelimsky-rspec-1.1.11.3 examples/passing/simple_matcher_example.rb
dchelimsky-rspec-1.1.11.4 examples/passing/simple_matcher_example.rb
dchelimsky-rspec-1.1.11.5 examples/passing/simple_matcher_example.rb
dchelimsky-rspec-1.1.11.6 examples/passing/simple_matcher_example.rb
dchelimsky-rspec-1.1.11.7 examples/passing/simple_matcher_example.rb
dchelimsky-rspec-1.1.12 examples/passing/simple_matcher_example.rb
dchelimsky-rspec-1.1.99.1 examples/passing/simple_matcher_example.rb
dchelimsky-rspec-1.1.99.13 examples/passing/simple_matcher_example.rb
dchelimsky-rspec-1.1.99.2 examples/passing/simple_matcher_example.rb
dchelimsky-rspec-1.1.99.3 examples/passing/simple_matcher_example.rb
dchelimsky-rspec-1.1.99.4 examples/passing/simple_matcher_example.rb
dchelimsky-rspec-1.1.99.5 examples/passing/simple_matcher_example.rb
dchelimsky-rspec-1.1.99.6 examples/passing/simple_matcher_example.rb
dchelimsky-rspec-1.1.99.7 examples/passing/simple_matcher_example.rb
dchelimsky-rspec-1.1.99.8 examples/passing/simple_matcher_example.rb
dchelimsky-rspec-1.1.99.9 examples/passing/simple_matcher_example.rb
newbamboo-evented-rspec-1.1.12 examples/passing/simple_matcher_example.rb
newbamboo-rspec-1.1.12 examples/passing/simple_matcher_example.rb