Improve EPCI specs (#8634)

* fix nonsense spec

* refactor spec
This commit is contained in:
Sébastien Carceles 2023-02-22 10:16:58 +01:00 committed by GitHub
parent 1e39c9c703
commit 28c6fd8cfc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,7 +12,7 @@ RSpec.describe TypesDeChamp::PrefillEpciTypeDeChamp do
describe 'ancestors' do describe 'ancestors' do
subject { described_class.new(type_de_champ) } subject { described_class.new(type_de_champ) }
it { is_expected.to be_kind_of(TypesDeChamp::PrefillEpciTypeDeChamp) } it { is_expected.to be_kind_of(TypesDeChamp::PrefillTypeDeChamp) }
end end
describe '#possible_values' do describe '#possible_values' do
@ -55,34 +55,38 @@ RSpec.describe TypesDeChamp::PrefillEpciTypeDeChamp do
describe '#transform_value_to_assignable_attributes' do describe '#transform_value_to_assignable_attributes' do
subject(:transform_value_to_assignable_attributes) { described_class.build(type_de_champ).transform_value_to_assignable_attributes(value) } subject(:transform_value_to_assignable_attributes) { described_class.build(type_de_champ).transform_value_to_assignable_attributes(value) }
shared_examples "a transformation to" do |code_departement, value|
it { is_expected.to match({ code_departement: code_departement, value: value }) }
end
context 'when the value is nil' do context 'when the value is nil' do
let(:value) { nil } let(:value) { nil }
it { is_expected.to match({ code_departement: nil, value: nil }) } it_behaves_like "a transformation to", nil, nil
end end
context 'when the value is empty' do context 'when the value is empty' do
let(:value) { '' } let(:value) { '' }
it { is_expected.to match({ code_departement: nil, value: nil }) } it_behaves_like "a transformation to", nil, nil
end end
context 'when the value is a string' do context 'when the value is a string' do
let(:value) { 'hello' } let(:value) { 'hello' }
it { is_expected.to match({ code_departement: nil, value: nil }) } it_behaves_like "a transformation to", nil, nil
end end
context 'when the value is an array of one element' do context 'when the value is an array of one element' do
let(:value) { ['01'] } let(:value) { ['01'] }
it { is_expected.to match({ code_departement: '01', value: nil }) } it_behaves_like "a transformation to", '01', nil
end end
context 'when the value is an array of two elements' do context 'when the value is an array of two elements' do
let(:value) { ['01', '200042935'] } let(:value) { ['01', '200042935'] }
it { is_expected.to match({ code_departement: '01', value: '200042935' }) } it_behaves_like "a transformation to", '01', '200042935'
end end
context 'when the value is an array of three or more elements' do context 'when the value is an array of three or more elements' do
let(:value) { ['01', '200042935', 'hello'] } let(:value) { ['01', '200042935', 'hello'] }
it { is_expected.to match({ code_departement: '01', value: '200042935' }) } it_behaves_like "a transformation to", '01', '200042935'
end end
end end