Sha256: 53bc515b1803a42fd9fe2bc44ec792454e49aeaef70e8bb39c659d1585cdf391

Contents?: true

Size: 1.05 KB

Versions: 6

Compression:

Stored size: 1.05 KB

Contents

require 'spec_helper'

describe Hashie::Rash do
  subject do
    Hashie::Rash.new(
      /hello/ => 'hello',
      /world/ => 'world',
      'other' => 'whee',
      true    => false,
      1       => 'awesome',
      1..1000 => 'rangey',
      /(bcd)/ => proc { |m| m[1] }
      # /.+/ => "EVERYTHING"
    )
  end

  it 'finds strings' do
    expect(subject['other']).to eq 'whee'
    expect(subject['well hello there']).to eq 'hello'
    expect(subject['the world is round']).to eq 'world'
    expect(subject.all('hello world').sort).to eq %w(hello world)
  end

  it 'finds regexps' do
    expect(subject[/other/]).to eq 'whee'
  end

  it 'finds other objects' do
    expect(subject[true]).to eq false
    expect(subject[1]).to eq 'awesome'
  end

  it 'finds numbers from ranges' do
    expect(subject[250]).to eq 'rangey'
    expect(subject[999]).to eq 'rangey'
    expect(subject[1000]).to eq 'rangey'
    expect(subject[1001]).to be_nil
  end

  it 'evaluates proc values' do
    expect(subject['abcdef']).to eq 'bcd'
    expect(subject['ffffff']).to be_nil
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
hashie-3.1.0 spec/hashie/rash_spec.rb
whos_dated_who-0.1.0 vendor/bundle/gems/hashie-3.0.0/spec/hashie/rash_spec.rb
whos_dated_who-0.0.1 vendor/bundle/gems/hashie-3.0.0/spec/hashie/rash_spec.rb
hashie-2.1.2 spec/hashie/rash_spec.rb
hashie-3.0.0 spec/hashie/rash_spec.rb
hashie-2.1.1 spec/hashie/rash_spec.rb