Created
November 19, 2014 21:24
-
-
Save jparker/c56dfc8667fd252402c4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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 |
This file contains hidden or 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
# 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 |
This file contains hidden or 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
# 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