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

Add a failing spec for #1343. #1353

Merged
merged 2 commits into from
Feb 26, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
### 3.0.0.rc1 Development
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.0.0.beta2...master)

Enhancements:

* Add `config.default_formatter` attribute, which can be used to set a
formatter which will only be used if no other formatter is set
(e.g. via `--formatter`). (Myron Marston)

Bug Fixes:

* Fix `spec_helper.rb` file generated by `rspec --init` so that the
recommended settings correctly use the documentation formatter
when running one file. (Myron Marston)

### 3.0.0.beta2 / 2014-02-17
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.0.0.beta1...v3.0.0.beta2)

Expand Down
22 changes: 7 additions & 15 deletions features/command_line/init.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Feature: --init option
files for an rspec project. It generates a `.rspec` and
`spec/spec_helper.rb` with some example settings to get you started.

These settings treat the case where you run an individual spec file
differently, using the documentation formatter if no formatter has
been explicitly set.

Scenario: generate .rspec
When I run `rspec --init`
Then the following files should exist:
Expand Down Expand Up @@ -39,19 +43,7 @@ Feature: --init option
end
"""

When I run `rspec`
Then the examples should all pass
And the output should not contain:
"""
Addition
works
"""

When I run `rspec spec/addition_spec.rb`
Then the examples should all pass
And the output should contain:
"""
Addition
works
"""
Then the output from `rspec` should not be in documentation format
But the output from `rspec spec/addition_spec.rb` should be in documentation format
But the output from `rspec spec/addition_spec.rb --format progress` should not be in documentation format

11 changes: 11 additions & 0 deletions features/step_definitions/additional_cli_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@
step %q{the exit status should be 0}
end

addition_example_formatter_output = <<-EOS
Addition
works
EOS

Then /^the output from `([^`]+)` (should(?: not)?) be in documentation format$/ do |cmd, should_or_not|
step %Q{I run `#{cmd}`}
step %q{the examples should all pass}
step %Q{the output from "#{cmd}" #{should_or_not} contain "#{addition_example_formatter_output}"}
end

Then /^the backtrace\-normalized output should contain:$/ do |partial_output|
# ruby 1.9 includes additional stuff in the backtrace,
# so we need to normalize it to compare it with our expected output.
Expand Down
17 changes: 17 additions & 0 deletions lib/rspec/core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,23 @@ def add_formatter(formatter_to_use, *paths)
end
alias_method :formatter=, :add_formatter

# The formatter that will be used if no formatter has been set.
# Defaults to 'progress'.
def default_formatter
formatter_loader.default_formatter
end

# Sets a fallback formatter to use if none other has been set.
#
# @example
#
# RSpec.configure do |rspec|
# rspec.default_formatter = 'doc'
# end
def default_formatter=(value)
formatter_loader.default_formatter = value
end

# @api private
def formatters
formatter_loader.formatters
Expand Down
4 changes: 3 additions & 1 deletion lib/rspec/core/formatters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,15 @@ def self.formatters
def initialize(reporter)
@formatters = []
@reporter = reporter
self.default_formatter = 'progress'
end
attr_reader :formatters, :reporter
attr_accessor :default_formatter

# @api private
def setup_default(output_stream, deprecation_stream)
if @formatters.empty?
add 'progress', output_stream
add default_formatter, output_stream
end
unless @formatters.any? { |formatter| DeprecationFormatter === formatter }
add DeprecationFormatter, deprecation_stream, output_stream
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/core/project_initializer/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
# Use the documentation formatter for detailed output,
# unless a formatter has already been configured
# (e.g. via a command-line flag).
config.formatter = 'doc' if config.formatters.none?
config.default_formatter = 'doc'
end
# Print the 10 slowest examples and example groups at the
Expand Down
35 changes: 35 additions & 0 deletions spec/rspec/core/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,41 @@ def metadata_hash(*args)
end
end

describe "#default_formatter" do
it 'defaults to `progress`' do
expect(config.default_formatter).to eq('progress')
end

it 'remembers changes' do
config.default_formatter = 'doc'
expect(config.default_formatter).to eq('doc')
end

context 'when another formatter has been set' do
it 'does not get used' do
config.default_formatter = 'doc'
config.add_formatter 'progress'

expect(used_formatters).to include(an_instance_of Formatters::ProgressFormatter)
expect(used_formatters).not_to include(an_instance_of Formatters::DocumentationFormatter)
end
end

context 'when no other formatter has been set' do
it 'gets used' do
config.default_formatter = 'doc'

expect(used_formatters).not_to include(an_instance_of Formatters::ProgressFormatter)
expect(used_formatters).to include(an_instance_of Formatters::DocumentationFormatter)
end
end

def used_formatters
config.reporter # to force freezing of formatters
config.formatters
end
end

describe "#filter_run_including" do
it_behaves_like "metadata hash builder" do
def metadata_hash(*args)
Expand Down