Nathan Long
Nathan Long

Reputation: 125892

Why is Capybara unable to see the contents of this page?

I'm trying to write an Rspec request spec using Capybara. It seems that everything is working correctly except that Capybara sees the page as blank.

Good signs:

Bad signs:

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?

Upvotes: 4

Views: 799

Answers (1)

Nathan Long
Nathan Long

Reputation: 125892

The forehead-slapping answer

... which I'm sharing to save others the same pain.

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

visit '/assembly/manage/task_lists/new'

Don't use get with Capybara:

get '/assembly/manage/task_lists/new'

Upvotes: 7

Related Questions