Issues with stream configuration / deprecation formatter
Created by: myronmarston
I'm working on #1092 (closed) and I've run into a larger issue that I'd like some feedback on before attempting to solve.
When adding a deprecation for --order default
(which is --order defined
in RSpec 3), get this error:
/Users/myron/code/rspec-dev/repos/rspec-core/lib/rspec/core/formatters/deprecation_formatter.rb:144:in `deprecation_summary': private method `puts' called for nil:NilClass (NoMethodError)
from /Users/myron/code/rspec-dev/repos/rspec-core/lib/rspec/core/formatters/deprecation_formatter.rb:27:in `deprecation_summary'
from /Users/myron/code/rspec-dev/repos/rspec-core/lib/rspec/core/reporter.rb:127:in `block in notify'
from /Users/myron/code/rspec-dev/repos/rspec-core/lib/rspec/core/reporter.rb:126:in `each'
from /Users/myron/code/rspec-dev/repos/rspec-core/lib/rspec/core/reporter.rb:126:in `notify'
from /Users/myron/code/rspec-dev/repos/rspec-core/lib/rspec/core/reporter.rb:111:in `finish'
from /Users/myron/code/rspec-dev/repos/rspec-core/lib/rspec/core/reporter.rb:60:in `report'
from /Users/myron/code/rspec-dev/repos/rspec-core/lib/rspec/core/command_line.rb:25:in `run'
from /Users/myron/code/rspec-dev/repos/rspec-core/lib/rspec/core/runner.rb:89:in `run'
from /Users/myron/code/rspec-dev/repos/rspec-core/lib/rspec/core/runner.rb:17:in `block in autorun'
Here's what's going on:
- The reporter and deprecation formatter are initialized lazily here when RSpec.deprecate.
-
RSpec::Core::Configuration#output_stream
is initiallynil
; it gets assigned lazily inRSpec::Core::CommandLine#run
. The||=
there goes back to this commit, which, unfortunately, lacks a spec. - Because I am issuing a deprecation warning from option_parser.rb, it is initializing the reporter and deprecation formatter before the output stream has been set, so it is nil and we get the above error.
So, a few things I'm considering:
- I think we should set
output_stream
to$stdout
inRSpec::Core::Configuration#initialize
so that it is never nil. - There's this bifurcation between
RSpec::Core::Configuration#output_stream
and#error_stream
being settable off of the config object and also being set viaCommandLine#run
. @dchelimsky, do you remember whyrun
accepts those args? Any reason not to remove them and just default the values on the config object and then allow users to overwrite them there? It would simplify this considerably, I think. - I'm realizing that with how the deprecation formatter works, if can be initialized with the deprecation stream + output stream before the user has had a chance to configure those...which means that if/when they configure those, it'll effectively ignore the user's config. I'm not sure what the solution is here. Any ideas?
/cc @soulcutter @jonrowe @xaviershay @samphippen