Rubocop spec/support/expect.rb

This commit is contained in:
Eric Schultz 2021-02-25 13:01:49 -06:00 committed by Eric Schultz
parent 7ce86e2c88
commit 5495f6574a

View file

@ -3,23 +3,28 @@
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later # License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE # Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
module Expect module Expect
def expect_validation_errors(list_of_errors, validators, error_validator_length_should_match = true) def expect_validation_errors(list_of_errors, validators, error_validator_length_should_match: true) # rubocop:disable Metrics/AbcSize
if list_of_errors.is_a?(ParamValidation::ValidationError) list_of_errors = get_list_of_errors(list_of_errors)
validators = [validators] if validators.is_a?(Hash)
expect(list_of_errors.length).to eq(validators.length) if error_validator_length_should_match
list_of_errors = list_of_errors.data validators.each do |i|
end expect(list_of_errors.any? do |e|
list_of_errors = [list_of_errors] if list_of_errors.is_a?(Hash) e[:key].to_s == i[:key].to_s && e[:name].to_s == i[:name].to_s
validators = [validators] if validators.is_a?(Hash) end).to eq(true), "#{i[:key]} should have existed for #{i[:name]}"
if error_validator_length_should_match end
expect(list_of_errors.length).to eq(validators.length) end
end
validators.each do |i| def match_houid(prefix)
expect(list_of_errors.any? { |e| e[:key].to_s == i[:key].to_s && e[:name].to_s == i[:name].to_s }).to eq(true), "#{i[:key]} should have existed for #{i[:name]}" match(/#{prefix}_[a-zA-Z0-9]{22}/)
end end
end
def match_houid(prefix) private
match(/#{prefix}_[a-zA-Z0-9]{22}/)
end def get_list_of_errors(list_of_errors)
return list_of_errors.data if list_of_errors.is_a?(ParamValidation::ValidationError)
return [list_of_errors] if list_of_errors.is_a?(Hash)
list_of_errors
end
end end