Add RSpec 4 compatibility (#17652)

* Remove outdated option

04078317ba

* Use the non-globally exposed RSpec syntax

https://github.com/rspec/rspec-core/pull/2803

* Use the non-globally exposed RSpec syntax, cont

https://github.com/rspec/rspec-core/pull/2803

* Comply to strict predicate matchers

See:
 - https://github.com/rspec/rspec-expectations/pull/1195
 - https://github.com/rspec/rspec-expectations/pull/1196
 - https://github.com/rspec/rspec-expectations/pull/1277
This commit is contained in:
Phil Pirozhkov
2022-07-28 05:27:38 +03:00
committed by GitHub
parent 72b24f3fb9
commit 493d437e79
736 changed files with 781 additions and 782 deletions

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe AllowedIpAddressValidator do
RSpec.describe AllowedIpAddressValidator do
let(:record) { Fabricate.build(:user, trust_level: TrustLevel[0], ip_address: '99.232.23.123') }
let(:validator) { described_class.new(attributes: :ip_address) }

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe CensoredWordsValidator do
RSpec.describe CensoredWordsValidator do
let(:value) { 'some new bad text' }
let(:record) { Fabricate(:post, raw: 'this is a test') }
let(:attribute) { :raw }

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe CssColorValidator do
RSpec.describe CssColorValidator do
subject { described_class.new }
it "validates hex colors" do

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe EmailAddressValidator do
RSpec.describe EmailAddressValidator do
it 'should match valid emails' do
['test@discourse.org', 'good_user@discourse.org', 'incoming+%{reply_key}@discourse.org'].each do |email|
expect(EmailAddressValidator.valid_value?(email)).to eq(true)

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe EmailSettingValidator do
RSpec.describe EmailSettingValidator do
describe '#valid_value?' do
subject(:validator) { described_class.new }

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe EmailValidator do
RSpec.describe EmailValidator do
def blocks?(email)
user = Fabricate.build(:user, email: email)
validator = EmailValidator.new(attributes: :email)

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe ExternalSystemAvatarsValidator do
RSpec.describe ExternalSystemAvatarsValidator do
subject { described_class.new }
it "disallows disabling external system avatars when Unicode usernames are enabled" do

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe GroupSettingValidator do
RSpec.describe GroupSettingValidator do
describe '#valid_value?' do
subject(:validator) { described_class.new }

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe HostListSettingValidator do
RSpec.describe HostListSettingValidator do
subject(:validator) { described_class.new() }
describe '#valid_value?' do

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe IntegerSettingValidator do
RSpec.describe IntegerSettingValidator do
describe '#valid_value?' do
shared_examples "for all IntegerSettingValidator opts" do

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe IpAddressFormatValidator do
RSpec.describe IpAddressFormatValidator do
let(:record) { Fabricate.build(:screened_ip_address, ip_address: '99.232.23.123') }
let(:validator) { described_class.new(attributes: :ip_address) }

View File

@@ -1,7 +1,7 @@
# encoding: UTF-8
# frozen_string_literal: true
describe MaxEmojisValidator do
RSpec.describe MaxEmojisValidator do
# simulate Rails behavior (singleton)
def validate

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe MaxUsernameLengthValidator do
RSpec.describe MaxUsernameLengthValidator do
it "checks for minimum range" do
User.update_all('username = username || username')
SiteSetting.min_username_length = 9

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe MinUsernameLengthValidator do
RSpec.describe MinUsernameLengthValidator do
it "checks for maximum range" do
SiteSetting.max_username_length = 10

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe PasswordValidator do
RSpec.describe PasswordValidator do
def password_error_message(key)
I18n.t("activerecord.errors.models.user.attributes.password.#{key.to_s}")

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe PostValidator do
RSpec.describe PostValidator do
fab!(:topic) { Fabricate(:topic) }
let(:post) { build(:post, topic: topic) }
let(:validator) { PostValidator.new({}) }

View File

@@ -10,7 +10,7 @@ module QualityTitleValidatorSpec
end
end
describe "A record validated with QualityTitleValidator" do
RSpec.describe "A record validated with QualityTitleValidator" do
let(:valid_title) { "hello this is my cool topic! welcome: all;" }
let(:short_title) { valid_title.slice(0, SiteSetting.min_topic_title_length - 1) }
let(:long_title) { valid_title.center(SiteSetting.max_topic_title_length + 1, 'x') }

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe RegexSettingValidator do
RSpec.describe RegexSettingValidator do
describe '#valid_value?' do
subject(:validator) { described_class.new }

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe RegexpListValidator do
RSpec.describe RegexpListValidator do
subject { described_class.new }
it "allows lists of valid regular expressions" do

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe ReplyByEmailAddressValidator do
RSpec.describe ReplyByEmailAddressValidator do
describe '#valid_value?' do
subject(:validator) { described_class.new }

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe ReplyByEmailEnabledValidator do
RSpec.describe ReplyByEmailEnabledValidator do
describe '#valid_value?' do
subject(:validator) { described_class.new }

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe SearchTokenizeChineseValidator do
RSpec.describe SearchTokenizeChineseValidator do
it 'does not allow search_tokenize_chinese to be enabled when search_tokenize_japanese is enabled' do
SiteSetting.search_tokenize_japanese = true

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe SearchTokenizeJapaneseValidator do
RSpec.describe SearchTokenizeJapaneseValidator do
it 'does not allow search_tokenize_japanese to be enabled when search_tokenize_chinese is enabled' do
SiteSetting.search_tokenize_chinese = true

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe SelectableAvatarsModeValidator do
RSpec.describe SelectableAvatarsModeValidator do
describe '#valid_value?' do
subject(:validator) { described_class.new }

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe StringSettingValidator do
RSpec.describe StringSettingValidator do
describe '#valid_value?' do
shared_examples "for all StringSettingValidator opts" do

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe TimezoneValidator do
RSpec.describe TimezoneValidator do
describe "#valid?" do
context "when timezone is ok" do
it "returns true" do

View File

@@ -1,7 +1,7 @@
# encoding: UTF-8
# frozen_string_literal: true
describe TopicTitleLengthValidator do
RSpec.describe TopicTitleLengthValidator do
# simulate Rails behavior (singleton)
def validate

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe UnicodeUsernameAllowlistValidator do
RSpec.describe UnicodeUsernameAllowlistValidator do
subject { described_class.new }
it "allows an empty allowlist" do

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe UnicodeUsernameValidator do
RSpec.describe UnicodeUsernameValidator do
subject { described_class.new }
it "disallows Unicode usernames when external system avatars are disabled" do

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe UploadValidator do
RSpec.describe UploadValidator do
subject(:validator) { described_class.new }
describe 'validate' do

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe UserFullNameValidator do
RSpec.describe UserFullNameValidator do
let(:validator) { described_class.new(attributes: :name) }
subject(:validate) { validator.validate_each(record, :name, @name) }
let(:record) { Fabricate.build(:user, name: @name) }

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe UsernameSettingValidator do
RSpec.describe UsernameSettingValidator do
describe '#valid_value?' do
subject(:validator) { described_class.new }