Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails 3.2 capybara Capybara::ElementNotFound:Unable to find xpath "/html"

I am trying to test my rails app with rspec 2.10.0 + capybara 1.1.2. Here is my test file

require 'spec_helper'

    describe AdminPanelController do
      describe "index" do
        it "should have return code 200" do
          visit '/admin'
          page.should have_content "hello"
          #response.status.should be(200)
        end
      end
    end

And here are test result

 Failure/Error: page.should have_content "hello"
 Capybara::ElementNotFound:
   Unable to find xpath "/html"

I google about this issue but find only information that webrat can be a problem however i do not have this gem installed. Thanks for any suggestions.

like image 674
John Avatar asked Jul 08 '12 10:07

John


1 Answers

Wrong type of test. This looks like a controller test, which does tests with methods like get and post and is in the spec/controllers folder. Request specs, which use capybara, reside in spec/requests. Run $ rails generate scaffold SomeModel to see how they each should look.

If you understood the above but would still like to use capybara for your controller test, modify your describe block:

describe AdminPanelController, :type => :request do
  ...
end
like image 161
Tanzeeb Khalili Avatar answered Oct 18 '22 00:10

Tanzeeb Khalili