blob: 33a237f215566ab95fc80e42cb5a21c04e645f15 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
require 'spec_helper'
describe Hashie::Rash do
attr_accessor :r
before :each do
@r = Hashie::Rash.new(
/hello/ => 'hello',
/world/ => 'world',
'other' => 'whee',
true => false,
1 => 'awesome',
1..1000 => 'rangey',
# /.+/ => "EVERYTHING"
)
end
it 'should lookup strings' do
r['other'].should eq 'whee'
r['well hello there'].should eq 'hello'
r['the world is round'].should eq 'world'
r.all('hello world').sort.should eq %w(hello world)
end
it 'should lookup regexps' do
r[/other/].should eq 'whee'
end
it 'should lookup other objects' do
r[true].should eq false
r[1].should eq 'awesome'
end
it 'should lookup numbers from ranges' do
@r[250].should eq 'rangey'
@r[999].should eq 'rangey'
@r[1000].should eq 'rangey'
@r[1001].should be_nil
end
it 'should call values which are procs' do
r = Hashie::Rash.new(/(ello)/ => proc { |m| m[1] })
r['hello'].should eq 'ello'
r['ffffff'].should be_nil
end
end
|