title: Using Rails RSpec and Capybara and Selenium how can I test to make sure a modal is being displayed
body: <p>I have a necessary modal that displays when a user has not yet excepted the Terms of Service for a site. I need to test to make sure the bootstrap modal is being displayed after looking through a lot of documentation I am still lost with how to perform this. </p>
  
  <pre><code># application.html.haml
  .container-fluid
    - if user_has_not_accepted_terms?
      = render 'parts/terms_modal'
  </code></pre>
  
  <p>my modal</p>
  
  <pre><code>.modal#terms_modal{'tabindex': "-1", role: "dialog", 'data- 
      keyboard':false, 'data-backdrop': "static"}
    .modal-dialog{role: "document"}
      .modal-content
        .modal-header
          %h5.modal-title
            Our Terms of Service have changed
        .modal-body
          %p
            Please take a minute and review our updated BLAH
        .modal-footer
          = link_to 'Accept Terms of Service', accept_terms_user_profile_path(current_user.id, current_user), method: :patch, class: 'btn btn-primary mx-auto'
  </code></pre>
  
  <p>Js making sure that modal opens on page load</p>
  
  <pre><code>$(document).on('turbolinks:load', -&gt;
    $('#terms_modal').modal('show')
  )
  
  $(document).on('page:load', -&gt;
    $('#terms_modal').modal('show')
  )
  </code></pre>
  
  <p>I know the user I am testing against has not yet accepted the terms and the conditional returns true, also when I run call save_and_open_page in my test I get back the html with the modal in it</p>
  
  <p>so far I have tried testing like</p>
  
  <pre><code># accepting_terms_spec.rb
  ...
  scenario 'user can accept terms of service', js: true do
    ... #user sign in and visit '/'
  
    within('.modal#terms_modal) do
      click_on('Accept Terms of Service')
    end
  
    expect(page).to have_content('Success')
  end
  </code></pre>
  
  <p>I get the return from the test the states the .modal is not visible. </p>