Skip to content

Commit

Permalink
remove prefix from selector initializer keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Mar 6, 2019
1 parent cadad8b commit 0261a98
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions lib/capybara/queries/selector_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def initialize(*args,

@selector = Selector.new(
find_selector(args[0].is_a?(Symbol) ? args.shift : args[0]),
selector_config: { enable_aria_label: enable_aria_label, test_id: test_id },
selector_format: selector_format
config: { enable_aria_label: enable_aria_label, test_id: test_id },
format: selector_format
)

@locator = args.shift
Expand Down Expand Up @@ -150,7 +150,7 @@ def negative_failure_message
private

def selector_format
@selector.selector_format
@selector.format
end

def text_fragments
Expand Down
26 changes: 13 additions & 13 deletions lib/capybara/selector/selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,32 +195,32 @@ def for(locator)

attr_reader :errors

def initialize(definition, selector_config:, selector_format:)
def initialize(definition, config:, format:)
definition = self.class[definition] unless definition.is_a? Definition
super(definition)
@definition = definition
@selector_config = selector_config
@selector_format = selector_format
@config = config
@format = format
@errors = []
end

def selector_format
@selector_format || @definition.default_format
def format
@format || @definition.default_format
end

def enable_aria_label
@selector_config[:enable_aria_label]
@config[:enable_aria_label]
end

def test_id
@selector_config[:test_id]
@config[:test_id]
end

def call(locator, **options)
if selector_format
raise ArgumentError, "Selector #{@name} does not support #{selector_format}" unless expressions.key?(selector_format)
if format
raise ArgumentError, "Selector #{@name} does not support #{format}" unless expressions.key?(format)

instance_exec(locator, options, &expressions[selector_format])
instance_exec(locator, options, &expressions[format])
else
warn 'Selector has no format'
end
Expand All @@ -232,8 +232,8 @@ def add_error(error_msg)
errors << error_msg
end

def expression_for(name, locator, config: @selector_config, format: selector_format, **options)
Selector.new(name, selector_config: config, selector_format: format).call(locator, **options)
def expression_for(name, locator, config: @config, format: format, **options)
Selector.new(name, config: config, format: format).call(locator, **options)
end

# @api private
Expand All @@ -247,7 +247,7 @@ def with_filter_errors(errors)

# @api private
def builder(expr = nil)
case selector_format
case format
when :css
Capybara::Selector::CSSBuilder
when :xpath
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/spec/session/all_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

it 'should accept an XPath instance', :exact_false do
@session.visit('/form')
@xpath = Capybara::Selector.new(:fillable_field, selector_config: {}, selector_format: :xpath).call('Name')
@xpath = Capybara::Selector.new(:fillable_field, config: {}, format: :xpath).call('Name')
expect(@xpath).to be_a(::XPath::Union)
@result = @session.all(@xpath).map(&:value)
expect(@result).to include('Smith', 'John', 'John Smith')
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/spec/session/find_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@

it 'should accept an XPath instance' do
@session.visit('/form')
@xpath = Capybara::Selector.new(:fillable_field, selector_config: {}, selector_format: :xpath).call('First Name')
@xpath = Capybara::Selector.new(:fillable_field, config: {}, format: :xpath).call('First Name')
expect(@xpath).to be_a(::XPath::Union)
expect(@session.find(@xpath).value).to eq('John')
end
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/spec/session/first_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

it 'should accept an XPath instance' do
@session.visit('/form')
@xpath = Capybara::Selector.new(:fillable_field, selector_config: {}, selector_format: :xpath).call('First Name')
@xpath = Capybara::Selector.new(:fillable_field, config: {}, format: :xpath).call('First Name')
expect(@xpath).to be_a(::XPath::Union)
expect(@session.first(@xpath).value).to eq('John')
end
Expand Down

0 comments on commit 0261a98

Please sign in to comment.