From e3eb3949273a534893f28921d8157aca8a1c61c8 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Thu, 29 Aug 2024 06:28:13 +0900 Subject: [PATCH] Mix-in `all` method proxy via `Object#extend` as described in https://github.com/teamcapybara/capybara/pull/2771 --- features/support/env.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/features/support/env.rb b/features/support/env.rb index fb8c7592..6bffbb97 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -5,16 +5,21 @@ require "bundler" Bundler.setup -# require order matters, capybara needs to be there before aruba for the RSpec shadowing fix to work (see slightly below) require "capybara/cucumber" require "capybara/apparition" require "aruba/cucumber" require "aruba/config/jruby" if RUBY_ENGINE == "jruby" require "simplecov" -# Small workaround I found for the RSpec/aruba shadowing problem showcased in https://github.com/PragTob/all_conflict/ -# It _seems_ to work for now but it's definitely not ideal. Wish this was fixed in Capybara. -Aruba::Api::Core.include(Capybara::RSpecMatcherProxies) +# Monkey-patching Capybara::DSL if Capybara::DSLRSpecProxyInstaller has no `extended` hook +unless Module.new { extend RSpec::Matchers; extend Capybara::DSL }.singleton_class.ancestors.include?(Capybara::RSpecMatcherProxies) + Capybara::DSL.extend(Module.new { + def extended(base) + base.extend(::Capybara::RSpecMatcherProxies) if defined?(::RSpec::Matchers) && base.is_a?(::RSpec::Matchers) + super + end + }) +end # Rack app for Capybara which returns the latest coverage report from Aruba temp project dir coverage_dir = File.expand_path("../../tmp/aruba/project/coverage/", __dir__)