jnicklas/capybara — Issue #648: Allow multiple args for new selectors
Author: ordinaryzelig
Created: 2012-02-23 06:05:05+00:00
State: open

In a recent project, I wanted to add a selector that required more than 1 argument. For example:

```ruby
Capybara.add_selector :id_and_class do
css { |id, css_class| "##{id}.#{css_class}" }
end
```
I attempted to implement it by using a splat inside [`Capybara::Query#initialize`](https://github.com/jnicklas/capybara/blob/master/lib/capybara/query.rb#L12-21):

```ruby
if args[1]
@selector = Selector.all[args[0]]
@locator = args[1...args.size]
else
@selector = Selector.all.values.find { |s| s.match?(args[0]) }
@locator = args[0]
end
@selector ||= Selector.all[Capybara.default_selector]
@xpath = @selector.call(*@locator).to_s
```
The test I wrote passed, but it broke other things. This didn't seem like a very good implementation anyway, just an attempt. What do you think?