Search code examples
coffeescriptcapybara

Capybara not following javascript redirection after select


I have a simple select tag:

  <strong>Choose: </strong><%= select_tag(:topic_id,  options_for_select([
          ['Choose','#'],
          ['Schools',schools_path],
          ['Spells', spells_path],
          ['Traits', traits_path],
          ['Clans', clans_path],
          ['Skills', skills_path]])) %>

And I have an coffeescript redirector:

$(document).on 'change','#topic_id', ->
  window.location.replace($(this).val())

By hand everything works great but when I try to test it with capybara it won`t fallow the redirect after select.

feature "legend school page" do
  background do
    visit legend_path
    select('Schools', from: 'topic_id' )
  end

  scenario "it should have right topic" do
    expect(page).to have_title "Schools"
  end

From what I have read capybara should use javascript, and it should work like this. But I just start learning, so I am probably wrong.


Solution

  • The default driver for Capybara is racktest which doesn't support JS. You'll need to use a js capable driver for your test to work - see drivers