1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
# frozen_string_literal: true
module Capybara
module RSpecMatcherProxies
def all(*args, **kwargs, &block)
if defined?(::RSpec::Matchers::BuiltIn::All) && args.first.respond_to?(:matches?)
::RSpec::Matchers::BuiltIn::All.new(*args)
else
find_all(*args, **kwargs, &block)
end
end
def within(*args, **kwargs, &block)
if block
within_element(*args, **kwargs, &block)
else
be_within(*args)
end
end
end
end
if RUBY_ENGINE == 'jruby'
# :nocov:
module Capybara::DSL
class << self
remove_method :included
def included(base)
warn 'including Capybara::DSL in the global scope is not recommended!' if base == Object
if defined?(::RSpec::Matchers) && base.include?(::RSpec::Matchers)
base.send(:include, ::Capybara::RSpecMatcherProxies)
end
super
end
end
end
if defined?(RSpec::Matchers)
module ::RSpec::Matchers
def self.included(base)
base.send(:include, ::Capybara::RSpecMatcherProxies) if base.include?(::Capybara::DSL)
super
end
end
end
# :nocov:
else
module Capybara::DSLRSpecProxyInstaller
module ClassMethods
def included(base)
base.include(::Capybara::RSpecMatcherProxies) if defined?(::RSpec::Matchers) && base.include?(::RSpec::Matchers)
super
end
end
def self.prepended(base)
class << base
prepend ClassMethods
end
end
end
module Capybara::RSpecMatcherProxyInstaller
module ClassMethods
def included(base)
base.include(::Capybara::RSpecMatcherProxies) if base.include?(::Capybara::DSL)
super
end
end
def self.prepended(base)
class << base
prepend ClassMethods
end
end
end
Capybara::DSL.prepend Capybara::DSLRSpecProxyInstaller
RSpec::Matchers.prepend Capybara::RSpecMatcherProxyInstaller if defined?(RSpec::Matchers)
end
|