Skip to content
This repository
Browse code

Merge pull request #1486 from rspec/return_formatters_dup

Dup formatters to prevent mutation
  • Loading branch information...
commit 7f3ace2fa41b150cdf24b43c817c5e68ab00f091 2 parents 1e4783c + 2a4c77b
Jon Rowe authored April 16, 2014
1  Changelog.md
Source Rendered
@@ -64,6 +64,7 @@ Breaking Changes for 3.0.0:
64 64
 * Remove `backtrace_cleaner` as an alias of `backtrace_formatter`. (Jon Rowe)
65 65
 * Remove `filename_pattern` as an alias of `pattern`. (Jon Rowe)
66 66
 * Extract support for legacy formatters to `rspec-legacy_formatters`. (Jon Rowe)
  67
+* `RSpec::Configuration#formatters` now returns a dup to prevent mutation. (Jon Rowe)
67 68
 
68 69
 Enhancements:
69 70
 
9  lib/rspec/core/configuration.rb
@@ -641,9 +641,14 @@ def default_formatter=(value)
641 641
         formatter_loader.default_formatter = value
642 642
       end
643 643
 
644  
-      # @private
  644
+      # Returns a duplicate of the formatters currently loaded in
  645
+      # the `FormatterLoader` for introspection.
  646
+      #
  647
+      # Note as this is a duplicate, any mutations will be disregarded.
  648
+      #
  649
+      # @return [Array] the formatters currently loaded
645 650
       def formatters
646  
-        formatter_loader.formatters
  651
+        formatter_loader.formatters.dup
647 652
       end
648 653
 
649 654
       # @private
8  spec/rspec/core/configuration_spec.rb
@@ -853,6 +853,14 @@ def metadata_hash(*args)
853 853
       end
854 854
     end
855 855
 
  856
+    describe "#formatters" do
  857
+      it "returns a dup of the formatter_loader formatters" do
  858
+        config.add_formatter 'doc'
  859
+        config.formatters.clear
  860
+        expect(config.formatters).to_not eq []
  861
+      end
  862
+    end
  863
+
856 864
     describe "#default_formatter" do
857 865
       it 'defaults to `progress`' do
858 866
         expect(config.default_formatter).to eq('progress')

0 notes on commit 7f3ace2

Please sign in to comment.
Something went wrong with that request. Please try again.