Capybara select chosen field for rspec testing
- Create a new file in
spec/support
/
# spec/support/select_from_chosen.rb
module SelectFromChosen
# select_from_chosen('Option', from: 'id_of_field')
def select_from_chosen(item_text, options)
field = find_field(options[:from], :visible => false)
find("##{field[:id]}_chosen").click
find("##{field[:id]}_chosen ul.chosen-results li", :text => item_text).click
end
end
- Include the module in the Rspec configuration for features:
# spec/rails_helper.rb
RSpec.configure do |config|
config.include SelectFromChosen, type: :feature
end
- Usage in scenario:
select_from_chosen('Option', from: 'id_of_field')
Written by Troy Martin
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rpsec
Authors
tmartin314
2.867K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#