Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Fix flaky tests caused by global state leaking between specs (#13573)

Damian Legawiec9b53fcb23b5a
diff --git a/backend/engines/core/spec/models/spree/ability_spec.rb b/backend/engines/core/spec/models/spree/ability_spec.rb
index de68527ba9..6b6828af07 100644
--- a/backend/engines/core/spec/models/spree/ability_spec.rb
+++ b/backend/engines/core/spec/models/spree/ability_spec.rb
@@ -25,6 +25,12 @@ describe Spree::Ability, type: :model do
let(:ability) { Spree::Ability.new(user) }
let(:token) { nil }
+ before do
+ # Ensure permission sets are configured (may have been reset by other specs)
+ Spree.permissions.assign(:default, [Spree::PermissionSets::DefaultCustomer])
+ Spree.permissions.assign(:admin, [Spree::PermissionSets::SuperUser])
+ end
+
after do
Spree::Ability.abilities = Set.new
end
diff --git a/backend/engines/core/spec/spec_helper.rb b/backend/engines/core/spec/spec_helper.rb
index b441312ba8..233c9efe94 100644
--- a/backend/engines/core/spec/spec_helper.rb
+++ b/backend/engines/core/spec/spec_helper.rb
@@ -72,8 +72,12 @@ RSpec.configure do |config|
end
# Re-enable events for specs that need them
+ # Also re-activate subscribers in case another spec called Events.reset!
config.around(:each, events: true) do |example|
- Spree::Events.enable { example.run }
+ Spree::Events.enable do
+ Spree::Events.activate!
+ example.run
+ end
end
config.before(:each) do