Ruby 为什么assert last_response.body.include(';[String]';)会给出假阳性?

Ruby 为什么assert last_response.body.include(';[String]';)会给出假阳性?,ruby,unit-testing,rack,Ruby,Unit Testing,Rack,在Sinatra中使用Rack和Test::unit进行单元测试时,last\u response.body.include?使用不存在的测试字符串给了我一个假阳性 为什么断言最后一个\u response.body.include?('string')在'string'不在响应正文中时给出一个假阳性?在加载页面之前,您需要使用以下方法检查页面是否正确加载: assert last_response.ok? 您需要先检查页面是否正确加载,然后使用: assert last_response.o

在Sinatra中使用
Rack
Test::unit
进行单元测试时,
last\u response.body.include?
使用不存在的测试字符串给了我一个假阳性


为什么
断言最后一个\u response.body.include?('string')
'string'
不在响应正文中时给出一个假阳性?

在加载页面之前,您需要使用以下方法检查页面是否正确加载:

assert last_response.ok?

您需要先检查页面是否正确加载,然后使用:

assert last_response.ok?