DEV: Fix failing chat spec and add unexpected failure indicator (#20299)

This commit fixes the UpdateUserLastRead spec which was checking
for a message ID that did not exist -- this could fail at times
since message ID 2 could exist. Better to create + destroy a message
since then it's guaranteed we have a unique ID.

This also attempts to clarify a step that we expect to fail which
succeeds instead by adding another emoji next to the success tick and
an explanation text.

Also removes some uses of unless in Services::Base, we generally prefer
to use alternatives, since unless can be hard to parse in a lot of
cases.

Co-authored-by: Loïc Guitaut <loic@discourse.org>
This commit is contained in:
Martin Brennan
2023-02-16 04:16:13 +10:00
committed by GitHub
parent d40143371b
commit c07f1e442f
5 changed files with 72 additions and 9 deletions

View File

@ -131,6 +131,47 @@ RSpec.describe Chat::StepsInspector do
OUTPUT
end
end
context "when running in specs" do
context "when a successful step is flagged as being an unexpected result" do
before { result["result.policy.policy"]["spec.unexpected_result"] = true }
it "adapts its output accordingly" do
expect(output).to eq <<~OUTPUT.chomp
[1/7] [model] 'model'
[2/7] [policy] 'policy' <= expected to return false but got true instead
[3/7] [contract] 'default'
[4/7] [transaction]
[5/7] [step] 'in_transaction_step_1'
[6/7] [step] 'in_transaction_step_2'
[7/7] [step] 'final_step'
OUTPUT
end
end
context "when a failing step is flagged as being an unexpected result" do
before do
class DummyService
def policy
false
end
end
result["result.policy.policy"]["spec.unexpected_result"] = true
end
it "adapts its output accordingly" do
expect(output).to eq <<~OUTPUT.chomp
[1/7] [model] 'model'
[2/7] [policy] 'policy' <= expected to return true but got false instead
[3/7] [contract] 'default'
[4/7] [transaction]
[5/7] [step] 'in_transaction_step_1'
[6/7] [step] 'in_transaction_step_2'
[7/7] [step] 'final_step'
OUTPUT
end
end
end
end
describe "#error" do