diff --git a/lib/capybara/selector/selector.rb b/lib/capybara/selector/selector.rb index 55e84c4ca6..62452c8018 100644 --- a/lib/capybara/selector/selector.rb +++ b/lib/capybara/selector/selector.rb @@ -214,6 +214,7 @@ def initialize(definition, config:, format:) def format @format || @definition.default_format end + alias_method :current_format, :format def enable_aria_label @config[:enable_aria_label] @@ -239,7 +240,7 @@ def add_error(error_msg) errors << error_msg end - def expression_for(name, locator, config: @config, format: format, **options) + def expression_for(name, locator, config: @config, format: current_format, **options) Selector.new(name, config: config, format: format).call(locator, **options) end diff --git a/spec/selector_spec.rb b/spec/selector_spec.rb index 52f27f35a3..fb09e503ff 100644 --- a/spec/selector_spec.rb +++ b/spec/selector_spec.rb @@ -164,7 +164,7 @@ describe 'xpath' do it 'uses filter names passed in' do - selector = Capybara.add_selector :test do + Capybara.add_selector :test do xpath(:something, :other) { |_locator| XPath.descendant } end selector = Capybara::Selector.new :test, config: nil, format: nil