Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

With Rails and Rspec, is there a way to see what page an action really takes you to?

I have a rails test in which I go to a page and enter information, save the page (which takes me back one page), and attempt to come back to see if the data is still there. I am hitting a wall, but suspect that if I could see what is on the page, I could discern what when wrong or how to adapt my assertions. Is there a way to visualize/breakpoint/curl that page that test is actually encountering? Everything I assert is coming back false.

it "Emergency Contact step saves data submitted" do
  click_link "Register online"
  click_link "Emergency Contacts"
  fill_in "Contact 1 Name", :with => "1 name"
  fill_in "Contact 1 Phone", :with => "123.456.7890"
  click_button "Save"
  click_link "Emergency Contacts"
  assert page.has_content?("1 name")
  assert page.has_content?("123.456.7890") 
end

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

One technique I use after a page transition is to check the current path (route) against a known one like this:

assert_equal page.current_path, new_page_path
# or
assert_equal page.current_path, "/things/new"

Another way to debug could be to look at the contents of page.html like

puts page.html

Or use capybara’s save_and_open_page method, which save the HTML of the current page to your Rails app’s tmp directory and opens that in a browser.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading