|
43 | 43 | expect(validator).to be === %w(1 2 3) |
44 | 44 | end |
45 | 45 |
|
46 | | - it 'has a built-in HashOf matcher' do |
47 | | - validator = subject.HashOf(Symbol => Integer) |
48 | | - expect(validator).to be === {a: 2, b:2} |
49 | | - end |
50 | | - |
51 | | - it 'raises ArgumentError if the HashOf argument is wrong' do |
52 | | - expect { subject.HashOf({a: 1, b: 2}) }.to raise_error(ArgumentError, |
53 | | - "HashOf() takes a hash with one key and one value", |
54 | | - ) |
| 46 | + context 'built-in HashOf matcher' do |
| 47 | + it 'matches hashes' do |
| 48 | + validator = subject.HashOf(Symbol => Integer) |
| 49 | + expect(validator).to be === {a: 2, b:2} |
| 50 | + end |
| 51 | + |
| 52 | + it 'raises ArgumentError if the argument is wrong' do |
| 53 | + expect { subject.HashOf({a: 1, b: 2}) }.to raise_error(ArgumentError, |
| 54 | + "HashOf() takes a hash with one key and one value", |
| 55 | + ) |
| 56 | + end |
55 | 57 | end |
56 | 58 |
|
57 | 59 | it 'has a built-in RangeOf matcher' do |
|
69 | 71 | expect(subject.__attributes.first.name).to eq(:else) |
70 | 72 | end |
71 | 73 |
|
| 74 | + context 'built-in HashCoercer coercer' do |
| 75 | + it 'allows anything for keys/values by default' do |
| 76 | + coercer = subject.HashCoercer() |
| 77 | + expect(coercer.({whatever: 42})).to eq({whatever: 42}) |
| 78 | + end |
| 79 | + |
| 80 | + it 'can take coercers for keys and values' do |
| 81 | + coercer = subject.HashCoercer( |
| 82 | + keys: ->(x) { x.to_sym }, |
| 83 | + values: ->(x) { x.to_i }, |
| 84 | + ) |
| 85 | + expect(coercer.({'x' => '1'})).to eq({x: 1}) |
| 86 | + end |
| 87 | + end |
| 88 | + |
72 | 89 | it "produces a frozen recipe with DSL.run" do |
73 | 90 | recipe = described_class.run { whatever } |
74 | 91 |
|
|
0 commit comments