Skip to content

Instantly share code, notes, and snippets.

@futhr
Created March 6, 2014 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save futhr/9398569 to your computer and use it in GitHub Desktop.
Save futhr/9398569 to your computer and use it in GitHub Desktop.
Select2 Capybara helper for forms.
# compact version from: https://github.com/spree/spree/blob/master/core/lib/spree/testing_support/capybara_ext.rb
# just drop file in spec/support
module CapybaraHelper
def select2_select(value, options)
find("#s2id_#{options[:from]} a").click
within(:xpath, '//body') do
find('div.select2-result-label', text: %r{#{Regexp.escape(value)}}i).click
end
end
end
RSpec.configure do |config|
config.include CapybaraHelper, type: :feature
end
# usage | I always use ID - i18n changes ID's normaly doesn't
# select2_select 'One Week', from: 'product_delivery_time_id'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment