Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rbngzlv/41c33e60a573b40c1e04d1d44a17341b to your computer and use it in GitHub Desktop.
Save rbngzlv/41c33e60a573b40c1e04d1d44a17341b 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