Created
March 6, 2014 20:15
-
-
Save futhr/9398569 to your computer and use it in GitHub Desktop.
Select2 Capybara helper for forms.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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