Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 3c92fed

Browse files
committed
Ensure ConsoleCodes is loaded in all files that reference it.
Previously, it was required from `base_text_formatter` and `profile_formatter`, but was used from a number of other places. An unrelated change I was making that affected bisect caused it to hit a code path that tried to use `ConsoleCodes` without it being loaded, resulting in an error. Note: I had to change `CONFIG_COLORS_TO_METHODS` from a constant to a method to delay the `Configuration.instance_methods` call. With the require changes, the `console_codes` file is now loaded before `configuration` and therefore cannot query it at load time.
1 parent 6a4376e commit 3c92fed

File tree

6 files changed

+11
-5
lines changed

6 files changed

+11
-5
lines changed

lib/rspec/core/formatters/base_text_formatter.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
RSpec::Support.require_rspec_core "formatters/base_formatter"
2-
RSpec::Support.require_rspec_core "formatters/console_codes"
32

43
module RSpec
54
module Core

lib/rspec/core/formatters/console_codes.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ module ConsoleCodes
2323
module_function
2424

2525
# @private
26-
CONFIG_COLORS_TO_METHODS = Configuration.instance_methods.grep(/_color\z/).inject({}) do |hash, method|
27-
hash[method.to_s.sub(/_color\z/, '').to_sym] = method
28-
hash
26+
def config_colors_to_methods
27+
@config_colors_to_methods ||=
28+
Configuration.instance_methods.grep(/_color\z/).inject({}) do |hash, method|
29+
hash[method.to_s.sub(/_color\z/, '').to_sym] = method
30+
hash
31+
end
2932
end
3033

3134
# Fetches the correct code for the supplied symbol, or checks
@@ -34,7 +37,7 @@ module ConsoleCodes
3437
# @param code_or_symbol [Symbol, Fixnum] Symbol or code to check
3538
# @return [Fixnum] a console code
3639
def console_code_for(code_or_symbol)
37-
if (config_method = CONFIG_COLORS_TO_METHODS[code_or_symbol])
40+
if (config_method = config_colors_to_methods[code_or_symbol])
3841
console_code_for RSpec.configuration.__send__(config_method)
3942
elsif VT100_CODE_VALUES.key?(code_or_symbol)
4043
code_or_symbol

lib/rspec/core/formatters/documentation_formatter.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
RSpec::Support.require_rspec_core "formatters/base_text_formatter"
2+
RSpec::Support.require_rspec_core "formatters/console_codes"
23

34
module RSpec
45
module Core

lib/rspec/core/formatters/exception_presenter.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# encoding: utf-8
2+
RSpec::Support.require_rspec_core "formatters/console_codes"
23
RSpec::Support.require_rspec_core "formatters/snippet_extractor"
34
RSpec::Support.require_rspec_support "encoded_string"
45

lib/rspec/core/formatters/progress_formatter.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
RSpec::Support.require_rspec_core "formatters/base_text_formatter"
2+
RSpec::Support.require_rspec_core "formatters/console_codes"
23

34
module RSpec
45
module Core

lib/rspec/core/notifications.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
RSpec::Support.require_rspec_core "formatters/console_codes"
12
RSpec::Support.require_rspec_core "formatters/exception_presenter"
23
RSpec::Support.require_rspec_core "formatters/helpers"
34
RSpec::Support.require_rspec_core "shell_escape"

0 commit comments

Comments
 (0)