debian-mirror-gitlab/spec/lib/gitlab/config/entry/validator_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
1.4 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2016-08-24 12:49:21 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::Config::Entry::Validator do
2016-08-24 12:49:21 +05:30
let(:validator) { Class.new(described_class) }
let(:validator_instance) { validator.new(node) }
let(:node) { spy('node') }
before do
allow(node).to receive(:key).and_return('node')
allow(node).to receive(:ancestors).and_return([])
end
describe 'delegated validator' do
before do
validator.class_eval do
validates :test_attribute, presence: true
end
end
context 'when node is valid' do
before do
allow(node).to receive(:test_attribute).and_return('valid value')
end
it 'validates attribute in node' do
expect(node).to receive(:test_attribute)
expect(validator_instance).to be_valid
end
it 'returns no errors' do
validator_instance.validate
expect(validator_instance.messages).to be_empty
end
end
context 'when node is invalid' do
before do
allow(node).to receive(:test_attribute).and_return(nil)
end
it 'validates attribute in node' do
expect(node).to receive(:test_attribute)
expect(validator_instance).to be_invalid
end
it 'returns errors' do
validator_instance.validate
expect(validator_instance.messages)
2018-03-17 18:26:18 +05:30
.to include /test attribute can't be blank/
2016-08-24 12:49:21 +05:30
end
end
end
end