spec/csv2hash/definition_spec.rb in csv2hash-0.0.1 vs spec/csv2hash/definition_spec.rb in csv2hash-0.0.2
- old
+ new
@@ -2,18 +2,14 @@
describe Definition do
context 'regular context' do
subject do
- Definition.new.tap do |definition|
- definition.type = Definition::MAPPING
- definition.rules = begin
- [
- { position: [0,0], key: 'name' }
- ]
- end
- end
+ Definition.new(
+ [ { position: [0,0], key: 'name' } ],
+ Definition::MAPPING
+ )
end
it 'variable should be assigned' do
subject.type.should eql Definition::MAPPING
subject.rules.should eql [ { position: [0,0], key: 'name' } ]
@@ -21,43 +17,31 @@
end
describe '#validate!' do
context 'rules failling validation' do
subject do
- Definition.new.tap do |definition|
- definition.type = 'unsuitable_type'
- end
+ Definition.new nil, 'unsuitable_type'
end
it 'should throw exception' do
expect {
subject.validate!
}.to raise_error "not suitable type, please use '#{Definition::MAPPING}' or '#{Definition::COLLECTION}'"
end
end
context 'rules failling validation' do
subject do
- Definition.new.tap do |definition|
- definition.type = Definition::MAPPING
- definition.rules = 'rules'
- end
+ Definition.new 'rules',Definition::MAPPING
end
it 'should throw exception' do
expect { subject.validate! }.to raise_error 'rules must be an Array of rules'
end
end
end
describe '#default!' do
subject do
- Definition.new.tap do |definition|
- definition.type = Definition::MAPPING
- definition.rules = begin
- [
- { position: [0,0], key: 'name' }
- ]
- end
- end
+ Definition.new [ { position: [0,0], key: 'name' } ], Definition::MAPPING
end
before { subject.default! }
it 'missing key must be filled' do
@@ -66,11 +50,10 @@
message: 'undefined :key on :position',
mappable: true,
type: 'string',
values: nil,
nested: nil,
- allow_blank: false,
- maptype: 'cell' }])
+ allow_blank: false }])
end
end
end