From b4b8b0346151422df398aed18052a2e7156a872b Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Fri, 13 Jan 2023 13:31:28 +1000 Subject: [PATCH] DEV: Add option to disable rspec diff truncation ENV var (#19861) Sometimes you may have a large string or object that you are comparing with some expectation, and you want to see the full diff between actual and expected without rspec truncating 90% of the diff. Setting the max_formatted_output_length to nil disables this truncation completely. c.f. https://www.rubydoc.info/gems/rspec-expectations/RSpec/Expectations/Configuration#max_formatted_output_length=-instance_method Use `RSPEC_DISABLE_DIFF_TRUNCATION=1` to disable this. --- spec/rails_helper.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 1644f6af06e..02aa2e80cdc 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -190,6 +190,18 @@ RSpec.configure do |config| # instead of true. config.use_transactional_fixtures = true + # Sometimes you may have a large string or object that you are comparing + # with some expectation, and you want to see the full diff between actual + # and expected without rspec truncating 90% of the diff. Setting the + # max_formatted_output_length to nil disables this truncation completely. + # + # c.f. https://www.rubydoc.info/gems/rspec-expectations/RSpec/Expectations/Configuration#max_formatted_output_length=-instance_method + if ENV["RSPEC_DISABLE_DIFF_TRUNCATION"] + config.expect_with :rspec do |expectation| + expectation.max_formatted_output_length = nil + end + end + # If true, the base class of anonymous controllers will be inferred # automatically. This will be the default behavior in future versions of # rspec-rails.