Sha256: 3715d2ab102d18075b788d91cb809d90ea5a7cec60d3447b697281a4c4d4e654

Contents?: true

Size: 1.53 KB

Versions: 14

Compression:

Stored size: 1.53 KB

Contents

describe Compel::Errors do

  it 'should add error' do
    errors = Compel::Errors.new
    errors.add(:first_name, 'is required')

    expect(errors.to_hash[:first_name]).to include('is required')
  end

  it 'should add multiple errors' do
    errors = Compel::Errors.new
    errors.add(:first_name, 'is required')
    errors.add(:first_name, 'is invalid')

    expect(errors.to_hash[:first_name]).to include('is required')
    expect(errors.to_hash[:first_name]).to include('is invalid')
  end

  it 'should add Compel::Errors' do
    address_errors = Compel::Errors.new
    address_errors.add(:line_one, 'is required')
    address_errors.add(:post_code, 'must be an Hash')

    errors = Compel::Errors.new
    errors.add(:address, address_errors)

    expect(errors.to_hash[:address][:line_one]).to include('is required')
    expect(errors.to_hash[:address][:post_code]).to include('must be an Hash')
  end

  it 'should add nested Compel::Errors' do
    post_code_errors = Compel::Errors.new
    post_code_errors.add(:prefix, 'is invalid')
    post_code_errors.add(:suffix, 'is required')

    address_errors = Compel::Errors.new
    address_errors.add(:line_one, 'is required')
    address_errors.add(:post_code, post_code_errors)

    errors = Compel::Errors.new
    errors.add(:address, address_errors)

    expect(errors.to_hash[:address][:line_one]).to include('is required')
    expect(errors.to_hash[:address][:post_code][:prefix]).to include('is invalid')
    expect(errors.to_hash[:address][:post_code][:suffix]).to include('is required')
  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
compel-0.5.1 spec/compel/errors_spec.rb
compel-0.5.0 spec/compel/errors_spec.rb
compel-0.4.3 spec/compel/errors_spec.rb
compel-0.4.2 spec/compel/errors_spec.rb
compel-0.4.0 spec/compel/errors_spec.rb
compel-0.3.7 spec/compel/errors_spec.rb
compel-0.3.6 spec/compel/errors_spec.rb
compel-0.3.4 spec/compel/errors_spec.rb
compel-0.3.2 spec/compel/errors_spec.rb
compel-0.3.1 spec/compel/errors_spec.rb
compel-0.2.0 spec/compel/errors_spec.rb
compel-0.1.3 spec/compel/errors_spec.rb
compel-0.1.2 spec/compel/errors_spec.rb
compel-0.1.1 spec/compel/errors_spec.rb