Permalink
Browse files

Improve the filter announcement messaging.

- Don't include the default filters.
- Remove the noisy hex number from procs.

Closes #350.
  • Loading branch information...
1 parent fd5ef93 commit aecda56ccb7a859e7168eaf98305b9bcb82f8ede @myronmarston myronmarston committed Apr 21, 2011
Showing with 70 additions and 8 deletions.
  1. +24 −4 lib/rspec/core/configuration.rb
  2. +4 −4 lib/rspec/core/world.rb
  3. +42 −0 spec/rspec/core/configuration_spec.rb
@@ -36,6 +36,11 @@ def self.add_setting(name, opts={})
add_setting :treat_symbols_as_metadata_keys_with_true_values, :default => false
add_setting :expecting_with_rspec
+ DEFAULT_EXCLUSION_FILTERS = {
+ :if => lambda { |value, metadata| metadata.has_key?(:if) && !value },
+ :unless => lambda { |value| value }
+ }
+
def initialize
@color_enabled = false
self.include_or_extend_modules = []
@@ -48,10 +53,7 @@ def initialize
/lib\/rspec\/(core|expectations|matchers|mocks)/
]
- self.exclusion_filter = {
- :if => lambda { |value, metadata| metadata.has_key?(:if) && !value },
- :unless => lambda { |value| value }
- }
+ self.exclusion_filter = DEFAULT_EXCLUSION_FILTERS.dup
end
# :call-seq:
@@ -335,6 +337,24 @@ def alias_it_should_behave_like_to(new_name, report_label = '')
RSpec::Core::ExampleGroup.alias_it_should_behave_like_to(new_name, report_label)
end
+ PROC_HEX_NUMBER = /0x[0-9a-f]+@/
+
+ def exclusion_filter=(filter)
+ def filter.description
+ reject { |k, v| DEFAULT_EXCLUSION_FILTERS[k] == v }.inspect.gsub(PROC_HEX_NUMBER, '')
+ end
+
+ settings[:exclusion_filter] = filter
+ end
+
+ def filter=(filter)
+ def filter.description
+ inspect.gsub(PROC_HEX_NUMBER, '')
+ end
+
+ settings[:filter] = filter
+ end
+
def filter_run_including(*args)
force_overwrite = if args.last.is_a?(Hash) || args.last.is_a?(Symbol)
false
View
@@ -72,22 +72,22 @@ def announce_filters
def announce_inclusion_filter(announcements)
if inclusion_filter
if @configuration.run_all_when_everything_filtered? && RSpec.world.example_count.zero?
- @configuration.reporter.message "No examples were matched by #{inclusion_filter.inspect}, running all"
+ @configuration.reporter.message "No examples were matched by #{inclusion_filter.description}, running all"
@configuration.clear_inclusion_filter
filtered_examples.clear
else
- announcements << "using #{inclusion_filter.inspect}"
+ announcements << "using #{inclusion_filter.description}"
end
end
end
def announce_exclusion_filter(announcements)
if exclusion_filter && RSpec.world.example_count.zero?
@configuration.reporter.message(
- "No examples were matched. Perhaps #{exclusion_filter.inspect} is excluding everything?")
+ "No examples were matched. Perhaps #{exclusion_filter.description} is excluding everything?")
example_groups.clear
else
- announcements << "excluding #{exclusion_filter.inspect}"
+ announcements << "excluding #{exclusion_filter.description}"
end
end
@@ -517,6 +517,18 @@ def metadata_hash(*args)
end
end
+ describe "#filter" do
+ describe "#description" do
+ it 'does not include the unnecessary hex number for lambdas' do
+ # check the assumption of this example
+ lambda { }.inspect.should include('0x')
+
+ config.filter_run :bar => lambda { }
+ config.filter.description.should_not include('0x')
+ end
+ end
+ end
+
describe "#filter_run_excluding" do
it_behaves_like "metadata hash builder" do
def metadata_hash(*args)
@@ -540,6 +552,36 @@ def metadata_hash(*args)
end
describe "#exclusion_filter" do
+ describe "#description" do
+ it 'returns `{}` when it only contains the default filters' do
+ config.exclusion_filter.description.should == {}.inspect
+ end
+
+ it 'includes other filters' do
+ config.exclusion_filter[:foo] = :bar
+ config.exclusion_filter.description.should == { :foo => :bar }.inspect
+ end
+
+ it 'includes an overriden :if filter' do
+ config.exclusion_filter[:if] = :custom_filter
+ config.exclusion_filter.description.should == { :if => :custom_filter }.inspect
+ end
+
+ it 'includes an overriden :unless filter' do
+ config.exclusion_filter[:unless] = :custom_filter
+ config.exclusion_filter.description.should == { :unless => :custom_filter }.inspect
+ end
+
+ it 'does not include the unnecessary hex number for lambdas' do
+ # check the assumption of this example
+ lambda { }.inspect.should include('0x')
+
+ config.exclusion_filter[:foo] = lambda { }
+ config.filter_run_excluding :bar => lambda { }
+ config.exclusion_filter.description.should_not include('0x')
+ end
+ end
+
describe "the default :if filter" do
it "does not exclude a spec with no :if metadata" do
config.exclusion_filter[:if].call(nil, {}).should be_false

0 comments on commit aecda56

Please sign in to comment.