Sha256: 24b17f7a6ecaa60f9f0068ad66e4b35c2011df7bce241f3cb8b5e3f209cf2c22
Contents?: true
Size: 1.18 KB
Versions: 11
Compression:
Stored size: 1.18 KB
Contents
require 'spec_helper' include Restspec::Schema::Types describe HashType do let(:options) { {} } let(:type) { HashType.new(options) } describe '#example_for' do it 'returns an empty hash' do expect(type.example_for(double)).to eq({}) end end describe '#valid?' do it 'validates if it is a hash' do expect(type.totally_valid?(double, {a: 1})).to eq(true) expect(type.totally_valid?(double, '{a: 1}')).to eq(false) end context 'with some specified keys' do let(:options) { { schema_options: { keys: ['name', 'age'] } } } it 'validates if the keys are present' do expect(type.totally_valid?(double, { 'name' => 'name', 'age' => 19 })).to eq(true) expect(type.totally_valid?(double, { 'name' => 'name', 'number' => 19 })).to eq(false) end end context 'with a specified value_type' do let(:options) { { schema_options: { value_type: StringType.new } } } it 'validates that the values are of that type' do expect(type.totally_valid?(double, { 'a' => '1', 'b' => '2' })).to eq(true) expect(type.totally_valid?(double, { 'a' => '1', 'b' => 2 })).to eq(false) end end end end
Version data entries
11 entries across 11 versions & 1 rubygems