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

Add silence_filter_announcements config option #2007

Merged
merged 2 commits into from
Jun 24, 2015
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
13 changes: 13 additions & 0 deletions Filtering.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,16 @@ end
```

These declarations can also be overridden from the command line.

## Silencing filter announcements

By default, RSpec will print a message before your specs run indicating what filters are configured, for instance, it might print "Run options: include {:focus=>true}" if you set `config.filter_run_including :focus => true`.

If you wish to prevent those messages from appearing in your spec output, you can set the `silence_filter_announcements` config setting to `true` like this:

``` ruby
RSpec.configure do |c|
c.filter_run_including :foo => :bar
c.silence_filter_announcements = true
end
```
5 changes: 5 additions & 0 deletions lib/rspec/core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@ def exclude_pattern=(value)
# :cyan]`
add_setting :detail_color

# @macro add_setting
# Don't print filter info i.e. "Run options: include {:focus=>true}"
# (default `false`).
add_setting :silence_filter_announcements

# Deprecated. This config option was added in RSpec 2 to pave the way
# for this being the default behavior in RSpec 3. Now this option is
# a no-op.
Expand Down
15 changes: 10 additions & 5 deletions lib/rspec/core/world.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ def announce_filters

unless filter_manager.empty?
if filter_announcements.length == 1
reporter.message("Run options: #{filter_announcements[0]}")
report_filter_message("Run options: #{filter_announcements[0]}")
else
reporter.message("Run options:\n #{filter_announcements.join("\n ")}")
report_filter_message("Run options:\n #{filter_announcements.join("\n ")}")
end
end

if @configuration.run_all_when_everything_filtered? && example_count.zero? && [email protected]_failures?
reporter.message("#{everything_filtered_message}; ignoring #{inclusion_filter.description}")
report_filter_message("#{everything_filtered_message}; ignoring #{inclusion_filter.description}")
filtered_examples.clear
inclusion_filter.clear
end
Expand All @@ -129,12 +129,17 @@ def announce_filters

example_groups.clear
if filter_manager.empty?
reporter.message("No examples found.")
report_filter_message("No examples found.")
elsif exclusion_filter.empty? || inclusion_filter.empty?
reporter.message(everything_filtered_message)
report_filter_message(everything_filtered_message)
end
end

# @private
def report_filter_message(message)
reporter.message(message) unless @configuration.silence_filter_announcements?
end

# @private
def everything_filtered_message
"\nAll examples were filtered out"
Expand Down
9 changes: 9 additions & 0 deletions spec/rspec/core/world_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,15 @@ module RSpec::Core
world.announce_filters
end
end

context "with a filter but with silence_filter_announcements" do
it "does not announce" do
configuration.silence_filter_announcements = true
configuration.filter_run_including :foo => 'bar'
expect(reporter).to_not receive(:message)
world.announce_filters
end
end
end

context "with examples" do
Expand Down