All Projects → Hirurg103 → capybara_select2

Hirurg103 / capybara_select2

Licence: MIT, MIT licenses found Licenses found MIT LICENSE MIT LICENSE.txt
Capybara helpers for https://select2.org select box (supports Select2 version 2/3/4)

Programming Languages

ruby
36898 projects - #4 most used programming language
HTML
75241 projects
shell
77523 projects

Projects that are alternatives of or similar to capybara select2

Knapsack
Knapsack splits tests evenly across parallel CI nodes to run fast CI build and save you time.
Stars: ✭ 430 (+795.83%)
Mutual labels:  rspec, cucumber, minitest
Email Spec
Collection of RSpec/MiniTest matchers and Cucumber steps for testing email in a ruby app using ActionMailer or Pony
Stars: ✭ 1,142 (+2279.17%)
Mutual labels:  rspec, cucumber, minitest
Aruba
Test command-line applications with Cucumber-Ruby, RSpec or Minitest. The most up to date documentation can be found on Cucumber.Pro (https://app.cucumber.pro/projects/aruba)
Stars: ✭ 900 (+1775%)
Mutual labels:  rspec, cucumber, minitest
knapsack pro-ruby
Knapsack Pro gem splits tests across parallel CI nodes and makes sure that tests will run in optimal time on each node.
Stars: ✭ 101 (+110.42%)
Mutual labels:  rspec, cucumber, minitest
Fabrication
This project has moved to GitLab! Please check there for the latest updates.
Stars: ✭ 1,017 (+2018.75%)
Mutual labels:  rspec, cucumber
bdd
Given/When/Then/And/But output to RSpec and Minitest
Stars: ✭ 33 (-31.25%)
Mutual labels:  rspec, minitest
Vscode Ruby Test Adapter
A Ruby test adapter extension for the VS Code Test Explorer
Stars: ✭ 50 (+4.17%)
Mutual labels:  rspec, minitest
Fake ftp
A fake FTP server for use with ruby tests
Stars: ✭ 77 (+60.42%)
Mutual labels:  rspec, minitest
With model
Dynamically build an Active Record model (with table) within a test context
Stars: ✭ 119 (+147.92%)
Mutual labels:  rspec, minitest
Lurker
📖 The ultimate tool for documenting and testing APIs in Rails
Stars: ✭ 120 (+150%)
Mutual labels:  rspec, minitest
Mutant
Automated code reviews via mutation testing - semantic code coverage.
Stars: ✭ 1,794 (+3637.5%)
Mutual labels:  rspec, minitest
Websiteone
A website for Agile Ventures
Stars: ✭ 132 (+175%)
Mutual labels:  rspec, cucumber
Factory trace
Simple tool to maintain factories and traits from FactoryBot
Stars: ✭ 184 (+283.33%)
Mutual labels:  rspec, minitest
N plus one control
RSpec and Minitest matchers to prevent N+1 queries problem
Stars: ✭ 345 (+618.75%)
Mutual labels:  rspec, minitest
factory bot-preload
Preload factories (factory_bot) just like fixtures. It will be easy and, probably, faster!
Stars: ✭ 68 (+41.67%)
Mutual labels:  rspec, minitest
LocalSupport
A directory of local support services and volunteer opportunities
Stars: ✭ 60 (+25%)
Mutual labels:  rspec, cucumber
allure-ruby
Allure integrations for Ruby test frameworks
Stars: ✭ 40 (-16.67%)
Mutual labels:  rspec, cucumber
Still life
Rails upgrade's best friend
Stars: ✭ 213 (+343.75%)
Mutual labels:  rspec, minitest
Base App
An app to help jumpstart a new Rails 4 app. Features Ruby 2.0, PostgreSQL, jQuery, RSpec, Cucumber, user and admin system built with Devise, Facebook login.
Stars: ✭ 127 (+164.58%)
Mutual labels:  rspec, cucumber
Action Cable Testing
Action Cable testing utils
Stars: ✭ 192 (+300%)
Mutual labels:  rspec, minitest

CapybaraSelect2 for select2 version 2/3/4

!!! CapybaraSelect2 detects select2 version automatically

Build Status Maintainability Test Coverage

Installation

Add this line to your application's Gemfile:

group :test do
  gem 'capybara-select-2'
end

And then execute:

$ bundle

Or install it with gem install command:

$ gem install capybara-select-2

Configuration

Minitest

# application_system_test_case.rb
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  include CapybaraSelect2
  include CapybaraSelect2::Helpers # if need specific helpers
end

Rspec

# spec_helper.rb
RSpec.configure do |config|
  config.include CapybaraSelect2
  config.include CapybaraSelect2::Helpers # if need specific helpers
end

[Note] In RSpec tests select2 helper is available out of the box

Cucumber

# env.rb
World CapybaraSelect2
World CapybaraSelect2::Helpers # if need specific helpers

Usage

Examples

select2 'Buy Milk', from: 'Todo'
select2 'Buy Milk', css: '#todo'
select2 'Buy Milk', xpath: '//div[@id="todo"]'

Selecting two or more options

select2 'Buy Milk', 'Go to gym', from: 'Todo'

Searching

select2 'Buy Milk', from: 'Todo', search: true

Searching by text different than an option text

select2 'Buy Milk', from: 'Todo', search: 'Buy'

Tagging

select2 'Go to gym', from: 'Todo', tag: true

Resolving ambiguous match

# Select the first matching option if there are two or more options with text 'Buy'
select2 'Buy', from: 'Todo', match: :first

Selecting an option by exact text

# Select 'Eat' if there are two or more options with text 'Eat' ('Eat', 'Eat salad')
select2 'Eat', from: 'Todo', exact_text: true

[Note] CSS and XPath selectors must identify an HTML node that wraps select2 element or a select2 element itself (an HTML element with the .select2-container class)

Options

Option Purpose
css Identify select2 element by a CSS selector
xpath Identify select2 element by an XPath selector
from Identify select2 element by a label
label Identify select2 element by a label
search Search for an option by the passed string. Search by an option text if true is passed
tag Create an option
match Specifies Capybara's matching strategy when selecting an option
exact_text Whether an option text must match exactly

Helpers

Specific select2 helpers that allow more refined access to a select2 control

select2_open label: 'Todo'
select2_close
select2_search 'Milk', css: '#todo'
select2_select 'Buy Milk', from: 'Todo'
select2_clear xpath: "//div[@id='todo']"
Helper Purpose Options
select2_open(options) Open select2 control label, css, xpath
select2_close Close select2 control -
select2_search(term, options) Type into a select2 search field label, from, css, xpath
select2_select(value, options) Select an option from an opened select2 control label, from, css, xpath, match, exact_text
select2_clear(options) Remove selected options (for multi select only) label, from, css, xpath

See description for each option in the Options section

[Note] Helpers above are not available in tests by default. To use them include CapybaraSelect2::Helpers in your test invironment (see Configuration section)

RSpec matchers

# Check that a select2 option with specified text is present on the page
expect(page).to have_select2_option 'Buy Milk'

Testing

See test examples

To see test examples for a specific select2 version, start Sinatra app first:

$ rackup spec/support/select2_examples/config.ru

Visit http://localhost:9292/select2/v4.0.5/examples in your browser to see examples for select2 version 4.0.5

Running tests

# run spec cases for all select2 versions
$ bundle exec rspec

# run spec cases for a specific select2 version
$ SELECT2_VERSION=4.0.5 bundle exec rspec spec/shared

Contributing

  1. Add a test case which covers the bug
  2. Add code which makes the test green
  3. Open pull request

License

The gem is available as open source under the terms of the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].