Can't refute presence of body
rafaelfranca opened this issue · 1 comments
This is a dup of rails/rails#17008 in the right reposity
In a demo reproduction app, I have a controller that returns no layout:
class TestController < ApplicationController
def index
render :layout => false
end
endIt works, there is no layout, and no <body> tag in the output (because I have no body tag in my template, naturally, only in the layout).
However, in testing:
class TestControllerTest < ActionController::TestCase
test "no layout" do
get :index
# Assert that no layout was included in the request
assert_select "body", 0
end
endreturns:
1) Failure:
TestControllerTest#test_no_layout [/Users/jrochkind/code/rails42/test/controllers/test_controller_test.rb:11]:
Expected exactly 0 elements matching "body", found 1..
Expected: 0
Actual: 1
This doesn't seem to be right, trying to introspect on response.body in the debugger, there appears to be no body tag. But assert_select is for some reason insisting there is one.
This is an extraction from a real app that has a test to make sure no layout is provided in a case where one shouldn't be provided.
Sorry, I tried to follow the template for creating a self-contained repro, but couldn't manage to create a self-contained repro that had the assert_select method available in a test, which is what I needed to demonstrate.
The problem is that we're using a Nokogiri::HTML::Document and not a Nokogiri::HTML::DocumentFragment for parsing.
Nokogiri envelops the HTML in a document complete with a head and body tag.
The search starts from the root of the document which will match against the body tag.