From 98f16e500cec94be404189eb098cf51ba67b79b0 Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Fri, 12 Jan 2024 12:10:22 +1100 Subject: [PATCH 1/2] Check existence of RSpec.configure When Rails commands such as db:migrate are executed (formerly rake tasks), they load the broader set of rake tasks, and that means that RSpec's rake task is loaded without all of the RSpec context - which means there _is_ an RSpec constant, but it does not have the configure method. i.e. lib/rspec/core/rake_task.rb in rspec-core I considered loading `rspec/core` here instead, but that feels counter to what's needed: if we have that full RSpec context, then we should add the Flipper helpers. But if we don't, then we should respect the current context, not load all of RSpec, and not add Flipper's helpers. --- lib/flipper/test_help.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/flipper/test_help.rb b/lib/flipper/test_help.rb index 23940e3ad..c0ff3878d 100644 --- a/lib/flipper/test_help.rb +++ b/lib/flipper/test_help.rb @@ -16,7 +16,7 @@ def flipper_reset end end -if defined?(RSpec) +if defined?(RSpec) && RSpec.methods.include?(:configure) RSpec.configure do |config| config.include Flipper::TestHelp config.before(:all) { flipper_configure } From f8d88075ac1ed1256ae5f1e43a2dc2fbeab51069 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Fri, 12 Jan 2024 07:46:02 -0500 Subject: [PATCH 2/2] Use respond_to? --- lib/flipper/test_help.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/flipper/test_help.rb b/lib/flipper/test_help.rb index c0ff3878d..ffa68f242 100644 --- a/lib/flipper/test_help.rb +++ b/lib/flipper/test_help.rb @@ -16,7 +16,7 @@ def flipper_reset end end -if defined?(RSpec) && RSpec.methods.include?(:configure) +if defined?(RSpec) && RSpec.respond_to?(:configure) RSpec.configure do |config| config.include Flipper::TestHelp config.before(:all) { flipper_configure }