Skip to content

Commit af63bf5

Browse files
committed
Merge pull request rspec#2007 from draffensperger/silence-filter-annouce
Add silence_filter_announcements config option
2 parents 0ba4f30 + 64ba03d commit af63bf5

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

Filtering.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,16 @@ end
159159
```
160160

161161
These declarations can also be overridden from the command line.
162+
163+
## Silencing filter announcements
164+
165+
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`.
166+
167+
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:
168+
169+
``` ruby
170+
RSpec.configure do |c|
171+
c.filter_run_including :foo => :bar
172+
c.silence_filter_announcements = true
173+
end
174+
```

lib/rspec/core/configuration.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,11 @@ def exclude_pattern=(value)
293293
# :cyan]`
294294
add_setting :detail_color
295295

296+
# @macro add_setting
297+
# Don't print filter info i.e. "Run options: include {:focus=>true}"
298+
# (default `false`).
299+
add_setting :silence_filter_announcements
300+
296301
# Deprecated. This config option was added in RSpec 2 to pave the way
297302
# for this being the default behavior in RSpec 3. Now this option is
298303
# a no-op.

lib/rspec/core/world.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,14 @@ def announce_filters
113113

114114
unless filter_manager.empty?
115115
if filter_announcements.length == 1
116-
reporter.message("Run options: #{filter_announcements[0]}")
116+
report_filter_message("Run options: #{filter_announcements[0]}")
117117
else
118-
reporter.message("Run options:\n #{filter_announcements.join("\n ")}")
118+
report_filter_message("Run options:\n #{filter_announcements.join("\n ")}")
119119
end
120120
end
121121

122122
if @configuration.run_all_when_everything_filtered? && example_count.zero? && !@configuration.only_failures?
123-
reporter.message("#{everything_filtered_message}; ignoring #{inclusion_filter.description}")
123+
report_filter_message("#{everything_filtered_message}; ignoring #{inclusion_filter.description}")
124124
filtered_examples.clear
125125
inclusion_filter.clear
126126
end
@@ -129,12 +129,17 @@ def announce_filters
129129

130130
example_groups.clear
131131
if filter_manager.empty?
132-
reporter.message("No examples found.")
132+
report_filter_message("No examples found.")
133133
elsif exclusion_filter.empty? || inclusion_filter.empty?
134-
reporter.message(everything_filtered_message)
134+
report_filter_message(everything_filtered_message)
135135
end
136136
end
137137

138+
# @private
139+
def report_filter_message(message)
140+
reporter.message(message) unless @configuration.silence_filter_announcements?
141+
end
142+
138143
# @private
139144
def everything_filtered_message
140145
"\nAll examples were filtered out"

spec/rspec/core/world_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,15 @@ module RSpec::Core
224224
world.announce_filters
225225
end
226226
end
227+
228+
context "with a filter but with silence_filter_announcements" do
229+
it "does not announce" do
230+
configuration.silence_filter_announcements = true
231+
configuration.filter_run_including :foo => 'bar'
232+
expect(reporter).to_not receive(:message)
233+
world.announce_filters
234+
end
235+
end
227236
end
228237

229238
context "with examples" do

0 commit comments

Comments
 (0)