Search code examples
ruby-on-rails-3htmlcapybararspec-rails

how to click on a table row using capybara & rspec


I am writitng request spec for my rails app with capybara. In my code I have something like:

%table
  %tbody
     %tr{"on_click" => "location.href='some_link'"}
       %td="Some attribute"
       %td="Some attribute"
       %td="Some attribute"
       %td="Some attribute"

This way I make the entire row clickable. I want to write a request spec with capybara for this feature but I don't know how. Can anyone help me on this ?

Thank you


Solution

  • May be you should first get to know the testing in rails. Check this out! http://railscasts.com/episodes/275-how-i-test it is really helpful. You can give your tr a class (say) .tr and do

    page.find(:css, ".tr").click()

    I hope this works, worked in my case!