Sha256: 477526eae2db9d45c3d77e12c20885fcf81330d5b61cfed519569942f3f7fa2f
Contents?: true
Size: 1.96 KB
Versions: 14
Compression:
Stored size: 1.96 KB
Contents
require 'spec_helper' describe Volt::LengthValidator do subject { Volt::LengthValidator.validate(*use_params) } let(:use_params) { [model, field_name, options] } let(:model) { Volt::Model.new name: name } let(:field_name) { :name } let(:name) { 'John Doe' } describe '.validate' do describe 'when options is a Fixnum' do let(:options) { 5 } describe 'when name is "John Doe"' do let(:name) { 'John Doe' } it { expect(subject).to eq({}) } end describe 'when name is "John"' do let(:name) { 'John' } it do expect(subject).to eq(name: ['must be at least 5 characters']) end end end describe 'when options is a Hash' do let(:options) do { length: 5, maximum: 10 } end describe 'when name is "John Doe"' do let(:name) { 'John Doe' } it { expect(subject).to eq({}) } end describe 'when name is "John"' do let(:name) { 'John' } it do if RUBY_PLATFORM == 'opal' expect(subject).to eq(name: ["must be at least {\"length\"=>5, \"maximum\"=>10} characters"]) else expect(subject).to eq(name: ['must be at least {:length=>5, :maximum=>10} characters']) end end end describe 'when name is "Zach Galifianakis"' do let(:name) { 'Zach Galifianakis' } it do if RUBY_PLATFORM == 'opal' expect(subject).to eq(name: ["must be less than {\"length\"=>5, \"maximum\"=>10} characters"]) else expect(subject).to eq(name: ['must be less than {:length=>5, :maximum=>10} characters']) end end end end describe 'when options not a Fixnum or a Hash' do let(:options) { 'string' } it 'raises an exception' do expect { subject }.to raise_error( RuntimeError, 'The arguments to length must be a number or a hash' ) end end end end
Version data entries
14 entries across 14 versions & 1 rubygems