Skip to content
This repository
Browse code

Configuration#inclusion_filter and #exclusion_filter guarantee non-nil

- Fixes #376.
  • Loading branch information...
commit b06c1d5396989e407464cc1b5589e728123c261b 1 parent e687d01
David Chelimsky authored May 18, 2011
9  lib/rspec/core/configuration.rb
@@ -349,10 +349,17 @@ def exclusion_filter=(filter)
349 349
         settings[:exclusion_filter] = filter
350 350
       end
351 351
 
  352
+      def exclusion_filter
  353
+        settings[:exclusion_filter] || {}
  354
+      end
  355
+
352 356
       def inclusion_filter=(filter)
353 357
         settings[:inclusion_filter] = filter
354 358
       end
355 359
 
  360
+      def inclusion_filter
  361
+        settings[:inclusion_filter] || {}
  362
+      end
356 363
       def filter_run_including(*args)
357 364
         force_overwrite = if args.last.is_a?(Hash) || args.last.is_a?(Symbol)
358 365
           false
@@ -362,7 +369,7 @@ def filter_run_including(*args)
362 369
 
363 370
         options = build_metadata_hash_from(args)
364 371
 
365  
-        if inclusion_filter and inclusion_filter[:line_number] || inclusion_filter[:full_description]
  372
+        if inclusion_filter[:line_number] || inclusion_filter[:full_description]
366 373
           warn "Filtering by #{options.inspect} is not possible since " \
367 374
                "you are already filtering by #{inclusion_filter.inspect}"
368 375
         else
14  lib/rspec/core/world.rb
@@ -34,8 +34,8 @@ def initialize(configuration=RSpec.configuration)
34 34
         @filtered_examples = Hash.new { |hash,group|
35 35
           hash[group] = begin
36 36
             examples = group.examples.dup
37  
-            examples = apply_exclusion_filters(examples, exclusion_filter) if exclusion_filter
38  
-            examples = apply_inclusion_filters(examples, inclusion_filter) if inclusion_filter
  37
+            examples = apply_exclusion_filters(examples, exclusion_filter)
  38
+            examples = apply_inclusion_filters(examples, inclusion_filter)
39 39
             examples.uniq
40 40
           end
41 41
         }
@@ -106,13 +106,13 @@ def announce_filters
106 106
           example_groups.clear
107 107
           if filter_announcements.empty?
108 108
             reporter.message("No examples found.")
109  
-          elsif inclusion_filter
  109
+          elsif !inclusion_filter.empty?
110 110
             message = "No examples matched #{inclusion_filter.description}."
111 111
             if @configuration.run_all_when_everything_filtered?
112 112
               message << " Running all."
113 113
             end
114 114
             reporter.message(message)
115  
-          elsif exclusion_filter
  115
+          elsif !exclusion_filter.empty?
116 116
             reporter.message(
117 117
               "No examples were matched. Perhaps #{exclusion_filter.description} is excluding everything?")
118 118
           end
@@ -122,7 +122,7 @@ def announce_filters
122 122
       end
123 123
 
124 124
       def announce_inclusion_filter(announcements)
125  
-        if inclusion_filter
  125
+        unless inclusion_filter.empty?
126 126
           announcements << "including #{inclusion_filter.description}"
127 127
         end
128 128
       end
@@ -139,8 +139,8 @@ def find_hook(hook, scope, group, example = nil)
139 139
 
140 140
     private
141 141
 
142  
-      def apply?(predicate, conditions)
143  
-        lambda {|example| example.metadata.apply?(predicate, conditions)}
  142
+      def apply?(predicate, filter)
  143
+        lambda {|example| filter.empty? || example.metadata.apply?(predicate, filter)}
144 144
       end
145 145
 
146 146
       def declaration_line_numbers
13  spec/rspec/core/configuration_spec.rb
@@ -527,7 +527,20 @@ def metadata_hash(*args)
527 527
       end
528 528
     end
529 529
 
  530
+    describe "#inclusion_filter" do
  531
+      it "returns {} even if set to nil" do
  532
+        config.inclusion_filter = nil
  533
+        config.inclusion_filter.should eq({})
  534
+      end
  535
+    end
  536
+
  537
+
530 538
     describe "#exclusion_filter" do
  539
+      it "returns {} even if set to nil" do
  540
+        config.exclusion_filter = nil
  541
+        config.exclusion_filter.should eq({})
  542
+      end
  543
+
531 544
       describe "the default :if filter" do
532 545
         it "does not exclude a spec with no :if metadata" do
533 546
           config.exclusion_filter[:if].call(nil, {}).should be_false

0 notes on commit b06c1d5

Please sign in to comment.
Something went wrong with that request. Please try again.