Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing a modal dialog with RSpec and Capybara

When I click 'Log In' on the navbar a modal dialog pops up rendering the log in partial.

How would I go about testing this using RSpec and Capybara?

<!--....-->
<li><%= link_to "Log in", '#', data: {:'reveal-id' => 'loginModal'} %></li>
<!--....-->

<div id="loginModal" class="reveal-modal">
  <%= render 'devise/sessions/new' %>
  <a class="close-reveal-modal">&#215;</a>
</div>
like image 476
Althaf Hameez Avatar asked Aug 11 '13 08:08

Althaf Hameez


1 Answers

Try:

visit your_page_path
click_link "Log in"
page.should have_content('a_modal_content_here') # async

Please consider using the following,

within('#loginModal') do
  page.should have_content('a_modal_content_here') # async
end

to look for your content in the modal only.

like image 191
Pierre-Louis Gottfrois Avatar answered Oct 27 '22 01:10

Pierre-Louis Gottfrois