22
33module BetterErrors
44 describe ErrorPage do
5+ # It's necessary to use HTML matchers here that are specific as possible.
6+ # This is because if there's an exception within this file, the lines of code will be reflected in the
7+ # generated HTML, so any strings being matched against the HTML content will be there if they're within 5
8+ # lines of code of the exception that was raised.
9+
510 let! ( :exception ) { raise ZeroDivisionError , "you divided by zero you silly goose!" rescue $! }
611
712 let ( :error_page ) { ErrorPage . new exception , { "PATH_INFO" => "/some/path" } }
@@ -104,7 +109,7 @@ def inspect
104109
105110 it "shows the variable content" do
106111 html = error_page . do_variables ( "index" => 0 ) [ :html ]
107- expect ( html ) . to include ( " shortval" )
112+ expect ( html ) . to have_tag ( 'div.variables' , text : / shortval/ )
108113 end
109114 end
110115 context 'and does not implement #inspect' do
@@ -185,7 +190,7 @@ def inspect
185190
186191 it "shows the variable content" do
187192 html = error_page . do_variables ( "index" => 0 ) [ :html ]
188- expect ( html ) . to include ( " shortval" )
193+ expect ( html ) . to have_tag ( 'div.variables' , text : / shortval/ )
189194 end
190195 end
191196 context 'and does not implement #inspect' do
@@ -198,8 +203,8 @@ def inspect
198203
199204 it "includes an indication that the variable was too large" do
200205 html = error_page . do_variables ( "index" => 0 ) [ :html ]
201- expect ( html ) . to_not include ( content )
202- expect ( html ) . to include ( " Object too large" )
206+ expect ( html ) . not_to have_tag ( 'div.variables' , text : %r{ #{ content } } )
207+ expect ( html ) . to have_tag ( 'div.variables' , text : / Object too large/ )
203208 end
204209 end
205210 end
0 commit comments