Skip to content

Commit

Permalink
Fix falsely passing specs looking for "shortval"
Browse files Browse the repository at this point in the history
They were finding it in the exception backtrace that was being dumped to the HTML.
  • Loading branch information
RobinDaugherty committed Feb 26, 2020
1 parent c18a975 commit 22b94ff
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions better_errors.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Gem::Specification.new do |s|

s.add_development_dependency "rake", "~> 10.0"
s.add_development_dependency "rspec", "~> 3.5"
s.add_development_dependency "rspec-html-matchers"
s.add_development_dependency "rspec-its"
s.add_development_dependency "yard"
# kramdown 2.1 requires Ruby 2.3+
Expand Down
13 changes: 9 additions & 4 deletions spec/better_errors/error_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

module BetterErrors
describe ErrorPage do
# It's necessary to use HTML matchers here that are specific as possible.
# This is because if there's an exception within this file, the lines of code will be reflected in the
# generated HTML, so any strings being matched against the HTML content will be there if they're within 5
# lines of code of the exception that was raised.

let!(:exception) { raise ZeroDivisionError, "you divided by zero you silly goose!" rescue $! }

let(:error_page) { ErrorPage.new exception, { "PATH_INFO" => "/some/path" } }
Expand Down Expand Up @@ -104,7 +109,7 @@ def inspect

it "shows the variable content" do
html = error_page.do_variables("index" => 0)[:html]
expect(html).to include("shortval")
expect(html).to have_tag('div.variables', text: /shortval/)
end
end
context 'and does not implement #inspect' do
Expand Down Expand Up @@ -185,7 +190,7 @@ def inspect

it "shows the variable content" do
html = error_page.do_variables("index" => 0)[:html]
expect(html).to include("shortval")
expect(html).to have_tag('div.variables', text: /shortval/)
end
end
context 'and does not implement #inspect' do
Expand All @@ -198,8 +203,8 @@ def inspect

it "includes an indication that the variable was too large" do
html = error_page.do_variables("index" => 0)[:html]
expect(html).to_not include(content)
expect(html).to include("Object too large")
expect(html).not_to have_tag('div.variables', text: %r{#{content}})
expect(html).to have_tag('div.variables', text: /Object too large/)
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@

require 'bundler/setup'
Bundler.require(:default)

require 'rspec-html-matchers'

RSpec.configure do |config|
config.include RSpecHtmlMatchers
end

0 comments on commit 22b94ff

Please sign in to comment.