Skip to content

Commit

Permalink
Improve display of run options
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Nov 5, 2011
1 parent 8062102 commit 765d8c7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
4 changes: 4 additions & 0 deletions lib/rspec/core/filter.rb
Expand Up @@ -52,6 +52,10 @@ def initialize
extend(BackwardCompatibility)
end

def empty?
inclusions.empty? && exclusions.empty_without_conditional_filters?
end

def prune(examples)
examples.select {|e| !exclude?(e) && include?(e)}
end
Expand Down
35 changes: 20 additions & 15 deletions lib/rspec/core/world.rb
Expand Up @@ -67,43 +67,48 @@ def reporter
def announce_filters
filter_announcements = []

announce_inclusion_filter filter_announcements
announce_exclusion_filter filter_announcements

unless filter.empty?
reporter.message("Run options:\n #{filter_announcements.join("\n ")}")
end

if @configuration.run_all_when_everything_filtered? && example_count.zero?
reporter.message( "No examples matched #{inclusion_filter.description}. Running all.")
reporter.message("#{everything_filtered_message}; ignoring #{inclusion_filter.description}")
filtered_examples.clear
inclusion_filter.clear
end

announce_inclusion_filter filter_announcements
announce_exclusion_filter filter_announcements

if example_count.zero?
example_groups.clear
if filter_announcements.empty?
if filter.empty?
reporter.message("No examples found.")
elsif !inclusion_filter.empty?
message = "No examples matched #{inclusion_filter.description}."
elsif exclusion_filter.empty_without_conditional_filters?
message = everything_filtered_message
if @configuration.run_all_when_everything_filtered?
message << " Running all."
message << "; ignoring #{inclusion_filter.description}"
end
reporter.message(message)
elsif !exclusion_filter.empty?
reporter.message(
"No examples were matched. Perhaps #{exclusion_filter.description} is excluding everything?")
elsif inclusion_filter.empty?
reporter.message(everything_filtered_message)
end
elsif !filter_announcements.empty?
reporter.message("Run filtered #{filter_announcements.join(', ')}")
end
end

def everything_filtered_message
"\nAll examples were filtered out"
end

def announce_inclusion_filter(announcements)
unless inclusion_filter.empty?
announcements << "including #{inclusion_filter.description}"
announcements << "include #{inclusion_filter.description}"
end
end

def announce_exclusion_filter(announcements)
unless exclusion_filter.empty_without_conditional_filters?
announcements << "excluding #{exclusion_filter.description}"
announcements << "exclude #{exclusion_filter.description}"
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/rspec/core/world_spec.rb
Expand Up @@ -94,7 +94,7 @@ module RSpec::Core
it "announces" do
configuration.filter_run_including :foo => 'bar'
reporter.should_receive(:message).
with("No examples matched #{{ :foo => 'bar' }.inspect}.")
with(/All examples were filtered out/)
world.announce_filters
end
end
Expand All @@ -104,7 +104,7 @@ module RSpec::Core
configuration.stub(:run_all_when_everything_filtered?) { true }
configuration.filter_run_including :foo => 'bar'
reporter.should_receive(:message).
with("No examples matched #{{ :foo => 'bar' }.inspect}. Running all.")
with(/All examples were filtered out/)
world.announce_filters
end
end
Expand All @@ -113,7 +113,7 @@ module RSpec::Core
it "announces" do
configuration.filter_run_excluding :foo => 'bar'
reporter.should_receive(:message).
with("No examples were matched. Perhaps #{{ :foo => 'bar' }.inspect} is excluding everything?")
with(/All examples were filtered out/)
world.announce_filters
end
end
Expand Down

0 comments on commit 765d8c7

Please sign in to comment.