Skip to content

Commit 22b94ff

Browse files
Fix falsely passing specs looking for "shortval"
They were finding it in the exception backtrace that was being dumped to the HTML.
1 parent c18a975 commit 22b94ff

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

better_errors.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
2222

2323
s.add_development_dependency "rake", "~> 10.0"
2424
s.add_development_dependency "rspec", "~> 3.5"
25+
s.add_development_dependency "rspec-html-matchers"
2526
s.add_development_dependency "rspec-its"
2627
s.add_development_dependency "yard"
2728
# kramdown 2.1 requires Ruby 2.3+

spec/better_errors/error_page_spec.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
module 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

spec/spec_helper.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@
1919

2020
require 'bundler/setup'
2121
Bundler.require(:default)
22+
23+
require 'rspec-html-matchers'
24+
25+
RSpec.configure do |config|
26+
config.include RSpecHtmlMatchers
27+
end

0 commit comments

Comments
 (0)