This repository was archived by the owner on Nov 30, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 7 files changed +86
-17
lines changed Expand file tree Collapse file tree 7 files changed +86
-17
lines changed Original file line number Diff line number Diff line change 1
1
### 3.0.0.rc1 Development
2
2
[ Full Changelog] ( http://github.com/rspec/rspec-core/compare/v3.0.0.beta2...master )
3
3
4
+ Enhancements:
5
+
6
+ * Add ` config.default_formatter ` attribute, which can be used to set a
7
+ formatter which will only be used if no other formatter is set
8
+ (e.g. via ` --formatter ` ). (Myron Marston)
9
+
10
+ Bug Fixes:
11
+
12
+ * Fix ` spec_helper.rb ` file generated by ` rspec --init ` so that the
13
+ recommended settings correctly use the documentation formatter
14
+ when running one file. (Myron Marston)
15
+
4
16
### 3.0.0.beta2 / 2014-02-17
5
17
[ Full Changelog] ( http://github.com/rspec/rspec-core/compare/v3.0.0.beta1...v3.0.0.beta2 )
6
18
Original file line number Diff line number Diff line change @@ -4,6 +4,10 @@ Feature: --init option
4
4
files for an rspec project. It generates a `.rspec` and
5
5
`spec/spec_helper.rb` with some example settings to get you started.
6
6
7
+ These settings treat the case where you run an individual spec file
8
+ differently, using the documentation formatter if no formatter has
9
+ been explicitly set.
10
+
7
11
Scenario : generate .rspec
8
12
When I run `rspec --init`
9
13
Then the following files should exist:
@@ -39,19 +43,7 @@ Feature: --init option
39
43
end
40
44
"""
41
45
42
- When I run `rspec`
43
- Then the examples should all pass
44
- And the output should not contain:
45
- """
46
- Addition
47
- works
48
- """
49
-
50
- When I run `rspec spec/addition_spec.rb`
51
- Then the examples should all pass
52
- And the output should contain:
53
- """
54
- Addition
55
- works
56
- """
46
+ Then the output from `rspec` should not be in documentation format
47
+ But the output from `rspec spec/addition_spec.rb` should be in documentation format
48
+ But the output from `rspec spec/addition_spec.rb --format progress` should not be in documentation format
57
49
Original file line number Diff line number Diff line change 31
31
step %q{the exit status should be 0}
32
32
end
33
33
34
+ addition_example_formatter_output = <<-EOS
35
+ Addition
36
+ works
37
+ EOS
38
+
39
+ Then /^the output from `([^`]+)` (should(?: not)?) be in documentation format$/ do |cmd , should_or_not |
40
+ step %Q{I run `#{ cmd } `}
41
+ step %q{the examples should all pass}
42
+ step %Q{the output from "#{ cmd } " #{ should_or_not } contain "#{ addition_example_formatter_output } "}
43
+ end
44
+
34
45
Then /^the backtrace\- normalized output should contain:$/ do |partial_output |
35
46
# ruby 1.9 includes additional stuff in the backtrace,
36
47
# so we need to normalize it to compare it with our expected output.
Original file line number Diff line number Diff line change @@ -580,6 +580,23 @@ def add_formatter(formatter_to_use, *paths)
580
580
end
581
581
alias_method :formatter= , :add_formatter
582
582
583
+ # The formatter that will be used if no formatter has been set.
584
+ # Defaults to 'progress'.
585
+ def default_formatter
586
+ formatter_loader . default_formatter
587
+ end
588
+
589
+ # Sets a fallback formatter to use if none other has been set.
590
+ #
591
+ # @example
592
+ #
593
+ # RSpec.configure do |rspec|
594
+ # rspec.default_formatter = 'doc'
595
+ # end
596
+ def default_formatter = ( value )
597
+ formatter_loader . default_formatter = value
598
+ end
599
+
583
600
# @api private
584
601
def formatters
585
602
formatter_loader . formatters
Original file line number Diff line number Diff line change @@ -80,13 +80,15 @@ def self.formatters
80
80
def initialize ( reporter )
81
81
@formatters = [ ]
82
82
@reporter = reporter
83
+ self . default_formatter = 'progress'
83
84
end
84
85
attr_reader :formatters , :reporter
86
+ attr_accessor :default_formatter
85
87
86
88
# @api private
87
89
def setup_default ( output_stream , deprecation_stream )
88
90
if @formatters . empty?
89
- add 'progress' , output_stream
91
+ add default_formatter , output_stream
90
92
end
91
93
unless @formatters . any? { |formatter | DeprecationFormatter === formatter }
92
94
add DeprecationFormatter , deprecation_stream , output_stream
Original file line number Diff line number Diff line change 36
36
# Use the documentation formatter for detailed output,
37
37
# unless a formatter has already been configured
38
38
# (e.g. via a command-line flag).
39
- config.formatter = 'doc' if config.formatters.none?
39
+ config.default_formatter = 'doc'
40
40
end
41
41
42
42
# Print the 10 slowest examples and example groups at the
Original file line number Diff line number Diff line change @@ -824,6 +824,41 @@ def metadata_hash(*args)
824
824
end
825
825
end
826
826
827
+ describe "#default_formatter" do
828
+ it 'defaults to `progress`' do
829
+ expect ( config . default_formatter ) . to eq ( 'progress' )
830
+ end
831
+
832
+ it 'remembers changes' do
833
+ config . default_formatter = 'doc'
834
+ expect ( config . default_formatter ) . to eq ( 'doc' )
835
+ end
836
+
837
+ context 'when another formatter has been set' do
838
+ it 'does not get used' do
839
+ config . default_formatter = 'doc'
840
+ config . add_formatter 'progress'
841
+
842
+ expect ( used_formatters ) . to include ( an_instance_of Formatters ::ProgressFormatter )
843
+ expect ( used_formatters ) . not_to include ( an_instance_of Formatters ::DocumentationFormatter )
844
+ end
845
+ end
846
+
847
+ context 'when no other formatter has been set' do
848
+ it 'gets used' do
849
+ config . default_formatter = 'doc'
850
+
851
+ expect ( used_formatters ) . not_to include ( an_instance_of Formatters ::ProgressFormatter )
852
+ expect ( used_formatters ) . to include ( an_instance_of Formatters ::DocumentationFormatter )
853
+ end
854
+ end
855
+
856
+ def used_formatters
857
+ config . reporter # to force freezing of formatters
858
+ config . formatters
859
+ end
860
+ end
861
+
827
862
describe "#filter_run_including" do
828
863
it_behaves_like "metadata hash builder" do
829
864
def metadata_hash ( *args )
You can’t perform that action at this time.
0 commit comments