\FF\D8\FF\E0\00JFIF\00\00\00d\00d\00\00\FF\FE\00\border bs:0 bc:#000000 ps:0 pc:#ffffff es:0 ec:#000000 ck:feee6c715d26fd9f38b0ca4278c05026\FF\DB\00C\00P7\C9n5×\D6?\BDê\9Ds\EBp\9F[`8m\B7)o\B5\E8\E6I\99\FE3]]A2\BA\8Cw\D6E\93\\DEv\C8\009\F2\F1NI?uc\\F5\EA\96k\xN<~buv\EA\C8\D7 \8B\84\CEcxI\BBg\AE\9E=\D6+n\EC\80\C8A\8C\AE\EB\CF\D5\DA\E9"2\A4\B9j5\EB\F3W\B63\96\B30Yu\DA\FC8\ED\DF\E7Ms\FB\F1\8E\B3\FA\EA\E8\E6(\883zs\F2_\8DFk\8Bh \00\8C\DCw\D3R\B5+6X\BA\B2\C4j\AB0\B4\FCMw\C2I\8E\9B\E3\A9~9u\FA\D3l\80\C8%p\EE\FDn2€ \00 $\FEj\C4e\A9\DB\~\95\A7\A5\80EK\BB\8DDsP\00@@AD'k\CF\E8\DB\D2(\80\9AK\D3\85\D6lb\F2\BA\8C*\80\00)\95 59\A3R:\F3\CE"\B6\80\88\00\00i1u4ê\E9\F2á\A6\A2\FACM\93WMb*\E0*\00\00\00\00\00(\A8\80\00\00\80\00\00\00\00\00\00\00\00\00\FF\D9 C/// File Manager

File Manager

Path: /opt/chef.upgrade/embedded/lib/ruby/gems/2.3.0/gems/hashie-3.5.5/spec/hashie/

Viewing File: rash_spec.rb

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 'finds floats from ranges' do
    expect(subject[10.1]).to eq 'rangey'
    expect(subject[1.0]).to eq 'rangey'
    expect(subject[1000.1]).to be_nil
  end

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

  it 'finds using the find method' do
    expect(subject.fetch(10.1)).to eq 'rangey'
    expect(subject.fetch(true)).to be false
  end

  it 'raises in find unless a key matches' do
    expect { subject.fetch(1_000_000) }.to raise_error(KeyError)
  end

  it 'yields in find unless a key matches' do
    expect { |y| subject.fetch(1_000_000, &y) }.to yield_control
    expect { |y| subject.fetch(10.1, &y) }.to_not yield_control
  end

  it 'gives a default value' do
    expect(subject.fetch(10.1, 'noop')).to eq 'rangey'
    expect(subject.fetch(1_000_000, 'noop')).to eq 'noop'
    expect(subject.fetch(1_000_000) { 'noop' }).to eq 'noop'
    expect(subject.fetch(1_000_000) { |k| k }).to eq 1_000_000
    expect(subject.fetch(1_000_000, 'noop') { 'op' }).to eq 'op'
  end

  it 'responds to hash methods' do
    expect(subject.respond_to?(:to_a)).to be true
    expect(subject.methods).to_not include(:to_a)
  end
end