DEV: ensure state is clean prior to spec (#12399)

Corrects flaky spec

Previously we were only clearing state after our spec ran, leaving possible
edge cases where `Discourse.plugins` had data.

Clean-up source of the plugin leak

1 pop was not enough to clear the plugin, plus make specs a bit more
deliberate
This commit is contained in:
Sam 2021-03-15 19:11:23 +11:00 committed by GitHub
parent 139a547f22
commit 6c57f6f49d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 7 deletions

View File

@ -78,8 +78,14 @@ describe Discourse do
let(:plugin1) { plugin_class.new.tap { |p| p.enabled = true; p.path = "my-plugin-1" } }
let(:plugin2) { plugin_class.new.tap { |p| p.enabled = false; p.path = "my-plugin-1" } }
before { Discourse.plugins.append(plugin1, plugin2) }
after { Discourse.plugins.clear }
before do
Discourse.plugins.append(plugin1, plugin2)
end
after do
Discourse.plugins.delete plugin1
Discourse.plugins.delete plugin2
end
before do
plugin_class.any_instance.stubs(:css_asset_exists?).returns(true)
@ -87,13 +93,13 @@ describe Discourse do
end
it 'can find plugins correctly' do
expect(Discourse.plugins).to contain_exactly(plugin1, plugin2)
expect(Discourse.plugins).to include(plugin1, plugin2)
# Exclude disabled plugins by default
expect(Discourse.find_plugins({})).to contain_exactly(plugin1)
expect(Discourse.find_plugins({})).to include(plugin1)
# Include disabled plugins when requested
expect(Discourse.find_plugins(include_disabled: true)).to contain_exactly(plugin1, plugin2)
expect(Discourse.find_plugins(include_disabled: true)).to include(plugin1, plugin2)
end
it 'can find plugin assets' do

View File

@ -28,14 +28,20 @@ describe Stylesheet::Compiler do
end
context "with a plugin" do
before do
let :plugin1 do
plugin1 = Plugin::Instance.new
plugin1.path = "#{Rails.root}/spec/fixtures/plugins/my_plugin/plugin.rb"
plugin1.register_css "body { background: $primary }"
plugin1
end
let :plugin2 do
plugin2 = Plugin::Instance.new
plugin2.path = "#{Rails.root}/spec/fixtures/plugins/scss_plugin/plugin.rb"
plugin2
end
before do
Discourse.plugins << plugin1
Discourse.plugins << plugin2
plugin1.activate!
@ -44,7 +50,8 @@ describe Stylesheet::Compiler do
end
after do
Discourse.plugins.pop
Discourse.plugins.delete plugin1
Discourse.plugins.delete plugin2
Stylesheet::Importer.register_imports!
DiscoursePluginRegistry.reset!
end