spec/restspec/schema/checker_spec.rb in restspec-0.2.6 vs spec/restspec/schema/checker_spec.rb in restspec-0.3.0

- old
+ new

@@ -1,12 +1,13 @@ require 'spec_helper' include Restspec::Schema describe Checker do + let(:options) { {} } let(:schema) do - Schema.new(:product).tap do |schema| + Schema.new(:product, options).tap do |schema| schema.attributes[:name] = Attribute.new(:name, Types::StringType.new) end end let(:checker) { Checker.new(schema) } @@ -15,9 +16,29 @@ context 'when no object is sent' do it 'raises a Checker::NoObjectError' do expect do checker.check!(nil) end.to raise_error(Checker::NoObjectError, /Nil/) + end + end + + context 'when the schema is root?' do + let(:options) { { root: 'monkey' } } + + context 'when no root is present' do + it 'raises a Checker::NoRootFoundError' do + expect do + checker.check!(age: 10) + end.to raise_error(Checker::NoRootFoundError, /monkey/) + end + end + + context 'when the root is present' do + it 'does not raises a Checker::NoRootFoundError' do + expect do + checker.check!(monkey: { name: 'Apu' }) + end.to_not raise_error + end end end context 'when no attribute is present' do it 'raises a Checker::NoAttributeError' do