diff --git a/lib/capybara/selector/selector.rb b/lib/capybara/selector/selector.rb index 63f132e1b9..083814a606 100644 --- a/lib/capybara/selector/selector.rb +++ b/lib/capybara/selector/selector.rb @@ -215,6 +215,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] @@ -240,7 +241,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 9b117a2871..60b1cc675b 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