Spying on assert_select

When testing your views with assert_select, it's nice to get information on what response text failed to match, but it's too much to just throw @response.body into the test failure message:

assert_select('div#whatever-id p.classname', 'small stuff', @response.body)

Instead you can use nested assert_selects and the elements they yield:

assert_select('div#whatever-id') do |whateverId|
assert_select('p.classname', 'small stuff', whateverId)

That will dump out just div#whatever-id and its contents into your test failure message.