module CapybaraChoices::Utils

Public Class Methods

detect_choices_version(container) click to toggle source
# File lib/capybara-choices/utils.rb, line 8
def self.detect_choices_version(container)
  '9'
end
find_choices_container(options, page) click to toggle source
# File lib/capybara-choices/utils.rb, line 18
def self.find_choices_container(options, page)
  container = if options[:xpath]
    page.find(:xpath, options[:xpath])
  elsif options[:css]
    page.find(:css, options[:css])
  else
    page.find(:css, 'label', text: options[:from])
      .find(:xpath, '..')
      .find(:css, '.choices')
  end

  container
end
get_page_container_and_version(options, context) click to toggle source
# File lib/capybara-choices/utils.rb, line 32
def self.get_page_container_and_version(options, context)
  page = options[:page] || context.page
  container = options[:container] || find_choices_container(options, page)
  version = options[:version] || detect_choices_version(container)

  [page, container, version]
end
set_option_aliases(options) click to toggle source
# File lib/capybara-choices/utils.rb, line 4
def self.set_option_aliases(options)
  options.dup.tap { |o| o[:from] ||= o[:label] }
end
validate_options!(options) click to toggle source
# File lib/capybara-choices/utils.rb, line 12
def self.validate_options!(options)
  unless options.is_a?(Hash) && [:css, :xpath, :from].any? { |k| options.key?(k) }
    fail ArgumentError.new("Please specify :css, :xpath or :from in options")
  end
end