Search code examples
rubyunit-testingrack

Why does assert last_response.body.include?('[String]') give a false positive?


When doing unit testing in Sinatra using Rack and Test::Unit, last_response.body.include? gave me a false positive using a non-present test string.

Why does assert last_response.body.include?('string') give a false positive when 'string' isn't in the response body?


Solution

  • You need to check before if page was loaded correctly using:

    assert last_response.ok?