Sha256: c9e673f844bd3008641e9522cfb18bae4bcfeffc74a52a14fcac236a8e9d11f6

Contents?: true

Size: 986 Bytes

Versions: 1

Compression:

Stored size: 986 Bytes

Contents

require 'spec_helper'
require 'timeout'

describe Range do
  it "should get a random number out of the range" do
    range = Forgery::Extend(0..9)
    10.times { range.should include(range.random) }
  end

  it "should not take a long time when the range is huge" do
    Timeout.timeout(1){Forgery::Extend(1234567890..12345678901234567890).random}.should_not raise_error(Timeout::Error)
  end

  it "should return nil for a random number from a reverse range" do
    10.times { Forgery::Extend(9..0).random.should be_nil }
  end

  it "should get a random string our of the range" do
    range = Forgery::Extend("a".."z")
    10.times { range.should include(range.random) }
  end

  it "should return nil if the maximum is less than the minimum" do
    Forgery::Extend("z".."a").random.should be_nil
  end

  it "should not return the maximum at excluded range" do
    Kernel.should_receive(:rand).with(9).and_return(8)
    Forgery::Extend(0...9).random.should_not be_equal 9
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
forgery-0.6.0 spec/extensions/range_spec.rb