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.
This commit is contained in:
Ryan Lue 2019-01-24 18:13:04 +08:00
parent 39bdbf22db
commit a97e959119
15 changed files with 22 additions and 22 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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) }

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -5,5 +5,5 @@ RSpec.describe UserGroup do
let!(:group_relation_instance) { create(:agent_user) }
include_examples 'HasGroupRelationDefinition'
it_behaves_like 'HasGroupRelationDefinition'
end

View file

@ -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) }