From a97e9591199e7536b9e10bd9839ed67a4b003f51 Mon Sep 17 00:00:00 2001 From: Ryan Lue Date: Thu, 24 Jan 2019 18:13:04 +0800 Subject: [PATCH] Prevent namespace collisions for let/subject in shared examples When referencing shared example groups in specs, use it_behaves_like instead of include_examples. This runs shared examples in their own, nested context, so that any top-level let/subject methods in the spec do not leak into the shared example groups. --- .../unit/import/zendesk/organization_fields_spec.rb | 2 +- spec/lib/sequencer/unit/import/zendesk/tickets_spec.rb | 2 +- .../sequencer/unit/import/zendesk/user_fields_spec.rb | 2 +- spec/models/group_spec.rb | 2 +- spec/models/history_spec.rb | 2 +- spec/models/organization_spec.rb | 4 ++-- spec/models/role_group_spec.rb | 2 +- spec/models/role_spec.rb | 4 ++-- spec/models/ticket/article_spec.rb | 2 +- spec/models/ticket/priority_spec.rb | 2 +- spec/models/ticket/state_spec.rb | 2 +- spec/models/ticket/state_type_spec.rb | 2 +- spec/models/ticket_spec.rb | 4 ++-- spec/models/user_group_spec.rb | 2 +- spec/models/user_spec.rb | 10 +++++----- 15 files changed, 22 insertions(+), 22 deletions(-) diff --git a/spec/lib/sequencer/unit/import/zendesk/organization_fields_spec.rb b/spec/lib/sequencer/unit/import/zendesk/organization_fields_spec.rb index 55c86c74b..edfd6c9ac 100644 --- a/spec/lib/sequencer/unit/import/zendesk/organization_fields_spec.rb +++ b/spec/lib/sequencer/unit/import/zendesk/organization_fields_spec.rb @@ -2,5 +2,5 @@ require 'rails_helper' require 'lib/sequencer/unit/import/zendesk/sub_sequence/base_examples' RSpec.describe Sequencer::Unit::Import::Zendesk::OrganizationFields, sequencer: :unit do - include_examples 'Sequencer::Unit::Import::Zendesk::SubSequence::Base' + it_behaves_like 'Sequencer::Unit::Import::Zendesk::SubSequence::Base' end diff --git a/spec/lib/sequencer/unit/import/zendesk/tickets_spec.rb b/spec/lib/sequencer/unit/import/zendesk/tickets_spec.rb index c9c4ab015..027798b7f 100644 --- a/spec/lib/sequencer/unit/import/zendesk/tickets_spec.rb +++ b/spec/lib/sequencer/unit/import/zendesk/tickets_spec.rb @@ -2,5 +2,5 @@ require 'rails_helper' require 'lib/sequencer/unit/import/zendesk/sub_sequence/base_examples' RSpec.describe Sequencer::Unit::Import::Zendesk::Tickets, sequencer: :unit do - include_examples 'Sequencer::Unit::Import::Zendesk::SubSequence::Base' + it_behaves_like 'Sequencer::Unit::Import::Zendesk::SubSequence::Base' end diff --git a/spec/lib/sequencer/unit/import/zendesk/user_fields_spec.rb b/spec/lib/sequencer/unit/import/zendesk/user_fields_spec.rb index 48eeee19b..967aac2a4 100644 --- a/spec/lib/sequencer/unit/import/zendesk/user_fields_spec.rb +++ b/spec/lib/sequencer/unit/import/zendesk/user_fields_spec.rb @@ -2,5 +2,5 @@ require 'rails_helper' require 'lib/sequencer/unit/import/zendesk/sub_sequence/base_examples' RSpec.describe Sequencer::Unit::Import::Zendesk::UserFields, sequencer: :unit do - include_examples 'Sequencer::Unit::Import::Zendesk::SubSequence::Base' + it_behaves_like 'Sequencer::Unit::Import::Zendesk::SubSequence::Base' end diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index 68778ad41..7a2f6116d 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -2,5 +2,5 @@ require 'rails_helper' require 'models/application_model_examples' RSpec.describe Group, type: :model do - include_examples 'ApplicationModel' + it_behaves_like 'ApplicationModel' end diff --git a/spec/models/history_spec.rb b/spec/models/history_spec.rb index 324550e6b..05e752e44 100644 --- a/spec/models/history_spec.rb +++ b/spec/models/history_spec.rb @@ -2,5 +2,5 @@ require 'rails_helper' require 'models/application_model_examples' RSpec.describe History, type: :model do - include_examples 'ApplicationModel' + it_behaves_like 'ApplicationModel' end diff --git a/spec/models/organization_spec.rb b/spec/models/organization_spec.rb index 0229e3b1d..45c7de74c 100644 --- a/spec/models/organization_spec.rb +++ b/spec/models/organization_spec.rb @@ -3,8 +3,8 @@ require 'models/concerns/can_lookup_examples' require 'models/concerns/has_search_index_backend_examples' RSpec.describe Organization, type: :model do - include_examples 'CanLookup' - include_examples 'HasSearchIndexBackend', indexed_factory: :organization + it_behaves_like 'CanLookup' + it_behaves_like 'HasSearchIndexBackend', indexed_factory: :organization describe '.where_or_cis' do it 'finds instance by querying multiple attributes case insensitive' do diff --git a/spec/models/role_group_spec.rb b/spec/models/role_group_spec.rb index cc924c7f2..ca5bb3f61 100644 --- a/spec/models/role_group_spec.rb +++ b/spec/models/role_group_spec.rb @@ -5,7 +5,7 @@ RSpec.describe RoleGroup do let!(:group_relation_instance) { create(:role) } - include_examples 'HasGroupRelationDefinition' + it_behaves_like 'HasGroupRelationDefinition' it 'prevents roles from beeing in Group assets' do diff --git a/spec/models/role_spec.rb b/spec/models/role_spec.rb index eb7ebf29d..253515a49 100644 --- a/spec/models/role_spec.rb +++ b/spec/models/role_spec.rb @@ -3,8 +3,8 @@ require 'models/application_model_examples' require 'models/concerns/has_groups_examples' RSpec.describe Role do - include_examples 'ApplicationModel' - include_examples 'HasGroups', group_access_factory: :role + it_behaves_like 'ApplicationModel' + it_behaves_like 'HasGroups', group_access_factory: :role subject(:role) { create(:role) } diff --git a/spec/models/ticket/article_spec.rb b/spec/models/ticket/article_spec.rb index fb1fa655a..787d400cc 100644 --- a/spec/models/ticket/article_spec.rb +++ b/spec/models/ticket/article_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' require 'models/application_model_examples' RSpec.describe Ticket::Article, type: :model do - include_examples 'ApplicationModel' + it_behaves_like 'ApplicationModel' describe '.create' do it 'handles NULL byte in subject or body' do diff --git a/spec/models/ticket/priority_spec.rb b/spec/models/ticket/priority_spec.rb index 677dcac02..b0fc57aad 100644 --- a/spec/models/ticket/priority_spec.rb +++ b/spec/models/ticket/priority_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' require 'models/application_model_examples' RSpec.describe Ticket::Priority, type: :model do - include_examples 'ApplicationModel' + it_behaves_like 'ApplicationModel' describe 'Default state' do describe 'of whole table:' do diff --git a/spec/models/ticket/state_spec.rb b/spec/models/ticket/state_spec.rb index b618818b3..5bbfd39ce 100644 --- a/spec/models/ticket/state_spec.rb +++ b/spec/models/ticket/state_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' require 'models/application_model_examples' RSpec.describe Ticket::State, type: :model do - include_examples 'ApplicationModel' + it_behaves_like 'ApplicationModel' describe '.by_category' do it 'looks up states by category' do diff --git a/spec/models/ticket/state_type_spec.rb b/spec/models/ticket/state_type_spec.rb index 6130131fe..fa7033f21 100644 --- a/spec/models/ticket/state_type_spec.rb +++ b/spec/models/ticket/state_type_spec.rb @@ -2,5 +2,5 @@ require 'rails_helper' require 'models/application_model_examples' RSpec.describe Ticket::StateType, type: :model do - include_examples 'ApplicationModel' + it_behaves_like 'ApplicationModel' end diff --git a/spec/models/ticket_spec.rb b/spec/models/ticket_spec.rb index 2d5899d04..cfd261c2a 100644 --- a/spec/models/ticket_spec.rb +++ b/spec/models/ticket_spec.rb @@ -3,8 +3,8 @@ require 'models/application_model_examples' require 'models/concerns/can_lookup_examples' RSpec.describe Ticket, type: :model do - include_examples 'ApplicationModel' - include_examples 'CanLookup' + it_behaves_like 'ApplicationModel' + it_behaves_like 'CanLookup' describe '#merge_to' do diff --git a/spec/models/user_group_spec.rb b/spec/models/user_group_spec.rb index 7dd7d2499..f9123fc59 100644 --- a/spec/models/user_group_spec.rb +++ b/spec/models/user_group_spec.rb @@ -5,5 +5,5 @@ RSpec.describe UserGroup do let!(:group_relation_instance) { create(:agent_user) } - include_examples 'HasGroupRelationDefinition' + it_behaves_like 'HasGroupRelationDefinition' end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 7aea1f93e..1be710d0d 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -6,11 +6,11 @@ require 'models/concerns/has_groups_permissions_examples' require 'models/concerns/can_lookup_examples' RSpec.describe User do - include_examples 'ApplicationModel' - include_examples 'HasGroups', group_access_factory: :agent_user - include_examples 'HasRoles', group_access_factory: :agent_user - include_examples 'HasGroups and Permissions', group_access_no_permission_factory: :user - include_examples 'CanLookup' + it_behaves_like 'ApplicationModel' + it_behaves_like 'HasGroups', group_access_factory: :agent_user + it_behaves_like 'HasRoles', group_access_factory: :agent_user + it_behaves_like 'HasGroups and Permissions', group_access_no_permission_factory: :user + it_behaves_like 'CanLookup' subject(:user) { create(:user) }