Why can't Capybara see the contents of this page?

I am trying to write an Rspec request specification using Capybara. Everything seems to work correctly except that Capybara sees the page blank.

Good signs:

  • The page loads fine in the browser
  • Bringing the log into the log shows that the correct view is displayed during the test run.
  • Any registration applications that I place in the submissions are executed.
  • If I use assert_select "h1", :text => "hello world" , the test passes.

Bad signs:

  • If I use page.should have_content('hello world') , it fails saying Capybara::ElementNotFound: Unable to find xpath "/html"
  • If I do $stdout.puts page.html , it is empty except for doctype

My test looks something like this:

 describe "working with foos" do it "should have a 'new foo' form" do get '/foos/new' assert_select 'h1', text: 'hello world' # passes page.should have_content('hello world') # fails $stdout.puts page.html # empty except for a doctype end end 

What could be wrong here?

+4
source share
1 answer

Answer to the forehead

... which I share to save others the same pain.

Capybara uses the visit method to set up its page variable.

 visit '/assembly/manage/task_lists/new' 

Do not use get with Capybara:

 get '/assembly/manage/task_lists/new' 
+7
source

All Articles