diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8b95d8ee4..2ba96814d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -91,10 +91,6 @@ RSpec/AnyInstance: - 'spec/mongoid/warnings_spec.rb' - 'spec/support/expectations.rb' -# Offense count: 84 -RSpec/BeforeAfterAll: - Enabled: false - # Offense count: 832 # Configuration parameters: Prefixes, AllowedPatterns. # Prefixes: when, with, without diff --git a/spec/integration/app_spec.rb b/spec/integration/app_spec.rb index 43299db48..c6f3b760e 100644 --- a/spec/integration/app_spec.rb +++ b/spec/integration/app_spec.rb @@ -20,7 +20,7 @@ def insert_rails_gem_version(cmd) end describe 'Mongoid application tests' do - before(:all) do + before do unless SpecConfig.instance.app_tests? skip 'Set APP_TESTS=1 in environment to run application tests' end diff --git a/spec/integration/dots_and_dollars_spec.rb b/spec/integration/dots_and_dollars_spec.rb index 8d63fe43c..103c07cf1 100644 --- a/spec/integration/dots_and_dollars_spec.rb +++ b/spec/integration/dots_and_dollars_spec.rb @@ -5,7 +5,7 @@ describe 'Dots and Dollars' do min_server_version '5.0' - before(:all) do + before do class DADMUser include Mongoid::Document field :'first.last', type: String, default: 'Neil.Shweky' diff --git a/spec/mongoid/association/auto_save_spec.rb b/spec/mongoid/association/auto_save_spec.rb index a700a76ba..e1be0def9 100644 --- a/spec/mongoid/association/auto_save_spec.rb +++ b/spec/mongoid/association/auto_save_spec.rb @@ -8,12 +8,12 @@ describe '.auto_save' do - before(:all) do + before do Person.has_many :drugs, validate: false, autosave: true Person.has_one :account, validate: false, autosave: true end - after(:all) do + after do Person.reset_callbacks(:save) end diff --git a/spec/mongoid/association/constrainable_spec.rb b/spec/mongoid/association/constrainable_spec.rb index e9aada89f..52f295832 100644 --- a/spec/mongoid/association/constrainable_spec.rb +++ b/spec/mongoid/association/constrainable_spec.rb @@ -8,7 +8,7 @@ context "when the id's class stores object ids" do - before(:all) do + before do Person.field( :_id, type: BSON::ObjectId, diff --git a/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb b/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb index cc353976f..c6db4e77f 100644 --- a/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +++ b/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb @@ -4695,7 +4695,7 @@ class TrackingIdValidationHistory context 'when substituting polymorphic documents' do - before(:all) do + before do module DNS class Zone include Mongoid::Document @@ -4716,7 +4716,7 @@ class Record end end - after(:all) do + after do Object.send(:remove_const, :DNS) end diff --git a/spec/mongoid/association/macros_spec.rb b/spec/mongoid/association/macros_spec.rb index e29f7ae23..221a23199 100644 --- a/spec/mongoid/association/macros_spec.rb +++ b/spec/mongoid/association/macros_spec.rb @@ -343,9 +343,6 @@ class RelationsTestClass after do Object.send(:remove_const, _class.name) - end - - after(:all) do Mongoid.configure do |config| config.load_configuration(CONFIG) end diff --git a/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb b/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb index 3dffb7ad2..13efc4aa8 100644 --- a/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +++ b/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb @@ -5,7 +5,7 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do - before(:all) do + before do Person.reset_callbacks(:validate) end @@ -503,7 +503,7 @@ person.save! end - after :all do + after do Account.belongs_to :person, dependent: :nullify Person.has_one :account, validate: false end @@ -554,7 +554,7 @@ person.save! end - after :all do + after do Drug.belongs_to :person, dependent: :nullify Person.has_many :drugs, validate: false end @@ -609,7 +609,7 @@ person.save! end - after :all do + after do Account.belongs_to :person, dependent: :nullify Person.has_one :account, validate: false end @@ -649,7 +649,7 @@ person.save! end - after :all do + after do Drug.belongs_to :person, dependent: :nullify Person.has_many :drugs, validate: false end @@ -1094,7 +1094,7 @@ context 'when the relation belongs to a has many and has one' do - before(:all) do + before do class A include Mongoid::Document has_many :bs, inverse_of: :a @@ -1112,7 +1112,7 @@ class C end end - after(:all) do + after do Object.send(:remove_const, :A) Object.send(:remove_const, :B) Object.send(:remove_const, :C) diff --git a/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb b/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb index 9c4811352..ba32dc94c 100644 --- a/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +++ b/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb @@ -13,7 +13,7 @@ Person.relations['preferences'] = original_preferences_association end - after(:all) do + after do Person.reset_callbacks(:save) Person.reset_callbacks(:destroy) end diff --git a/spec/mongoid/association/referenced/has_many/proxy_spec.rb b/spec/mongoid/association/referenced/has_many/proxy_spec.rb index b7265d873..fb6fe96a0 100644 --- a/spec/mongoid/association/referenced/has_many/proxy_spec.rb +++ b/spec/mongoid/association/referenced/has_many/proxy_spec.rb @@ -25,12 +25,12 @@ def initialize(*args) describe Mongoid::Association::Referenced::HasMany::Proxy do config_override :raise_not_found_error, true - before :all do + before do Drug.belongs_to :person, primary_key: :username Person.has_many :drugs, validate: false, primary_key: :username end - after :all do + after do Drug.belongs_to :person, counter_cache: true Person.has_many :drugs, validate: false end diff --git a/spec/mongoid/association/syncable_spec.rb b/spec/mongoid/association/syncable_spec.rb index 514e0dbdf..a3a53f898 100644 --- a/spec/mongoid/association/syncable_spec.rb +++ b/spec/mongoid/association/syncable_spec.rb @@ -5,13 +5,13 @@ describe 'Syncable Association' do config_override :raise_not_found_error, true - before(:all) do + before do Person._synced(Person.relations['preferences']) Person.has_and_belongs_to_many :preferences Preference.has_and_belongs_to_many :people end - after(:all) do + after do Person.reset_callbacks(:save) Person.reset_callbacks(:destroy) end diff --git a/spec/mongoid/association_spec.rb b/spec/mongoid/association_spec.rb index 585dea058..584fcd102 100644 --- a/spec/mongoid/association_spec.rb +++ b/spec/mongoid/association_spec.rb @@ -4,7 +4,7 @@ describe Mongoid::Association do - before(:all) do + before do Person.field( :_id, type: BSON::ObjectId, diff --git a/spec/mongoid/attributes_spec.rb b/spec/mongoid/attributes_spec.rb index d84a2934f..1f74ee953 100644 --- a/spec/mongoid/attributes_spec.rb +++ b/spec/mongoid/attributes_spec.rb @@ -543,7 +543,7 @@ describe '#_id=' do - after(:all) do + after do Person.field( :_id, type: BSON::ObjectId, @@ -555,7 +555,7 @@ context 'when using object ids' do - before(:all) do + before do Person.field( :_id, type: BSON::ObjectId, @@ -622,7 +622,7 @@ context 'when using string ids' do - before(:all) do + before do Person.field( :_id, type: String, @@ -676,7 +676,7 @@ context 'when using integer ids' do - before(:all) do + before do Person.field(:_id, type: Integer, overwrite: true) end diff --git a/spec/mongoid/clients/sessions_spec.rb b/spec/mongoid/clients/sessions_spec.rb index 3453ceaa3..79e2b4821 100644 --- a/spec/mongoid/clients/sessions_spec.rb +++ b/spec/mongoid/clients/sessions_spec.rb @@ -4,7 +4,7 @@ describe Mongoid::Clients::Sessions do - before(:all) do + before do CONFIG[:clients][:other] = CONFIG[:clients][:default].dup CONFIG[:clients][:other][:database] = 'other' Mongoid::Clients.clients.each_value(&:close) @@ -12,7 +12,7 @@ Mongoid::Clients.with_name(:other).subscribe(Mongo::Monitoring::COMMAND, EventSubscriber.new) end - after(:all) do + after do Mongoid::Clients.with_name(:other).close Mongoid::Clients.clients.delete(:other) end diff --git a/spec/mongoid/clients/transactions_spec.rb b/spec/mongoid/clients/transactions_spec.rb index 6d1933892..b3a1e2253 100644 --- a/spec/mongoid/clients/transactions_spec.rb +++ b/spec/mongoid/clients/transactions_spec.rb @@ -14,7 +14,7 @@ def capture_exception end describe Mongoid::Clients::Sessions do - before(:all) do + before do CONFIG[:clients][:other] = CONFIG[:clients][:default].dup CONFIG[:clients][:other][:database] = 'other' Mongoid::Clients.clients.each_value(&:close) @@ -22,7 +22,7 @@ def capture_exception Mongoid::Clients.with_name(:other).subscribe(Mongo::Monitoring::COMMAND, EventSubscriber.new) end - after(:all) do + after do if Gem::Version.new(Mongo::VERSION) >= Gem::Version.new('2.6') Mongoid::Clients.with_name(:other).close Mongoid::Clients.clients.delete(:other) diff --git a/spec/mongoid/clients_spec.rb b/spec/mongoid/clients_spec.rb index fa87dac6a..e0823ff11 100644 --- a/spec/mongoid/clients_spec.rb +++ b/spec/mongoid/clients_spec.rb @@ -590,7 +590,7 @@ context 'when no client exists with the key' do - before(:all) do + before do Band.store_in(client: :nonexistent) end @@ -700,7 +700,7 @@ context 'when no client exists with the key' do - before(:all) do + before do Band.store_in(client: :nonexistent) end diff --git a/spec/mongoid/collection_configurable_spec.rb b/spec/mongoid/collection_configurable_spec.rb index 849e886ed..9be8e97e1 100644 --- a/spec/mongoid/collection_configurable_spec.rb +++ b/spec/mongoid/collection_configurable_spec.rb @@ -4,7 +4,7 @@ describe Mongoid::CollectionConfigurable do - before(:all) do + before do class CollectionConfigurableValidOptions include Mongoid::Document @@ -35,16 +35,13 @@ class CollectionConfigurableInvalidOptions end end - after(:all) do + after do Mongoid.deregister_model(CollectionConfigurableValidOptions) Object.send(:remove_const, :CollectionConfigurableValidOptions) Mongoid.deregister_model(CollectionConfigurableUnknownOptions) Object.send(:remove_const, :CollectionConfigurableUnknownOptions) Mongoid.deregister_model(CollectionConfigurableInvalidOptions) Object.send(:remove_const, :CollectionConfigurableInvalidOptions) - end - - after do [ CollectionConfigurableValidOptions, CollectionConfigurableUnknownOptions diff --git a/spec/mongoid/criteria/findable_spec.rb b/spec/mongoid/criteria/findable_spec.rb index 527e75e41..c182cf6b6 100644 --- a/spec/mongoid/criteria/findable_spec.rb +++ b/spec/mongoid/criteria/findable_spec.rb @@ -618,11 +618,11 @@ context 'when using string ids' do - before(:all) do + before do Band.field :_id, overwrite: true, type: String end - after(:all) do + after do Band.field :_id, overwrite: true, type: BSON::ObjectId, default: -> { BSON::ObjectId.new } end @@ -784,11 +784,11 @@ context 'when using hash ids' do - before(:all) do + before do Band.field :_id, overwrite: true, type: Hash end - after(:all) do + after do Band.field :_id, overwrite: true, type: BSON::ObjectId, default: -> { BSON::ObjectId.new } end @@ -950,11 +950,11 @@ context 'when using integer ids' do - before(:all) do + before do Band.field :_id, overwrite: true, type: Integer end - after(:all) do + after do Band.field :_id, overwrite: true, type: BSON::ObjectId, default: -> { BSON::ObjectId.new } end diff --git a/spec/mongoid/criteria/includable_spec.rb b/spec/mongoid/criteria/includable_spec.rb index 1dcb832c9..6f8e12cc3 100644 --- a/spec/mongoid/criteria/includable_spec.rb +++ b/spec/mongoid/criteria/includable_spec.rb @@ -114,7 +114,7 @@ context 'when the models are inherited' do - before(:all) do + before do class A include Mongoid::Document end @@ -129,7 +129,7 @@ class C end end - after(:all) do + after do Object.send(:remove_const, :A) Object.send(:remove_const, :B) Object.send(:remove_const, :C) @@ -171,7 +171,7 @@ class C context 'when the relation is a has_one' do - before(:all) do + before do class A include Mongoid::Document end @@ -191,7 +191,7 @@ class D end end - after(:all) do + after do Object.send(:remove_const, :A) Object.send(:remove_const, :B) Object.send(:remove_const, :C) @@ -242,7 +242,7 @@ class D context 'when the relation is a has_many' do - before(:all) do + before do class A include Mongoid::Document end @@ -262,7 +262,7 @@ class D end end - after(:all) do + after do Object.send(:remove_const, :A) Object.send(:remove_const, :B) Object.send(:remove_const, :C) @@ -1081,7 +1081,30 @@ class D context 'when including nested referenced associations' do context 'when using a has_one association' do - before(:all) do + after do + Object.send(:remove_const, :A) + Object.send(:remove_const, :B) + Object.send(:remove_const, :C) + Object.send(:remove_const, :D) + end + + let(:a) do + A.create! + end + + let(:b) do + B.create! + end + + let(:c) do + C.create! + end + + let(:d) do + D.create! + end + + before do class A include Mongoid::Document has_one :b @@ -1103,32 +1126,7 @@ class D include Mongoid::Document belongs_to :c end - end - after(:all) do - Object.send(:remove_const, :A) - Object.send(:remove_const, :B) - Object.send(:remove_const, :C) - Object.send(:remove_const, :D) - end - - let!(:a) do - A.create! - end - - let!(:b) do - B.create! - end - - let!(:c) do - C.create! - end - - let!(:d) do - D.create! - end - - before do c.d = d b.c = c a.b = b @@ -1242,7 +1240,10 @@ class D end context 'when there are multiple associations' do - before(:all) do + let(:c2) { C.create! } + let(:d2) { D.create! } + + before do class A has_one :c end @@ -1250,12 +1251,7 @@ class A class C belongs_to :a end - end - - let(:c2) { C.create! } - let(:d2) { D.create! } - before do a.c = c2 a.c.d = d2 end diff --git a/spec/mongoid/criteria/queryable/options_spec.rb b/spec/mongoid/criteria/queryable/options_spec.rb index eb7134e30..4e479a9c0 100644 --- a/spec/mongoid/criteria/queryable/options_spec.rb +++ b/spec/mongoid/criteria/queryable/options_spec.rb @@ -180,7 +180,7 @@ context 'when the serializer is not localized' do - before(:all) do + before do class Field def localized? false @@ -188,7 +188,7 @@ def localized? end end - after(:all) do + after do Object.send(:remove_const, :Field) end @@ -222,15 +222,7 @@ def localized? context 'when the serializer is localized' do with_default_i18n_configs - before(:all) do - class Field - def localized? - true - end - end - end - - after(:all) do + after do Object.send(:remove_const, :Field) end @@ -239,6 +231,12 @@ def localized? end before do + class Field + def localized? + true + end + end + I18n.locale = :de end diff --git a/spec/mongoid/criteria/queryable/selectable_spec.rb b/spec/mongoid/criteria/queryable/selectable_spec.rb index 2b1a18e78..04bb33d0b 100644 --- a/spec/mongoid/criteria/queryable/selectable_spec.rb +++ b/spec/mongoid/criteria/queryable/selectable_spec.rb @@ -314,7 +314,7 @@ def localized? context 'when serializers are provided' do - before(:all) do + before do class Field def evolve(object) Integer.evolve(object) @@ -326,7 +326,7 @@ def localized? end end - after(:all) do + after do Object.send(:remove_const, :Field) end diff --git a/spec/mongoid/criteria/queryable/selectable_where_spec.rb b/spec/mongoid/criteria/queryable/selectable_where_spec.rb index db8d869b2..bfa1aab21 100644 --- a/spec/mongoid/criteria/queryable/selectable_where_spec.rb +++ b/spec/mongoid/criteria/queryable/selectable_where_spec.rb @@ -153,7 +153,7 @@ context 'when the value must be evolved' do - before(:all) do + before do class Document def id 13 @@ -165,7 +165,7 @@ def self.evolve(object) end end - after(:all) do + after do Object.send(:remove_const, :Document) end diff --git a/spec/mongoid/criteria/queryable/selector_spec.rb b/spec/mongoid/criteria/queryable/selector_spec.rb index 9e54f9d4c..76975ab93 100644 --- a/spec/mongoid/criteria/queryable/selector_spec.rb +++ b/spec/mongoid/criteria/queryable/selector_spec.rb @@ -373,7 +373,7 @@ context 'when the alias has a serializer' do - before(:all) do + before do class Field def evolve(object) Integer.evolve(object) @@ -385,7 +385,7 @@ def localized? end end - after(:all) do + after do Object.send(:remove_const, :Field) end @@ -518,7 +518,7 @@ def localized? context 'when the serializer is not localized' do - before(:all) do + before do class Field def evolve(object) Integer.evolve(object) @@ -530,7 +530,7 @@ def localized? end end - after(:all) do + after do Object.send(:remove_const, :Field) end @@ -777,7 +777,15 @@ def localized? context 'when the serializer is localized' do with_default_i18n_configs - before(:all) do + after do + Object.send(:remove_const, :Field) + end + + let(:selector) do + described_class.new({}, { 'key' => Field.new }) + end + + before do class Field def evolve(object) Integer.evolve(object) @@ -787,17 +795,7 @@ def localized? true end end - end - after(:all) do - Object.send(:remove_const, :Field) - end - - let(:selector) do - described_class.new({}, { 'key' => Field.new }) - end - - before do I18n.locale = :de end diff --git a/spec/mongoid/document_spec.rb b/spec/mongoid/document_spec.rb index e2ec62d75..b7b8a3103 100644 --- a/spec/mongoid/document_spec.rb +++ b/spec/mongoid/document_spec.rb @@ -775,7 +775,7 @@ class << self; attr_accessor :name; end describe '#becomes' do - before(:all) do + before do Person.validates_format_of(:ssn, without: /\$\$\$/) class Manager < Person @@ -783,7 +783,7 @@ class Manager < Person end end - after(:all) do + after do Person.reset_callbacks(:validate) Object.send(:remove_const, :Manager) end diff --git a/spec/mongoid/fields/standard_spec.rb b/spec/mongoid/fields/standard_spec.rb index 8c09adedd..fc165f9ec 100644 --- a/spec/mongoid/fields/standard_spec.rb +++ b/spec/mongoid/fields/standard_spec.rb @@ -17,13 +17,13 @@ describe '#pre_processed?' do - before(:all) do + before do class FieldTest include Mongoid::Document end end - after(:all) do + after do Object.send(:remove_const, :FieldTest) end diff --git a/spec/mongoid/fields_spec.rb b/spec/mongoid/fields_spec.rb index 5c0158ac6..6315217d2 100644 --- a/spec/mongoid/fields_spec.rb +++ b/spec/mongoid/fields_spec.rb @@ -300,7 +300,7 @@ describe '#field' do - before(:all) do + before do described_class.option :custom do |model, field, value| end end diff --git a/spec/mongoid/interceptable_spec.rb b/spec/mongoid/interceptable_spec.rb index 1453ffb42..898d1ad75 100644 --- a/spec/mongoid/interceptable_spec.rb +++ b/spec/mongoid/interceptable_spec.rb @@ -511,12 +511,12 @@ class TestClass context 'when running the callbacks directly' do - before(:all) do + before do Exhibition.define_model_callbacks(:rearrange) Exhibition.after_rearrange {} end - after(:all) do + after do Exhibition.reset_callbacks(:rearrange) end @@ -542,14 +542,14 @@ class TestClass band.records.build end - before(:all) do + before do Band.define_model_callbacks(:rearrange) Band.set_callback(:validation, :before) do run_callbacks(:rearrange) end end - after(:all) do + after do # ActiveSupport may raise an error when trying to reset callbacks on all of Band's # descendants, regardless of whether they have a particular callback defined. Band.reset_callbacks(:rearrange) @@ -1658,13 +1658,13 @@ class TestClass Address.new(street: '123 Sesame') end - before(:all) do + before do Person.before_save do |doc| throw(:abort) if doc.mode == :prevent_save end end - after(:all) do + after do Person.reset_callbacks(:save) end diff --git a/spec/mongoid/persistable/creatable_spec.rb b/spec/mongoid/persistable/creatable_spec.rb index a3393dc71..f174a978e 100644 --- a/spec/mongoid/persistable/creatable_spec.rb +++ b/spec/mongoid/persistable/creatable_spec.rb @@ -99,7 +99,7 @@ user.collection.find(_id: user.id).first end - before(:all) do + before do User.embeds_many( :addresses, class_name: 'Address', @@ -107,9 +107,7 @@ validate: false ) Address.embedded_in :user - end - before do user.addresses.create!(city: 'nantes') end diff --git a/spec/mongoid/relations/proxy_spec.rb b/spec/mongoid/relations/proxy_spec.rb index 1a8f86b0a..b92180b4e 100644 --- a/spec/mongoid/relations/proxy_spec.rb +++ b/spec/mongoid/relations/proxy_spec.rb @@ -58,13 +58,13 @@ # # describe "#extend" do # -# before(:all) do +# before do # Person.reset_callbacks(:validate) # module Testable # end # end # -# after(:all) do +# after do # Object.send(:remove_const, :Testable) # end # diff --git a/spec/mongoid/reloadable_spec.rb b/spec/mongoid/reloadable_spec.rb index 7a68bc60e..0bddfa236 100644 --- a/spec/mongoid/reloadable_spec.rb +++ b/spec/mongoid/reloadable_spec.rb @@ -482,14 +482,6 @@ context 'on sharded cluster' do require_topology :sharded - before(:all) do - CONFIG[:clients][:other] = CONFIG[:clients][:default].dup - CONFIG[:clients][:other][:database] = 'other' - Mongoid::Clients.clients.each_value(&:close) - Mongoid::Config.send(:clients=, CONFIG[:clients]) - Mongoid::Clients.with_name(:other).subscribe(Mongo::Monitoring::COMMAND, EventSubscriber.new) - end - let(:subscriber) do client = Mongoid::Clients.with_name(:other) monitoring = client.send(:monitoring) @@ -501,6 +493,12 @@ end before do + CONFIG[:clients][:other] = CONFIG[:clients][:default].dup + CONFIG[:clients][:other][:database] = 'other' + Mongoid::Clients.clients.each_value(&:close) + Mongoid::Config.send(:clients=, CONFIG[:clients]) + Mongoid::Clients.with_name(:other).subscribe(Mongo::Monitoring::COMMAND, EventSubscriber.new) + subscriber.clear_events! end diff --git a/spec/mongoid/tasks/database_spec.rb b/spec/mongoid/tasks/database_spec.rb index fb5304a7d..5f79092f8 100644 --- a/spec/mongoid/tasks/database_spec.rb +++ b/spec/mongoid/tasks/database_spec.rb @@ -4,7 +4,7 @@ describe Mongoid::Tasks::Database do - before(:all) do + before do module DatabaseSpec class Measurement include Mongoid::Document @@ -40,9 +40,11 @@ class Note } end end + + allow(Mongoid::Tasks::Database).to receive(:logger).and_return(logger) end - after(:all) do + after do Mongoid.deregister_model(DatabaseSpec::Measurement) DatabaseSpec.send(:remove_const, :Measurement) Mongoid.deregister_model(DatabaseSpec::Comment) @@ -61,10 +63,6 @@ class Note [User, Account, Address, Draft] end - before do - allow(described_class).to receive(:logger).and_return(logger) - end - describe '.create_collections' do context 'collection_options are specified' do let(:models) do diff --git a/spec/mongoid/timestamps/timeless_spec.rb b/spec/mongoid/timestamps/timeless_spec.rb index a22f24cbb..0b6f76d49 100644 --- a/spec/mongoid/timestamps/timeless_spec.rb +++ b/spec/mongoid/timestamps/timeless_spec.rb @@ -6,7 +6,7 @@ describe '#timeless' do - before(:all) do + before do class Chicken include Mongoid::Document include Mongoid::Timestamps @@ -24,7 +24,7 @@ class Egg end end - after(:all) do + after do Object.send(:remove_const, :Chicken) Object.send(:remove_const, :Egg) end diff --git a/spec/mongoid/traversable_spec.rb b/spec/mongoid/traversable_spec.rb index 39314e6bd..8b4d6fe92 100644 --- a/spec/mongoid/traversable_spec.rb +++ b/spec/mongoid/traversable_spec.rb @@ -1249,7 +1249,7 @@ class GlobalDuplicateDiscriminatorKeyChild < GlobalDuplicateDiscriminatorKeyPare context 'when using the Class.new syntax' do context 'when assigning to a constant' do - before :all do + before do NewClassPerson = Class.new(Person) NewClassPerson2 = Class.new(NewClassPerson) end diff --git a/spec/mongoid/validatable/numericality_spec.rb b/spec/mongoid/validatable/numericality_spec.rb index e4c7f4b5c..92337ae23 100644 --- a/spec/mongoid/validatable/numericality_spec.rb +++ b/spec/mongoid/validatable/numericality_spec.rb @@ -6,7 +6,7 @@ describe '#validate_each' do - before(:all) do + before do class TestModel include Mongoid::Document field :amount, type: BigDecimal @@ -14,7 +14,7 @@ class TestModel end end - after(:all) do + after do Object.send(:remove_const, :TestModel) end diff --git a/spec/mongoid/validatable_spec.rb b/spec/mongoid/validatable_spec.rb index e331c23f6..af093a3a4 100644 --- a/spec/mongoid/validatable_spec.rb +++ b/spec/mongoid/validatable_spec.rb @@ -173,11 +173,11 @@ context 'when the child does not validate the parent' do - before(:all) do + before do Person.validates_associated(:services) end - after(:all) do + after do Person.reset_callbacks(:validate) end diff --git a/spec/support/constraints.rb b/spec/support/constraints.rb index 0bd670643..5f17c3c0a 100644 --- a/spec/support/constraints.rb +++ b/spec/support/constraints.rb @@ -40,7 +40,7 @@ def without_i18n_fallbacks %i[min max].each do |dir| # rubocop:disable Performance/CollectionLiteralInLoop define_method(:"#{dir}_#{meth}_version") do |version| current_version = current_version.call if current_version.is_a?(Proc) - before(:all) do + before do if Constraints.send(:"#{dir}_version?", current_version, version) skip "#{name} version #{version} or #{dir == :min ? 'higher' : 'lower'} " \ "is required (using #{current_version})" @@ -61,7 +61,7 @@ def local_env(env = nil) end def require_mri - before(:all) do + before do unless SpecConfig.instance.mri? skip "MRI required, we have #{SpecConfig.instance.platform}" end @@ -75,7 +75,7 @@ def require_topology(*topologies) raise ArgumentError.new("Invalid topologies requested: #{invalid_topologies.join(', ')}") end - before(:all) do + before do topology = ClusterConfig.instance.topology unless topologies.include?(topology) skip "Topology #{topologies.join(' or ')} required, we have #{topology}" @@ -84,7 +84,7 @@ def require_topology(*topologies) end def require_transaction_support - before(:all) do + before do case ClusterConfig.instance.topology when :single skip 'Transactions tests require a replica set or a sharded cluster' @@ -97,7 +97,7 @@ def require_transaction_support end def require_multi_mongos - before(:all) do + before do if ClusterConfig.instance.topology == :sharded && SpecConfig.instance.addresses.length == 1 skip 'Test requires a minimum of two mongoses if run in sharded topology' end @@ -117,7 +117,7 @@ def require_multi_mongos # In load-balanced topology, the same problem can happen when there is # more than one mongos behind the load balancer. def require_no_multi_shard - before(:all) do + before do if ClusterConfig.instance.topology == :sharded && SpecConfig.instance.addresses.length > 1 skip 'Test requires a single mongos if run in sharded topology' end @@ -129,7 +129,7 @@ def require_no_multi_shard end def require_enterprise - before(:all) do + before do unless ClusterConfig.instance.enterprise? skip 'Test requires enterprise build of MongoDB' end @@ -137,7 +137,7 @@ def require_enterprise end def require_libmongocrypt - before(:all) do + before do # If FLE is set in environment, the entire test run is supposed to # include FLE therefore run the FLE tests. unless ENV['LIBMONGOCRYPT_PATH'].present? || ENV['FLE'].present? @@ -147,7 +147,7 @@ def require_libmongocrypt end def require_no_libmongocrypt - before(:all) do + before do if ENV['LIBMONGOCRYPT_PATH'].present? skip 'Test requires libmongocrypt to not be configured' end