Skip to content

Instantly share code, notes, and snippets.

@jparker
Created November 19, 2014 21:24
Show Gist options
  • Save jparker/c56dfc8667fd252402c4 to your computer and use it in GitHub Desktop.
Save jparker/c56dfc8667fd252402c4 to your computer and use it in GitHub Desktop.
# spec/support/autocompletion.rb
module Autocompletion
def select_autocompletion(value, from:, with:, multiple: false)
input_field = find_field(from)
input_value = multiple ? "#{input_field.value}#{with}" : with
# fill_in input[:id], with: input_value
# input_field.trigger(:keydown)
page.execute_script "$('##{input_field[:id]}').val('#{input_value}').trigger('keydown')"
find('.ui-menu-item', text: value).trigger(:click)
end
end
# spec/features/awesome_feature_spec.rb
feature 'an awesome feature' do
scenario 'an awesome scenario with auto-complete-iness', :js do
# setup
# ...
select_autocompletion 'Autocompletion', from: 'Field label', with: 'auto'
# ...
# verify and teardown
end
end
# spec/rails_helper.rb
# Make sure autocompletion.rb is loaded (you may already have something like this)
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
RSpec.configure do |config|
# ...
config.include Autocompletion, type: :feature
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment