CapybaraSelect2 for select2 version 2/3/4
Installation
Add this line to your application's Gemfile:
group :test do
gem 'capybara-select-2'
end
And then execute:
$ bundle
Or install it yourself as:
$ gem install capybara-select-2
Rspec
In your spec_helper.rb
RSpec.configure do |config|
config.include CapybaraSelect2
end
Cucumber
In your env.rb
World CapybaraSelect2
Usage
Select from a container containing the select2 control
Identified by CSS selector
select2 'Buy Milk', css: '#todo'
Identified by XPath selector
select2 'Buy Milk', xpath: '//div[@id="todo"]'
Or Identified by label
select2 'Buy Milk', from: 'Things to do'
If you want to search for an option (via Ajax for example)
select2 'Buy Milk', from: 'Things to do', search: true
Contributing
- Add a test case which covers the bug
- Add code which makes the test green
- Open pull request
License
The gem is available as open source under the terms of the MIT License.