Sha256: 54d1bebd487f1933df3cfd6f65a18de8be8241ff2ef21af5ccb0c8274a5fc381

Contents?: true

Size: 965 Bytes

Versions: 60

Compression:

Stored size: 965 Bytes

Contents

require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)

describe "Array#include?" do
  it "returns true if object is present, false otherwise" do
    [1, 2, "a", "b"].include?("c").should == false
    [1, 2, "a", "b"].include?("a").should == true
  end

  it "determines presence by using element == obj" do
    o = mock('')

    [1, 2, "a", "b"].include?(o).should == false

    def o.==(other); other == 'a'; end

    [1, 2, o, "b"].include?('a').should == true

    [1, 2.0, 3].include?(2).should == true
  end

  it "calls == on elements from left to right until success" do
    key = "x"
    one = mock('one')
    two = mock('two')
    three = mock('three')
    one.should_receive(:==).any_number_of_times.and_return(false)
    two.should_receive(:==).any_number_of_times.and_return(true)
    three.should_not_receive(:==)
    ary = [one, two, three]
    ary.include?(key).should == true
  end
end

Version data entries

60 entries across 60 versions & 3 rubygems

Version Path
rhodes-7.6.0 spec/framework_spec/app/spec/core/array/include_spec.rb
rhodes-7.5.1 spec/framework_spec/app/spec/core/array/include_spec.rb
rhodes-7.4.1 spec/framework_spec/app/spec/core/array/include_spec.rb
rhodes-7.1.17 spec/framework_spec/app/spec/core/array/include_spec.rb
rhodes-6.2.0 spec/framework_spec/app/spec/core/array/include_spec.rb
rhodes-6.0.11 spec/framework_spec/app/spec/core/array/include_spec.rb
rhodes-5.5.18 spec/framework_spec/app/spec/core/array/include_spec.rb
rhodes-5.5.17 spec/framework_spec/app/spec/core/array/include_spec.rb
rhodes-5.5.15 spec/framework_spec/app/spec/core/array/include_spec.rb
rhodes-5.5.0.22 spec/framework_spec/app/spec/core/array/include_spec.rb
rhodes-5.5.2 spec/framework_spec/app/spec/core/array/include_spec.rb
rhodes-5.5.0.7 spec/framework_spec/app/spec/core/array/include_spec.rb
rhodes-5.5.0.3 spec/framework_spec/app/spec/core/array/include_spec.rb
rhodes-5.5.0 spec/framework_spec/app/spec/core/array/include_spec.rb
tauplatform-1.0.3 spec/framework_spec/app/spec/core/array/include_spec.rb
tauplatform-1.0.2 spec/framework_spec/app/spec/core/array/include_spec.rb
tauplatform-1.0.1 spec/framework_spec/app/spec/core/array/include_spec.rb
opal-0.4.4 spec/rubyspec/core/array/include_spec.rb
opal-0.4.3 spec/rubyspec/core/array/include_spec.rb
opal-0.4.2 spec/rubyspec/core/array/include_spec.rb