Skip to content

Commit 3b74fd6

Browse files
Add silence_filter_announcements config option
1 parent 72cda5c commit 3b74fd6

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ def reporter
106106
# Notify reporter of filters.
107107
def announce_filters
108108
fail_if_config_and_cli_options_invalid
109+
return if @configuration.silence_filter_announcements?
110+
109111
filter_announcements = []
110112

111113
announce_inclusion_filter filter_announcements

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)