Skip to content

Instantly share code, notes, and snippets.

@eprothro
Last active June 8, 2018 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save eprothro/6243211 to your computer and use it in GitHub Desktop.
Save eprothro/6243211 to your computer and use it in GitHub Desktop.
Foundation Custom Forms Select Capybara Helper

Helper Module

# spec/support/custom_forms_helper.rb
module CustomFormsHelper
  def foundation_select(option, opts={})
    # Zurb Foundation adds custom markup after (and then hides)
    # the originating select. Here we simulate the user's interaction
    # with the custom form instead of just setting the hidden originating select's value
    originating_select_name = opts[:from]

    custom_select = find("select[name='#{originating_select_name}'] + .custom.dropdown")
    # click dropdown trigger
    custom_select.find('a.selector').click
    # click option li with correct option text
    custom_select.find('li', text: option).click
  end
end

Usage

Rails resource form

foundation_select('Texas', :from => 'user[state]')

Some other form

foundation_select('Texas', :from => 'state')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment