!!! CapybaraSelect2 detects select2 version automatically
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
[Note] In the projects which use RSpec or Cucumber, the select2
helper is available out of the box
In your application_system_test_case.rb
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
include CapybaraSelect2::Helpers
end
In your spec_helper.rb
RSpec.configure do |config|
config.include CapybaraSelect2
end
In your env.rb
World CapybaraSelect2
- Identified by CSS selector
select2 'Buy Milk', css: '#todo'
- Identified by XPath selector
select2 'Buy Milk', xpath: '//div[@id="todo"]'
[Note] CSS and xPath selectors should identify a block which wraps select2 element or a select2 element itself (an html element with the .select2-container
class)
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
select2 'Millennials', from: 'Generations', tag: true
select2 'Buy Milk', 'Go to gym', css: '#todo'
select2 'Buy Milk', from: 'Things to do', search: true, match: :first
select2 'Buy Milk', from: 'Things to do', exact_text: true
expect(page).to have_select2_option('Buy Milk')
- Add a test case which covers the bug
- Add code which makes the test green
- Open pull request
The gem is available as open source under the terms of the MIT License.