A platform for community discussion. Free, open, simple.
DEV: Add some description to help with understanding flakey test failures (#23053)
Natalie Tayaa7917d53361
diff --git a/spec/models/username_validator_spec.rb b/spec/models/username_validator_spec.rbindex 603f12e7bba..7cbc48ab4d7 100644--- a/spec/models/username_validator_spec.rb+++ b/spec/models/username_validator_spec.rb@@ -1,23 +1,27 @@# frozen_string_literal: trueRSpec.describe UsernameValidator do- def expect_valid(*usernames)+ def expect_valid(*usernames, failure_reason: "")usernames.each do |username|validator = UsernameValidator.new(username)+ message = "expected '#{username}' to be valid"+ message = "#{message}, #{failure_reason}" if failure_reason.present?aggregate_failures do- expect(validator.valid_format?).to eq(true), "expected '#{username}' to be valid"+ expect(validator.valid_format?).to eq(true), messageexpect(validator.errors).to be_emptyendendend- def expect_invalid(*usernames, error_message:)+ def expect_invalid(*usernames, error_message:, failure_reason: "")usernames.each do |username|validator = UsernameValidator.new(username)+ message = "expected '#{username}' to be invalid"+ message = "#{message}, #{failure_reason}" if failure_reason.present?aggregate_failures do- expect(validator.valid_format?).to eq(false), "expected '#{username}' to be invalid"+ expect(validator.valid_format?).to eq(false), messageexpect(validator.errors).to include(error_message)endend@@ -43,13 +47,20 @@ RSpec.describe UsernameValidator doit "is invalid when the username is too long" doSiteSetting.max_username_length = 8- expect_invalid("abcdefghi", error_message: I18n.t(:"user.username.long", max: 8))+ expect_invalid(+ "abcdefghi",+ error_message: I18n.t(:"user.username.long", max: 8),+ failure_reason: "Should be invalid as username length > #{SiteSetting.max_username_length}",+ )endit "is valid when the username has the maximum length" doSiteSetting.max_username_length = 8- expect_valid("abcdefgh")+ expect_valid(+ "abcdefgh",+ failure_reason: "Should be valid as username length = #{SiteSetting.max_username_length}",+ )endit "is valid when the username contains alphanumeric characters, dots, underscores and dashes" do@@ -142,13 +153,20 @@ RSpec.describe UsernameValidator do"חוטב_עצים","Holzfäller",error_message: I18n.t(:"user.username.long", max: 8),+ failure_reason:+ "Should be invalid as username length are > #{SiteSetting.max_username_length}",)endit "is valid when the username has the maximum length" doSiteSetting.max_username_length = 9- expect_valid("Дровосек", "چوب-لباسی", "தமிழ்-தமிழ்")+ expect_valid(+ "Дровосек",+ "چوب-لباسی",+ "தமிழ்-தமிழ்",+ failure_reason: "Should be valid as usernames are <= #{SiteSetting.max_username_length}",+ )endit "is invalid when the username has too many Unicode codepoints" do