Module: CapybaraSelect2

Defined in:
lib/capybara_select2.rb,
lib/capybara_select2/utils.rb,
lib/capybara_select2/helpers.rb,
lib/capybara_select2/version.rb,
lib/capybara_select2/selectors.rb

Defined Under Namespace

Modules: Helpers, Selectors, Utils

Constant Summary collapse

VERSION =
"0.5.1"

Instance Method Summary collapse

Instance Method Details

#select2(*args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/capybara_select2.rb', line 7

def select2(*args)
  options = args.pop
  values = args

  Utils.validate_options!(options)

  container = Utils.find_select2_container(options, page)
  version = Utils.detect_select2_version(container)
  options_with_select2_details =
    options.merge({ container: container, version: version, page: page })

  values.each do |value|
    Helpers.select2_open(options_with_select2_details)

    if options[:search] || options[:tag]
      term = options[:search].is_a?(String) ? options[:search] : value
      Helpers.select2_search(term, options_with_select2_details)
    end

    Helpers.select2_select(value, options_with_select2_details)
  end
end