Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style(RSpec/BeforeAfterAll): manual #106

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/dots_and_dollars_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions spec/mongoid/association/auto_save_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion spec/mongoid/association/constrainable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions spec/mongoid/association/embedded/embeds_many/proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4695,7 +4695,7 @@ class TrackingIdValidationHistory

context 'when substituting polymorphic documents' do

before(:all) do
before do
module DNS
class Zone
include Mongoid::Document
Expand All @@ -4716,7 +4716,7 @@ class Record
end
end

after(:all) do
after do
Object.send(:remove_const, :DNS)
end

Expand Down
3 changes: 0 additions & 3 deletions spec/mongoid/association/macros_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions spec/mongoid/association/referenced/belongs_to/proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

describe Mongoid::Association::Referenced::BelongsTo::Proxy do

before(:all) do
before do
Person.reset_callbacks(:validate)
end

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/mongoid/association/referenced/has_many/proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/mongoid/association/syncable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/mongoid/association_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

describe Mongoid::Association do

before(:all) do
before do
Person.field(
:_id,
type: BSON::ObjectId,
Expand Down
8 changes: 4 additions & 4 deletions spec/mongoid/attributes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@

describe '#_id=' do

after(:all) do
after do
Person.field(
:_id,
type: BSON::ObjectId,
Expand All @@ -555,7 +555,7 @@

context 'when using object ids' do

before(:all) do
before do
Person.field(
:_id,
type: BSON::ObjectId,
Expand Down Expand Up @@ -622,7 +622,7 @@

context 'when using string ids' do

before(:all) do
before do
Person.field(
:_id,
type: String,
Expand Down Expand Up @@ -676,7 +676,7 @@

context 'when using integer ids' do

before(:all) do
before do
Person.field(:_id, type: Integer, overwrite: true)
end

Expand Down
4 changes: 2 additions & 2 deletions spec/mongoid/clients/sessions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

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)
Mongoid::Config.send(:clients=, CONFIG[:clients])
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
Expand Down
4 changes: 2 additions & 2 deletions spec/mongoid/clients/transactions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ 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)
Mongoid::Config.send(:clients=, CONFIG[:clients])
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)
Expand Down
4 changes: 2 additions & 2 deletions spec/mongoid/clients_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@

context 'when no client exists with the key' do

before(:all) do
before do
Band.store_in(client: :nonexistent)
end

Expand Down Expand Up @@ -700,7 +700,7 @@

context 'when no client exists with the key' do

before(:all) do
before do
Band.store_in(client: :nonexistent)
end

Expand Down
7 changes: 2 additions & 5 deletions spec/mongoid/collection_configurable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

describe Mongoid::CollectionConfigurable do

before(:all) do
before do
class CollectionConfigurableValidOptions
include Mongoid::Document

Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions spec/mongoid/criteria/findable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
Loading
Loading