Sha256: 721f22cdadea0bd184955d5ed42cdd05df642f46b13c04fd7c861ae557e97ede

Contents?: true

Size: 1.82 KB

Versions: 52

Compression:

Stored size: 1.82 KB

Contents

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

ruby_version_is "1.8.8" do
  describe "Range#cover?" do

    it "raises an ArgumentError without exactly one argument" do
      lambda{ (1..2).cover? }.should raise_error(ArgumentError)
      lambda{ (1..2).cover?(1,2) }.should raise_error(ArgumentError)
    end

    it "returns true if argument is equal to the first value of the range" do
      (0..5).cover?(0).should be_true
      ('f'..'s').cover?('f').should be_true
    end

    it "returns true if argument is equal to the last value of the range" do
      (0..5).cover?(5).should be_true
      (0...5).cover?(4).should be_true
      ('f'..'s').cover?('s').should be_true
    end

    it "returns true if argument is less than the last value of the range and greater than the first value" do
      (20..30).cover?(28).should be_true
      ('e'..'h').cover?('g').should be_true
      ("\u{999}".."\u{9999}").cover? "\u{9995}"
    end

    it "returns true if argument is sole element in the range" do
      (30..30).cover?(30).should be_true
    end

    it "returns false if range is empty" do
      (30...30).cover?(30).should be_false
      (30...30).cover?(nil).should be_false
    end

    it "returns false if the range does not contain the argument" do
      ('A'..'C').cover?(20.9).should be_false
      ('A'...'C').cover?('C').should be_false
    end

    it "uses the range element's <=> to make the comparison" do
      a = mock('a')
      a.should_receive(:<=>).twice.and_return(-1,-1)
      (a..'z').cover?('b').should be_true
    end

    it "uses a continuous inclusion test" do
      ('a'..'f').cover?('aa').should be_true
      ('a'..'f').cover?('babe').should be_true
      ('a'..'f').cover?('baby').should be_true
      ('a'..'f').cover?('ga').should be_false
      (-10..-2).cover?(-2.5).should be_true
    end

  end
end

Version data entries

52 entries across 52 versions & 2 rubygems

Version Path
rhodes-7.6.0 spec/framework_spec/app/spec/core/range/cover_spec.rb
rhodes-7.5.1 spec/framework_spec/app/spec/core/range/cover_spec.rb
rhodes-7.4.1 spec/framework_spec/app/spec/core/range/cover_spec.rb
rhodes-7.1.17 spec/framework_spec/app/spec/core/range/cover_spec.rb
rhodes-6.2.0 spec/framework_spec/app/spec/core/range/cover_spec.rb
rhodes-6.0.11 spec/framework_spec/app/spec/core/range/cover_spec.rb
rhodes-5.5.18 spec/framework_spec/app/spec/core/range/cover_spec.rb
rhodes-5.5.17 spec/framework_spec/app/spec/core/range/cover_spec.rb
rhodes-5.5.15 spec/framework_spec/app/spec/core/range/cover_spec.rb
rhodes-5.5.0.22 spec/framework_spec/app/spec/core/range/cover_spec.rb
rhodes-5.5.2 spec/framework_spec/app/spec/core/range/cover_spec.rb
rhodes-5.5.0.7 spec/framework_spec/app/spec/core/range/cover_spec.rb
rhodes-5.5.0.3 spec/framework_spec/app/spec/core/range/cover_spec.rb
rhodes-5.5.0 spec/framework_spec/app/spec/core/range/cover_spec.rb
tauplatform-1.0.3 spec/framework_spec/app/spec/core/range/cover_spec.rb
tauplatform-1.0.2 spec/framework_spec/app/spec/core/range/cover_spec.rb
tauplatform-1.0.1 spec/framework_spec/app/spec/core/range/cover_spec.rb
rhodes-3.5.1.12 spec/framework_spec/app/spec/core/range/cover_spec.rb
rhodes-3.3.5 spec/framework_spec/app/spec/core/range/cover_spec.rb
rhodes-3.4.2 spec/framework_spec/app/spec/core/range/cover_spec.rb