DEV: Refactor chat service matchers

This commit is contained in:
Loïc Guitaut
2023-02-15 16:07:32 +01:00
committed by Loïc Guitaut
parent 9c30ae93b3
commit c20b381508

View File

@ -31,6 +31,10 @@ module Chat
error_message_with_inspection(message) error_message_with_inspection(message)
end end
def description
"fail a #{type} named '#{name}'"
end
private private
def step_exists? def step_exists?
@ -46,7 +50,11 @@ module Chat
end end
def type def type
"step" self.class.name.split("::").last.sub("Fail", "").downcase
end
def step
"result.#{type}.#{name}"
end end
def error_message_with_inspection(message) def error_message_with_inspection(message)
@ -56,46 +64,9 @@ module Chat
end end
class FailContract < FailStep class FailContract < FailStep
attr_reader :error_message
def step
"result.contract.#{name}"
end
def type
"contract"
end
def matches?(service)
super && has_error?
end
def has_error?
result[step].errors.present?
end
def failure_message
return "expected contract '#{step}' to have errors" unless has_error?
super
end
def description
"fail a contract named '#{name}'"
end
end end
class FailPolicy < FailStep class FailPolicy < FailStep
def type
"policy"
end
def step
"result.policy.#{name}"
end
def description
"fail a policy named '#{name}'"
end
end end
class FailToFindModel < FailStep class FailToFindModel < FailStep
@ -103,10 +74,6 @@ module Chat
"model" "model"
end end
def step
"result.model.#{name}"
end
def description def description
"fail to find a model named '#{name}'" "fail to find a model named '#{name}'"
end end