Emily
Emily

Reputation: 164

Capybara undefined method 'current_scope'

I have the following code

scenario "it should not appears submenus' links if it doesn't has any" do
  expect(page.find('li.main-category', text: "Stargazing")).not_to have_tag('ul.nested')
end

and when I run the test I get this error

 NoMethodError:
 undefined method `current_scope' for #<Capybara::Node::Element:0x0055d1ab86e430>

I am trying to test this code

<ul class="menu vertical">
   <li class="main-category"><a href="#">Solar System</a>
     <ul class="nested vertical menu">
       <li class="subcategory"><a href="#">Planets</a></li>
     </ul>
   </li>
   <li class="main-category"><a href="#">Stargazing</a></li>
</ul>

The li tag with text 'Stargazing' should not contain a ul tag

Any ideas?

Upvotes: 1

Views: 1955

Answers (1)

Thomas Walpole
Thomas Walpole

Reputation: 49910

I'm not sure what library the have_tag matcher you're using is coming from, but that's not a Capybara matcher and is not compatible with Capybara. You want

expect(page.find('li.main-category', text: "Stargazing")).not_to have_css('ul.nested')

or have_css('ul') if you are trying to make sure there are no ul elements at all, and not just no ul elements with a class of nested.

Also make sure your Capybara is updated.

Upvotes: 3

Related Questions